/* Menu hover Link */

//Define your bullet image(s) via arbitrary variables, where bulletimg=["imagepath", imagewidth, offsetxfromroot, offsetyfromroot]

var xmlHttp;
var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";

var bulletimg1=["images/menu_bullet.png", 13, 5, 0]


////Stop editting here/////////////////////
var classnameRE=/(^|\s+)menu($|\s+)/i //regular expression to screen for classname within element

function caloffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function displaybullet(linkobj){
var reltovar=window[linkobj.getAttribute("rel")]
bulletobj.setAttribute("src", reltovar[0])
bulletobj.style.left=caloffset(linkobj, "left")-reltovar[1]-reltovar[1]+"px"
bulletobj.style.top=caloffset(linkobj, "top")-reltovar[3]+"px"
bulletobj.style.visibility="visible"
}

function modifylinks(){
bulletobj=document.createElement("img")
bulletobj.setAttribute("id", "bulletimage")
bulletobj.className="bulletimagestyle"
document.body.appendChild(bulletobj)
for (i=0; i<document.links.length; i++){
if (typeof document.links[i].className=="string" && document.links[i].className.search(classnameRE)!=-1){
document.links[i].onmouseover=function(){displaybullet(this)}
document.links[i].onmouseout=function(){bulletobj.style.visibility="hidden"}
}
}
}

if (window.addEventListener)
window.addEventListener("load", modifylinks, false)
else if (window.attachEvent)
window.attachEvent("onload", modifylinks)
else if (document.getElementById || document.all)
window.onload=modifylinks













function chLang(ln)
{
document.chgLngForm.lang.value=ln;
document.chgLngForm.submit();
}

function showStatus(sMsg)
 {
   window.status = sMsg ;
   return true ;
 }



function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") {
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") {
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) {
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
   }
   return retValue;
}

function Trim(s,Field) 
   {
   	// Remove leading spaces and carriage returns
   	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
   	 { s = s.substring(1,s.length); }
     
   	// Remove trailing spaces and carriage returns
 while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
   	 { s = s.substring(0,s.length-1); }
     
   	//return s;
   	//document.this.Form.this.Field.value=s;
   	document.getElementById(Field).value=s;
   }

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }



function maskKeyPress(objEvent) 
	{
	  var iKeyCode;  	
	  iKeyCode = objEvent.keyCode;			
	  if(iKeyCode>=48 && iKeyCode<=57) return true;
	  return false;
	}
	
	
function checkemail(emailadd)
{
	var result = false;
  	var theStr = new String(emailadd);
  	var index = theStr.indexOf("@");
  	if (index > 0)
  	{
    	var pindex = theStr.indexOf(".",index);
    	if ((pindex > index+1) && (theStr.length > pindex+2))
		result = true;
		else
		alert("Please enter the valid email")
  	}
  	else {
  	      alert("Please enter the valid email")
  	      return false;
  	     }
  		
  	return result;
}


function numbersonly(e){
var unicode=e.charCode? e.charCode : e.keyCode
if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
if (unicode<48||unicode>57) //if not a number
return false //disable key press
}
}


// syntax : < return limitlength(this,20) > 

function limitlength(obj, length){
var maxlength=length
if (obj.value.length>maxlength)
obj.value=obj.value.substring(0, maxlength)
}


/* CV file filter by Shaik Amjad */

extArray = new Array(".doc",".ppt", ".xls", ".pdf",".jpg");
function LimitAttach(form, file) 
{
allowSubmit = false;
if (!file) return;
while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
for (var i = 0; i < extArray.length; i++) {
if (extArray[i] == ext) { allowSubmit = true; break; }
}
if (allowSubmit)
{
return true;
}
else
{
alert("Please only upload files that end in types:  " + (extArray.join("  ")) + "\nPlease select a new "+ "file to upload and submit again.");
return false;
}}

/* Navigate to mainCat list */

function listCatFN(cid,ctype,p_cname,p_sname,p_ssname)
{
docF = document.listCats;

	switch(ctype)
	{
	case "main":
		  docF.cid.value=cid;
		  docF.sid.value=0;
		  docF.ssid.value=0;
		  docF.ctype.value="main";	
			
	break;
	
	case "sub":
		  docF.cid.value=1;
		  docF.sid.value=cid;
		  docF.ssid.value=0;
		  docF.ctype.value="sub";				
	break;
	
	case "subsub":
		  docF.cid.value=1;
		  docF.sid.value=1;
		  docF.ssid.value=cid;
		  docF.ctype.value="subsub";				
	break;
	

	default:
	  docF.cid.value=cid;
	  docF.sid.value=0;
	  docF.ssid.value=0;
	  docF.ctype.value="main";	
    }
    
    
	docF.cname.value=p_cname; 
	docF.sname.value=p_sname; 
	docF.ssname.value=p_ssname; 
    

docF.submit();
}

