var NUMBER_OF_REPETITIONS = 40;
var nRepetitions = 0;
var g_oTimer = null;
function startLongProcess()
{
   divProgressDialog.style.display = "";
   resizeModal();
   btnCancel.focus();
   // Add a resize handler for the window
   window.onresize = resizeModal;
}

function stopLongProcess()
{  
   if (g_oTimer != null){
      // Clear the timer so we don't get called back an extra time
      window.clearTimeout(g_oTimer);
      g_oTimer = null;
   }
   // Hide the fake modal DIV
   divModal.style.width = "0px";
   divModal.style.height = "0px";
   divProgressDialog.style.display = "none";
   // Remove our event handlers
   window.onresize = null;
   window.onbeforeunload = null;
   nRepetitions = 0;
}
function resizeModal()
{
   // Resize the DIV which fakes the modality of the dialog DIV
   divModal.style.width = document.body.scrollWidth;
   divModal.style.height = document.body.scrollHeight;
   // Re-center the dialog DIV
   divProgressDialog.style.left = ((document.body.offsetWidth - divProgressDialog.offsetWidth) / 2);
   divProgressDialog.style.top = ((document.body.offsetHeight - divProgressDialog.offsetHeight) / 10);
}

function enter(){
	if(event.keyCode==13)event.keyCode=9;
	}

function gethtml(t,d,v)
    {
        var url = t;
		var div=d;
        var pars = 'someParameter=ABC';
		
	
        var myAjax = new Ajax.Updater(
                    {success:div},
                    url,
                    {method: 'get', parameters: pars,evalScripts:true, onFailure: reportError});

    }

    function reportError(request)
    {
       // alert('sorry,have a wrong');
    }

function requesthtml(t,d,v,m){
	var url=t;
	var div=d;
	var pv=v;
	var md=m;
        new Ajax.Request(url,{
            method:md,
            parameters:pv,
            onSuccess: function(xmlHttpRequestObject){
                $(div).innerHTML=xmlHttpRequestObject.responseText;
            },
            onFailure: function(){
              //  alert('sorry,have a wrong');
                }
        });           
}


function DIVOpen() {    
     document.getElementById("divPageMask").style.display="block";
     resizeMask();
     window.onResize = resizeMask;
     document.getElementById("divOpenWin").style.display="block";
}
function DIVClose() {  
	var divPageMask =  document.getElementById("divPageMask"); 
	var divOpenWin = document.getElementById("divOpenWin");
     divPageMask.style.width = "0px";
     divPageMask.style.height = "0px";
     divOpenWin.style.top = "-300px";
     window.onResize = null;
}
function resizeMask() {
	var divPageMask =  document.getElementById("divPageMask");
	var divOpenWin = document.getElementById("divOpenWin");
	divPageMask.style.width = document.body.scrollWidth +"px"; 
	divPageMask.style.height = (document.body.scrollHeight>document.body.clientHeight ? document.body.scrollHeight : document.body.clientHeight) +"px";
	divOpenWin.style.left = ((document.body.offsetWidth - divOpenWin.offsetWidth) / 2) +"px";
	divOpenWin.style.top = ((document.body.offsetHeight - divOpenWin.offsetHeight) / 2) +"px";
}

function chatCancel(){
    jQuery("#floatChat").css("display","block");  
    jQuery("#floatChat").animate({  
        bottom: "-160px",  
        opacity:0
        },
    1000
    );
}

function chatShow(){    
    jQuery("#floatChat").css("display","block");  
    jQuery("#floatChat").animate({
        bottom:"6px",
        opacity:1
        },
    1000
    );  
}

function addToCart(id,menu_id,add,product_name,product_pic,price) {
	document.addToCartForm.id.value = id;
	document.addToCartForm.menu_id.value = menu_id;
	document.addToCartForm.add.value = add;
	document.addToCartForm.product_name.value = product_name;
	document.addToCartForm.product_pic.value = product_pic;
	document.addToCartForm.price.value = price;
	document.addToCartForm.submit();
}

