var xmlHttp;
var dataDiv;
var offsetEI;
function createXMLHttpRequest(){
 if (window.XMLHttpRequest) { // Mozilla, Safari,...
                xmlHttp = new XMLHttpRequest();
            if (xmlHttp.overrideMimeType) {
                xmlHttp.overrideMimeType('text/xml');
            }
 } else if (window.ActiveXObject) { // IE
            try {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }
}

function getTooltipData(element,k){
	//alert(element.id);	
	createXMLHttpRequest();
	var url = "../Products/category1.php?Glink="+element.id+"&tick="+k;
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		 	document.getElementById("ProductInfo"+k).innerHTML = xmlHttp.responseText;
			
		}else{
		 	document.getElementById("ProductInfo"+k).innerHTML ="<img src='../imgs/loading.gif' />";
		}	
	}
	xmlHttp.send(null);
	
	}		

function clearData(k){
	document.getElementById("ProductInfo"+k).innerHTML="";
}

function getTooltipData2(element,k){
	//alert(element.id);	
	createXMLHttpRequest();
	var url = "../Products/category2.php?Glink="+element.id+"&tick="+k;
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { 		
		 	document.getElementById("ProductInfos"+k).innerHTML = xmlHttp.responseText;
		}else{
		 	document.getElementById("ProductInfos"+k).innerHTML ="<img src='../imgs/loading.gif' />";
		}			
	}
	xmlHttp.send(null);
	
	}	
function clearData2(k){
	document.getElementById("ProductInfos"+k).innerHTML="";
}
function getTooltipData3(element,k){
	//alert(element.id);	
	createXMLHttpRequest();
	var url = "../Products/category3.php?Glink="+element.id+"&tick="+k;
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { 		
		 	document.getElementById("ProductInfosP"+k).innerHTML = xmlHttp.responseText;
		}else{
		 	document.getElementById("ProductInfosP"+k).innerHTML ="<img src='../imgs/loading.gif' />";
		}	
	
	}
	xmlHttp.send(null);
	
	}	
function clearData3(k){
	document.getElementById("ProductInfosP"+k).innerHTML="";
}
function chkGrp(){
	var id=document.getElementById("GrpID");
	var Grp=document.getElementById("GrpSel");
	var GrpName=document.getElementById("GrpName");
	if(id.value=="" || Grp.value=="0" || GrpName.value=="")
		{	alert("Request all field.");		
			return false;
		}
}
function chkNull(){
	var catID=document.getElementById("catID");
	var catName=document.getElementById("catName");
	if(catID.value=="" || catName.value==""){
	alert("Request all field.");return false
	}
}
function chkNull2(){
	var catID=document.getElementById("Sub1ID");
	var catName=document.getElementById("Sub1Name");
	if(catID.value=="" || catName.value==""){
	alert("Request all field.");return false
	}
}
function hl2(qu){
		chk=document.getElementById("chk"+qu);
		datas=document.getElementById("data"+qu);			
		if(chk.checked==true){		datas.style.backgroundColor="#e8f9ff"; 		return false;		}			
		datas.style.backgroundColor="#ffffff"; 		
}	
function mover(element){
	document.getElementById(element.id).style.backgroundColor="#e8f9ff"; 
}	  
function mout(element,qu){
	 chk=document.getElementById("chk"+qu);
	 if(chk.checked==true) return false;
	 document.getElementById(element.id).style.backgroundColor="#ffffff"; 	
}
function mover2(element){
	//alert(element.id);
	document.getElementById(element.id).style.backgroundColor="#e8f9ff"; 
}	
function mout2(element){
	 document.getElementById(element.id).style.backgroundColor="#ffffff"; 	
}
function ingrp1(tagsname,c){
	//alert(tagsname+c);
	var tags=document.getElementById(tagsname+c);
	if(tags.style.display=="none")
		tags.style.display="";
	else
		tags.style.display="none";
}
function edits(dbName,ID,colv,updates,updateENG){
	
//		alert(dbName+"=>"+ID+"=>"+colv+"=>"+updates+"=>"+oldtxt);
		createXMLHttpRequest();
	offsetEI=document.getElementById("ezE");
	dataDiv=document.getElementById("edtor");
	var url = "../Products/ezEditor.php?dbName="+dbName+"&cID="+ID+"&setis="+updates+"&seteng="+updateENG+"&wheres="+colv;
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { 		
		 	clearDatas();
			setOffsets();
			dataDiv.innerHTML = xmlHttp.responseText;
			dataDiv.style.width = "350px";
		}else{
		 	dataDiv.innerHTML ="<img src='../imgs/loading.gif' />";
		}	
	
	}
	
	xmlHttp.send(null);
	
	