/* Product functions */

function showDetails(id,lang,mc,sc,ssc)
{
docF = document.details;
docF.id.value=id;
docF.lang.value=lang; 

docF.mcat.value=mc; 
docF.scat.value=sc; 
docF.sscat.value=ssc; 

docF.submit();
}

function printDetails(id)
{
document.getElementById("prodPrint").href="print.php?id="+id
window.self.print();
}


function revealEmailDetails()
{
document.getElementById("mailbar").style.display='';
document.getElementById("mailbar_result").style.display='none';
}


var prod_id;
function wishList(prod_id)
{
	
	document.getElementById("wishlistLoading"+prod_id).style.display='';
	document.getElementById("wishlist_Stat"+prod_id).style.display='';
	document.getElementById("wishlist_Stat"+prod_id).innerHTML="Adding, Please wait...";
	xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
			var url="../../process.php?action=wishList&id="+prod_id;
			document.details.id.value=prod_id;
			xmlHttp.onreadystatechange=dowishList;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);

}

function dowishList()
{
	if (xmlHttp.readyState==4)
	{
	 if(xmlHttp.status==200)
	   {
	    //alert(xmlHttp.responseText);
		prod_id=document.details.id.value;
	    document.getElementById("wishlistLoading"+prod_id).style.display='none';
	    document.getElementById("wishlist_Stat"+prod_id).style.display='';
	    document.getElementById("wishlist_Stat"+prod_id).innerHTML="Successfully added";
	    document.getElementById("wishListLink").style.display='';
	    	document.getElementById("wishListCELL"+prod_id).innerHTML='<img border="0" src="images/gwishlist.png" title="This product already exists in your wishlist">'
	    document.details.id.value="allowsubmit";	
	    
	    xmlHttp=null;
	   }
	   else {
	   	document.getElementById("wishlist_Stat"+prod_id).style.display='';
	   	document.getElementById("wishlist_Stat"+prod_id).innerHTML='Failure';
	    alert("Error: "+xmlHttp.statusText);
	    }
   }
}   












function emailDetails(lang)
{
docF = document.emailProd;
prod_id = docF.id.value;
vemail = docF.email.value;
	if(vemail=="")
	{
	alert ("Please enter your email to send this product information");
	}
	else
	{
	  if(checkemail(vemail))
	   {
	   document.getElementById("loadingx").style.display='';
	      xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null)
			  {
			  alert ("Your browser does not support AJAX!");
			  return;
			  }
			var url="mail/sendProdInfo.php?id="+prod_id+"&email="+vemail+"&lang="+lang;
			xmlHttp.onreadystatechange=showResult;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
	   }
      else
      {
      docF.email.select();
      docF.email.focus();
      return false;
      }     
     } 

}


function showResult() 
{ 
if (xmlHttp.readyState==4)
{
 if(xmlHttp.status==200)
   {
    //alert(xmlHttp.responseText);
    document.getElementById("mailbar").style.display='none';
    document.getElementById("mailbar_result").style.display='';
    document.getElementById("loadingx").style.display='none';
    xmlHttp=null;
   }
   else {
    alert("Error: "+xmlHttp.statusText);
    }
}
}


/* AJax stuff goes here */



function GetXmlHttpObject()
{
 xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}


/* Product multi chek valid */

var len;

function ValidateFormProductSack(dml,chkName)
{
	dml = document.productList;
	len = dml.elements.length;	
	
	
	if(document.details.id.value=="allowsubmit")
	{
	dml.submit();
	return true;
	}
	else	
	{
		var i=0;
		
		for( i=0 ; i<len ; i++)
		 {
			if ((dml.elements[i].name==chkName) && (dml.elements[i].checked==1))
	         {
				dml.submit();
				return true;
		 	 }	
	     }
	alert("Please select atleast one product to order!");
	return false;
    }
}    



function handleCancel()
{
if(confirm('Are you sure you want to cancel your order?'))
{
var url="process.php?action=destroyCart";
window.location=url;
}
}

/* Function to load the pages */

function loadPage(pname)
{
document.whichPage.page.value=pname;
document.whichPage.submit();
}

/* Function to Display special offers in new.php page */

function dispOffers()
{
document.whichPage.page.value="offer";
document.whichPage.action="new.php";
document.whichPage.submit();
}
