/*
+-------------------------------------------------------------------------+
| TOIT ONLINE WWW Project                                                 |
+-------------------------------------------------------------------------+
| Copyright (c) 2000 Andrew Sitnikov                                      |
+-------------------------------------------------------------------------+
| This program is copywrite Andrew Sitnikov <sitnikov@infonet.ee> 2000    |
| All rights  reserved. You may not sell, distribute, or give away        |
| any copy of this program without the express consent                    |
| This notice must remain in the top of every                             |
| document included in this distribution.                                 |
+-------------------------------------------------------------------------+
| Author: Andrew Sitnikov <sitnikov@infonet.ee>                           |
+-------------------------------------------------------------------------+
*/
function submitOnEnter(e,o) {
	if (e.keyCode == 13){
		o.form.submit();
	}
}

function nextOnEnter(e,o) {
	if (e.keyCode == 13 && o.next) {
		o.next.click();
		return false;
	}

	return false;
}

/*
function prevOnEsc(e,o) {
if (e.keyCode == 27 && o) {
o.form.prev.click();
return false;
}
}*/

function InputSet(id, val){
	var o = document.getElementById("dish_id_"+id);

	if (!o){
		return;
	}

	if ( Number(o.value)<1 ){
		o.value=val;
	}
}
function InputChange(id, qnt){
	var o = document.getElementById("dish_id_"+id);
	var i = 0;

	if (!o){
		return;
	}

	i = Number(o.value)+qnt;

	if (i<0){
		i=0;
	}

	o.value=i;
}

function InputInc(id){
	InputChange(id,1);
}

function InputDec(id){
	InputChange(id,-1);
}

function InputFocus(o) {
	if ( !o ){
		return false;
	}

	if ( o.value == '0' ){
		o.value = '';
	}

	return true;
}

function InputBlur(o){
	if ( !o ){
		return false;
	}

	if ( o.value == '' ){
		o.value = '0';
	}

	return true;
}

function submitParentForm(o)
{
	while (o)
	{
		if ( o.nodeName.toLowerCase()=='form' ){
			break;
		}

		o = o.parentNode;
	}

	if ( o ){
		o.submit();
	}
}

function clearErrorClass(o){
	if (!o){
		return;
	}

	var str = o.className;

	var i = str.indexOf('error');

	if (  i == -1 ){
		return;
	}

	if ( i == 0 ){
		 str = str.substr(5);
	}else if(str.length==(i+5)){
		 str = str.substr(0,i-1);
	}else{
		 str = str.substr(0,i-1)+ str.substr(i+5);
	}

	o.className = str;
}


function showElement(id){
	var o = document.getElementById(id);

	if (!o){
		return;
	}

//	alert('showElement: '+id);

	o.style.display='';
}

function hideElement(id) {
	var o = document.getElementById(id);

	if (!o){
		return;
	}

//	alert('hideElement: '+id);

	o.style.display='none';
}

/*
function findObj(n, d) { //v3.0
var p,i,x;
if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
}
if(!(x=d[n])&&d.all) x=d.all[n];
for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document); return x;
}

function showHideLayers() { //v3.0
var i,p,v,obj,args=showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) {
v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
obj.visibility=v;
}
}

function setTextOfLayer(objName,x,newText) { //v3.0
if ((obj=findObj(objName))!=null) with (obj)
if (navigator.appName=='Netscape') {document.write(unescape(newText)); document.close();}
else innerHTML = unescape(newText);
}
*/

var already_send = Array();

function isAlreadySend(obj,msg){
	//alert('Obj_id : '+obj.name)
	for (i=0,j=0;i<already_send.length && j==0;i++){
		if (already_send[i]==obj.name){
			j=1;
		}
	}

	if (j==0){
		already_send[already_send.length] = obj.name;
		return false;
	}else{
		alert(msg);
		return true;
	}
}

function OpenPrintWin(url)
{
	printwin=window.open(url,"printwin");
}


	function showCustomAddress(){
		var c = document.getElementById('custom_address');
		var a = document.getElementById('order_address_id');
		if ( !c || !a){
			return;
		}

		c.style.display = (a.value == 0) ? '' : 'none'
	}