//	var cateno=prompt("Enter data finish click OK or CANCEL.\nname : "+oldtxt);		
//	if(cateno){window.location.assign("../Products/editCategory.php?dbName="+dbName+"&cID="+ID+"&upDTxt="+cateno+"&setis="+updates+"&wheres="+colv);}
	
}

function ckUpdateZ(txtID){
if(document.getElementById(txtID).value==""){ alert("Please, Enter Category name and Click OK"); return false;}
}

function clearDatas(){
	var ind = dataDiv.childNodes.length;
	//alert(ind);
	for(var i=ind -1;i>=0;i--){	
		dataDiv.removeChild(dataDiv.childNodes[i]);
		}
		dataDiv.style.border = 0;
		dataDiv.style.width = "0px";
}
function setOffsets(){

	var end =offsetEI.offsetWidth;
	var top = calculateOffsetTop(offsetEI);
	dataDiv.style.border= "black 1px solid";
//alert("End = "+end+"....Top = " + top + "... offsetEI=");
if(navigator.appName == "Microsoft Internet Explorer" ){
	dataDiv.style.top =  0+ "px";
	dataDiv.style.left = end  + "px";	
}else{ dataDiv.style.left = "0px";}	

	dataDiv.style.top =  top + "px";
	dataDiv.style.left =  end / 2 + "px";
	
}
function calculateOffsetTop(field){
	return calculateOffset(field,"offsetTop");
}
function calculateOffset(field,attr){
	var offset = 0 ;
	while(field){
		offset +=field[attr];
		field = field.offsetParent;
	}
	return offset;
}

function moves(dbName,ID,colv,updates,older,upcol,dbupdate,updateID){
	//alert(dbName+"=>"+ID+"=>"+colv+"=>"+updates+"=>"+older);
	var cateno=prompt("Enter data finish click OK or CANCEL.\nname : "+older);	
	if(cateno){window.location.assign("../Products/moveCategory.php?dbName="+dbName+"&cID="+cateno+"&upDTxt="+cateno+"&setis="+updates+"&wheres="+colv+"&updatis="+upcol+"&dbupdate="+dbupdate+"&whereUpdate="+ID+"&updatwhereis="+updateID);}
}
function delit(dbName,ID,colv){	
	//alert(dbName+"=>"+ID+"=>"+colv);
	var answer=confirm("Please click on OK to continue DELETE or CANCEL.");	
	if(answer)	{window.location.assign("../Products/delCategory.php?dbName="+dbName+"&cID="+ID+"&wheres="+colv);}
}

function delprod(ID){	
//	alert("ProductID =>"+ID);
	var answer=confirm("Please click on OK to continue DELETE or CANCEL.");	
	if(answer)	
	{window.location.assign("delProduct.php?PID="+ID);}
}
function editProd(ID){
	switch(navigator.appName){
		case "Microsoft Internet Explorer" : window.location.assign("productEdit.php?PID="+ID);//parent.window.open("productEdit.php?PID="+ID); 
		break;
		default : window.open("productEdit.php?PID="+ID);//window.location.assign("productEdit.php?PID="+ID);
		break;
		}
}
function pChk(){
	var productid=document.getElementById("productid");
	var productname=document.getElementById("productname");
	var verifyID=document.getElementById("verifyReady");
	if(productid.value=="" || productname.value=="" || verifyID.value==""){
	alert("Request all field.");return false
	}else{
		if(!confirm("Really save this product?")){
			return false;
			}
	}
}
function brand(){
str=window.location.search.substring(1);
	createXMLHttpRequest();
	//var url = "../Products/brand.php?"+str;
	xmlHttp.open("post","../Products/brand.php",true);
	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { 			
			document.getElementById("brand").innerHTML = xmlHttp.responseText;
			
		}else{
			document.getElementById("brand").innerHTML ="<img src='../imgs/loading.gif' />";
		}
	}
	xmlHttp.send(str);
	
	}
