// JavaScript Document//////////////get the Sub Manu
function getSub(){
var MainCate= document.AddProducts.Category_Name.value;
if (MainCate.length>0){	
	var url="Ajax.asp?Action=getSub&MainCate="+MainCate+"&rd="+Math.random();
	xmlHttp=GetXmlHttpObject(stateChanged3);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
	}
	
	}
function ok(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
if(xmlHttp.responseText.length>0)
{return true} 
return false;
}
return true;}

function stateChanged3()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
if(xmlHttp.responseText.length>0)
{document.getElementById("SubCate").innerHTML=xmlHttp.responseText; } 
return false;
}

return true;
} 
//---------------------------------------------------------------
//function getProdID(){////////////////////get-the-productID-for-order///////////////////////
//var idcate= document.AddProducts.ID_Category1.value;
//alert(idcate);
//if (idcate.length>0){
//var url="Ajax.asp?Action=getProdID&idcate="+idcate+"&rd="+Math.random();
 //   xmlHttp=GetXmlHttpObject(stateChangedGetID);
  //  xmlHttp.open("GET", url , true);
//    xmlHttp.send(null);
//	}
//}
//----------------
//function stateChangedGetID()
//{ 
//if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
//{
//if(xmlHttp.responseText.length>0)
//{document.getElementById("ProdIDShw").innerHTML=xmlHttp.responseText; } 
//return false;
//}
//return true;
//}
// JavaScript Document//////////////get the CategoryLevel1
function DisLevel1(form){
var chk= form.Level2.checked;

if (chk ==true){
	var url="Ajax.asp?Action=DisLevel1&rd="+Math.random();
	xmlHttp=GetXmlHttpObject(stateChanged2);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
	}
else{
	var url="Ajax.asp?Action=CloseLevel1&rd="+Math.random();
	xmlHttp=GetXmlHttpObject(stateChanged2);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null)
	}
	
	}

function stateChanged2()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
if(xmlHttp.responseText.length>0)
{document.getElementById("Level1").innerHTML=xmlHttp.responseText; } 
return false;
}

return true;
} 
// JavaScript Document//////////////modify category
function ModifCategory(CHid){
	var ypos=document.getElementById("Yps").value;	
	var xpos=document.getElementById("Xps").value;
	var url="Ajax.asp?Action=CategoryChg&CHid="+CHid+"&Ypos="+ypos+"&Xpos="+xpos+"&rd="+Math.random();
	xmlHttp=GetXmlHttpObject(CategoryChanged);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);

}
//----------------------
function CategoryChanged()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
if(xmlHttp.responseText.length>0)
{document.getElementById("adds").innerHTML=xmlHttp.responseText; } 
return false;
}

return true;
} 
////////////////////////////
function SaveCate(saveid){
	var ypos=document.getElementById("Yps").value;	
	var xpos=document.getElementById("Xps").value;
	var label=document.getElementById("NewCate").value;
	var url="Ajax.asp?Action=SaveCategory&CHid="+saveid+"&Ypos="+ypos+"&Xpos="+xpos+"&newLabel="+label+"&rd="+Math.random();
	xmlHttp=GetXmlHttpObject(saveCategory);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
}
function saveCategory()
{ 

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
if(xmlHttp.responseText.length>0)
{
	document.getElementById("adds").innerHTML=xmlHttp.responseText; 
closeDis();
window.location.href="bonzaiAction.asp?Action=Category";
} 
return false;

}
}
//--------------------------------------------------------------------------------------------------------------------
function DelQua(DelID){
	//alert(DelID);
	var url="Ajax.asp?Action=dQ&ProdID="+DelID+"&rd="+Math.random();
	xmlHttp=GetXmlHttpObject(dellQuotation);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
	//alert(url);
	}
	
function DelQua2(DelID){
	//alert(DelID);
	var url="Ajax.asp?Action=dQ&ProdID="+DelID+"&rd="+Math.random();
	xmlHttp=GetXmlHttpObject(dellQuotation);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
	//alert(url);
	history.go(0)
	}	
	
function dellQuotation()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
if(xmlHttp.responseText.length>0)
{ document.getElementById("QuoList").innerHTML=xmlHttp.responseText;
//closeDis();
//alert(xmlHttp.responseText);
} 
return false;
}
return true;
}


function AddInCart(ProdID,usr){//Add-products-in-Coustomer-Cart
mouseMove();
if (usr==''){alert("Please login first ! ");
}
else{
	var ypos=document.getElementById('Yps').value;	
	var xpos=document.getElementById('Xps').value;
	var url="Ajax.asp?Action=AddOrder&ProdID="+ProdID+"&Ypos="+ypos+"&Xpos="+xpos+"&rd="+Math.random();
	xmlHttp=GetXmlHttpObject(AddQuotation);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
}


}

function AddQuotation()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
if(xmlHttp.responseText.length>0)
{ document.getElementById("adds").innerHTML=xmlHttp.responseText;
//closeDis();
} 
return false;
}
return true;
}

function closeDis(){window.setTimeout("CloseDis2()",4000);}//auto close after 8s
function CloseDis2(){document.getElementById("adds").innerHTML="";}

//save the products
function SaveOrder(){
var y=document.getElementById('Yps').value;	
var x=document.getElementById('Xps').value;

var prodID=document.OD_Save.ID_Prod.value;
var qti=document.OD_Save.quantity.value;
var msg=document.OD_Save.leaveMsg.value;
var User=document.OD_Save.User.value;
if (User==""){alert("Please sign in first !");return false;}
myText="0123456789";
for (var i = 0; i < qti.length; i++)
{j=myText.indexOf(qti.charAt(i));
if (j==-1)
  { alert("Quantity input must be numeric !");
   document.OD_Save.quantity.focus();  
   return false;}
}

if(qti.length == 0)
{ alert("Please input the Quantity !");
return false;
}else{
var url="Ajax.asp?Action=SaveOrder&ProdID="+prodID+"&Quantity="+qti+"&msg="+msg+"&x="+x+"&y="+y+"&rd="+Math.random();//-----Send data to save
	xmlHttp=GetXmlHttpObject(saveEnd);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
	CloseDis2();
}
return true;
}
/////////////////////////////////////////////////////////////////
function clquantity(){document.getElementById("quantity").readonly="";document.getElementById("quantity").value="";}
function saveEnd()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
if(xmlHttp.responseText.length>0)
{ document.getElementById("adds").innerHTML=xmlHttp.responseText;
var T=document.getElementById("quantity");
if(T!=null){
T.readonly="readonly";
setTimeout("clquantity()",4500)};
closeDis();
} 
return false;
}
return true;
}
/////////////////////////////////////////////////////////

/////////////////////////////get-mouse-postion///////////////////////////////////////
function mouseMove(ev){
	ev           = ev || window.event;
	var mousePos = mouseCoords(ev);
		document.getElementById('Yps').value = mousePos.y;
		document.getElementById('Xps').value = mousePos.x;
		}

function mouseCoords(ev){
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	return {
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:ev.clientY + document.body.scrollTop  - document.body.clientTop
	};
}

document.onmousemove = mouseMove;