function changeCount(pid, my) {
	document.shoppingForm.omthod.value = "updateCount";
	document.shoppingForm.id.value = pid;
	document.shoppingForm.count.value = my.value;
	document.shoppingForm.submit();
}

function changeSize(pid, my) {
	document.shoppingForm.omthod.value = "updateSize";
	document.shoppingForm.id.value = pid;
	document.shoppingForm.size_id.value = my.value;	
	document.shoppingForm.submit();
}

function deleteProduct(pid) {
	document.shoppingForm.omthod.value = "delete";
	document.shoppingForm.id.value = pid;
	document.shoppingForm.submit();
}

function  Form_Validator(frm) {
    if(frm.username.value=="") {
		alert("Please enter name!");
		return false;
    }
    if(frm.passwd.value=="") {
		alert("Please enter your password");
		return false;
    }
    if(frm.verifycode){
	    if(frm.verifycode.value=="") {
			alert("Please enter verify code first!");
			return false;
	    }
    }
}

function Form_Validator_reg(theForm) {	
	if (theForm.username){
		if (theForm.username.value == ""){
			alert("Please enter your Username!");
				theForm.username.focus();
				return (false);
		}
	}

	if (theForm.passwd){
		if (theForm.passwd.value == ""){
			alert("Please enter your password!");
			theForm.passwd.focus();
			return (false);
		}
		var pswstr = theForm.passwd.value;
		if (pswstr.length < 4){
			alert("Password can not less four numbers!");
			theForm.passwd.focus();
			return (false);
		}
	
		if (theForm.passwd.value != theForm.repasswd.value){
			alert("Twice password are not accordant!");
			theForm.passwd.focus();
			return (false);
		}
	}

	if (theForm.email){
		if (theForm.email.value == ""){
			alert("Please enter Email address!");
			theForm.email.focus();
			return (false);
		}
		var re = new RegExp("^([A-Za-z0-9_|-]+[.]*[A-Za-z0-9_|-]+)+@[A-Za-z0-9|-]+([.][A-Za-z0-9|-]+)*[.][A-Za-z0-9]+$","ig");
		{if (!re.test(theForm.email.value))
			{alert("E-MAIL address is not available!");
			theForm.email.focus();
			return false;
			}
		}
	}
}

function doSubmitInfoForm() {
	var theForm = document.infoForm;	
	if (theForm.fullName){
		if (theForm.fullName.value == ""){
			alert("Please enter your fullName!");
				theForm.username.focus();
				return (false);
		}
	}
	
	if (theForm.email){
		if (theForm.email.value == ""){
			alert("Please enter Email address!");
			theForm.email.focus();
			return (false);
		}
		var re = new RegExp("^([A-Za-z0-9_|-]+[.]*[A-Za-z0-9_|-]+)+@[A-Za-z0-9|-]+([.][A-Za-z0-9|-]+)*[.][A-Za-z0-9]+$","ig");
		{if (!re.test(theForm.email.value))
			{alert("E-MAIL address is not available!");
			theForm.email.focus();
			return false;
			}
		}
	}
	
	if (theForm.Phone){
		if (theForm.Phone.value == ""){
			alert("Please enter your Phone!");
				theForm.Phone.focus();
				return (false);
		}
	}
	
	if (theForm.address){
		if (theForm.address.value == ""){
			alert("Please enter your address!");
				theForm.address.focus();
				return (false);
		}
	}
	
	if (theForm.postal_code){
		if (theForm.postal_code.value == ""){
			alert("Please enter your postal_code!");
			theForm.postal_code.focus();
			return (false);
		}
	}

	if (theForm.country){
		if (theForm.country.value == ""){
			alert("Please enter your country!");
			theForm.country.focus();
			return (false);
		}
	}

	theForm.submit();
}