function Fbrand(s){
	
	createXMLHttpRequest();
	var url = "../Products/Fbrand.php?f="+s;
	xmlHttp.open("post",url,true);
	xmlHttp.onreadystatechange = function(){
		//alert("Request: "+xmlHttp.readyState+"\n Status:" + xmlHttp.status);
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { 	
		
			document.getElementById("Fbrand").innerHTML =  xmlHttp.responseText;
			
		}else{
			
		 	document.getElementById("Fbrand").innerHTML ="<img src='../imgs/loading.gif' />";
		}
	}
	xmlHttp.send(s);
	
	}	
	
function chBrand(){
document.getElementById('bname').value=document.getElementById('sel_brand')[document.getElementById('sel_brand').selectedIndex].text;
document.getElementById('oldat').value=document.getElementById('sel_brand')[document.getElementById('sel_brand').selectedIndex].value;
}
function frmBrand(element){
	var bname=document.getElementById("bname");	
	var oldat=document.getElementById("oldat");	
	
	createXMLHttpRequest();
if(element.id=="save"){
	var url = "../Products/brand.php?bname="+bname.value+"&oldat="+oldat.value;
}else if(element.id=="del"){
	var url = "../Products/brand.php?dname="+oldat.value;
}

	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { 
		se = window.location.search.substring(1);
		document.getElementById("brand").innerHTML ="";		 
	
		Fbrand(oldat.value);
	
		}else{
		 	document.getElementById("brand").innerHTML ="<img src='../imgs/loading.gif' />";
		}
	
	}
	
	xmlHttp.send(null);
	
	
	
}
function rOver(element){
	switch(navigator.appName){
		case "Microsoft Internet Explorer" :document.getElementById(element.id).setAttribute('className','rollover1'); break;
		default : document.getElementById(element.id).setAttribute("class","rollover1");break;
		}	
}

function searchWord(tagW,url,stype){	

	var SearchW=document.getElementById(tagW);	
	var SearchType=document.getElementById(stype)[document.getElementById(stype).selectedIndex].value;
	if(SearchW.value != ""){
	window.location.assign(url+"?searchGorilla="+SearchW.value+"&stype="+SearchType);
	}else{
		alert("Please, Enter key word.");
		return false;	
	}
	return true;
}

function showSrc1(element,filesname,divid){
	
	createXMLHttpRequest();
	var url = filesname;
	xmlHttp.open("POST",url,true);	
	var id = document.getElementById(element.id)[document.getElementById(element.id).selectedIndex].value;
	var params="findID="+id;
	
	
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");	
	
	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		 	document.getElementById(divid).innerHTML = xmlHttp.responseText;
			switch(divid){
				case "divsub1": 
					document.getElementById("divsub2").innerHTML="";
					document.getElementById("divsub3").innerHTML="";
					document.getElementById("divsub4").innerHTML="";
				break;
				case "divsub2":
					document.getElementById("divsub3").innerHTML="";
					document.getElementById("divsub4").innerHTML="";
				break;
				case "divsub3":
					document.getElementById("divsub4").innerHTML="";
				break;
			}
		}else{
		 	document.getElementById(divid).innerHTML ="<img src='../imgs/loading.gif' />";
		}	
	}
	xmlHttp.send(params);
	
	}	

function ClkImage(pic,old,del,act){	
	var showpic = document.getElementById(pic);
	var oldpic = document.getElementById(old);
	var delpic = document.getElementById(del);
	switch(act){
		case "btndel":
			showpic.value="";			
			delpic.checked=true;
			oldpic.style.display="none";
		break;
		case "txtfile":	
			delpic.checked=true;
			oldpic.style.display="none";
		break;
	}
	
	
}


function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function checkEmail(email) {	
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(email)) {
			//alert('Please provide a valid email address');
			email.focus;
			return false;
		}else{
			return email;	
		}
}

function savepayment(cusname,tel,email,bank,transfer,datetran,timetran,ponum,amount,url){
	createXMLHttpRequest();
	xmlHttp.open("post",url,true);	
	
		var params="cusname="+cusname+"&tel="+tel+"&email="+email+"&bank="+bank+"&transfer="+transfer+"&datetran="+datetran+"&timetran="+timetran+"&ponum="+ponum+"&amount="+amount;
		
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	
	xmlHttp.onreadystatechange =function(){
		
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200){ 
		//setTimeout("window.location.reload();",0);	
		document.getElementById('main').innerHTML =  xmlHttp.responseText;
		}else{
		document.getElementById('main').innerHTML ="<img src='../imgs/loading.gif' />";
		}
	}
	xmlHttp.send(params);	
	
}



