// JavaScript Document

function getOffsets (evt) {
  var target = evt.target;
  if (typeof target.offsetLeft == 'undefined') {
    target = target.parentNode;
  }
  var pageCoords = getPageCoords(target);
  var eventCoords = { 
    x: window.pageXOffset + evt.clientX,
    y: window.pageYOffset + evt.clientY
  };
  var offsets = {
    offsetX: eventCoords.x - pageCoords.x,
    offsetY: eventCoords.y - pageCoords.y
  }
  return offsets;
}

function getPageCoords (element) {
  var coords = {x : 0, y : 0};
  while (element) {
    coords.x += element.offsetLeft;
    coords.y += element.offsetTop;
    element = element.offsetParent;
  }
  return coords;
}

function skey_valid(){
  
  if(!validate_text(document.skey.pkeyword,1,"Please enter the search Keyword")){
	  return false;
  }  
   
  /*if (/^[^\\\/\:\*\?\"\<\>\|\.\+\-]+$/.test(document.skey.pkeyword.value)) {
	// no code  
  }else{
	  alert("This keyword is invalid");
	  document.skey.pkeyword.focus();
	  return false;
  }*/	
  
  return true;
}

 function news_check(){	
	 
	 if(!validate_email(document.news_ff.nemail,1,"Please enter your Email Address")){
	    return false;
	 }
	 
	 var locvl = document.news_ff.nemail.value;
	  locvl = locvl.toLowerCase();
	  locvl = allTrim(locvl);
	
	  if (locvl == "enter email address"){
			 alert ("Please enter your Email Address");
			 document.news_ff.nemail.value = "";
			 document.news_ff.nemail.focus();
			 return false;
	  }
	
     return true;
}

function ns_check(){	 
 if(!validate_email(document.con_ff.nemail,1,"Please enter your Email Address")){
	return false;
 }	 	
 return true;
}
   
function small_check(){
 
 if(!validate_email(document.lgn.t1,1,"Please enter your Email Address")){
	 return;
 }
 
 if(!validate_text(document.lgn.t2,1,"Please enter your Password")){
	 return;
 } 

 document.lgn.submit();
}

function checkk(){
 
 if(!validate_email(document.lgn.t1,1,"Please enter your Email Address")){
	 return false;
 }
 
 if(!validate_text(document.lgn.t2,1,"Please enter your Password")){
	 return false;
 } 

 return true;
}

function l_checkk(){
 
 if(!validate_text(document.m_lgn.t1,1,"Please enter your Username or Email")){
	 return false;
 }
 
 if(!validate_text(document.m_lgn.t2,1,"Please enter your Password")){
	 return false;
 } 

 return true;
}
 
 
function getXmlHttpRequestObject() {
    if (window.XMLHttpRequest) {
      return new XMLHttpRequest();
    } else if(window.ActiveXObject) {
      return new ActiveXObject("Microsoft.XMLHTTP");
    } else {
      alert("Your Browser Sucks!\nIt's about time to upgrade don't you think?");
    }
  }
  
var liveReqp = getXmlHttpRequestObject();
var print_dt = "";
var chng = "";

function getdata(aa,tb,fld,folpth) {			
	chng = fld;
	
	if (window.XMLHttpRequest) {
		liveReqp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveReqp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	var sURL = folpth + "includes/get_cat.php?id="+aa+"&tbl="+tb;
	
	if (tb == "ba"){ // first level
	    combo_field = "";
	    if (document.getElementById("scategory_id")){ combo_field = "scategory_id"; }
		if (document.getElementById("ssid")){ combo_field = "ssid"; }
		if (combo_field != ""){
		nummd =  document.getElementById(combo_field).length;	   
	    while(nummd > 1) {
		   nummd--;
		   document.getElementById(combo_field).options[nummd] = null;
	    }
		}
		
		combo_field = "";
		if (document.getElementById("sscategory_id")){ combo_field = "sscategory_id"; }
		if (document.getElementById("sssid")){ combo_field = "sssid"; }
		if (combo_field != ""){
		nummd =  document.getElementById(combo_field).length;	   
	    while(nummd > 1) {
		   nummd--;
		   document.getElementById(combo_field).options[nummd] = null;
	    }
		}
	}
	
	if (tb == "bb"){ 
	    categoryvalue = "";
	    if (document.getElementById("category_id")){ categoryvalue = document.getElementById("category_id").value; }
		if (document.getElementById("ccid")){ categoryvalue = document.getElementById("ccid").value; }
		sURL = sURL + "&cid=" + categoryvalue;
		
		combo_field = "";
		if (document.getElementById("sscategory_id")){ combo_field = "sscategory_id"; }
		if (document.getElementById("sssid")){ combo_field = "sssid"; }
		if (combo_field != ""){
		nummd =  document.getElementById(combo_field).length;	   
	    while(nummd > 1) {
		   nummd--;
		   document.getElementById(combo_field).options[nummd] = null;
	    }
		}
	}
	
	if (tb == "bc"){ 
	    categoryvalue = "";
	    if (document.getElementById("category_id")){ categoryvalue = document.getElementById("category_id").value; }
		if (document.getElementById("ccid")){ categoryvalue = document.getElementById("ccid").value; }
		
		scategoryvalue = "";
	    if (document.getElementById("brand_id")){ scategoryvalue = document.getElementById("brand_id").value; }
		if (document.getElementById("bbid")){ scategoryvalue = document.getElementById("bbid").value; }
		sURL = sURL + "&cid=" + categoryvalue + "&bid=" + scategoryvalue;		
	}
	
	liveReqp.onreadystatechange = receivercode;
	liveReqp.open("GET", sURL);		
	liveReqp.send(null);
}

function receivercode(){
   if (liveReqp.readyState == 4) {
          
       var nummd =  document.getElementById(chng).length;	   
	   while(nummd > 1) {
		   nummd--;
		   document.getElementById(chng).options[nummd] = null;
	   }				    
	    
		var str=liveReqp.responseText;			
		var str_sr=str.split("#");
		var str_ln=str_sr.length
	
	    for (var k=0;k<str_ln-1;k++){
			 var second_sr=str_sr[k].split("/!");
			 document.getElementById(chng).options[k+1] = new Option(second_sr[0], second_sr[1]);
	    }
	}
 }
 
 function order_det(aa)
   {  
	var url = 'order_det.php?ucode='+aa;
	var ttl = 'Order';
	var params = 'status=yes, resizable=yes ,width=650px, height=600px, top=10px, left=10px, scrollbars=yes, toolbar=no';
	window.open(url, ttl, params);
   }
   
function set_tab_class(div_nm,clasnm){
	document.getElementById(div_nm).className = clasnm;
}   

