// JScript File

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function checkCharacters(strVal){
	j_maj = strVal.length;
	validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.+,<>#;?- %@1234567890"\'&!=_-:/';
	for(i_maj=0; i_maj<j_maj; i_maj++){
		if (validChars.indexOf(strVal.charAt(i_maj))<0){
			i_maj=99;
			return true;
		}
	}	
	return false;	
}

function YY_checkform() { //v4.71
  //copyright (c)1998,2002 Yaromat.com
  var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
  for (i=1; i<a.length;i=i+4){
    if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
    o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
    o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
    v=o.value;t=a[i+2];
    validChar=false;
    if (o.type=='text'||o.type=='password'||o.type=='hidden'){
      if (r&&v.length==0){err=true}
	  if(checkCharacters(v)){
		  err=true;	
		  validChar=true;
	  }
      if (v.length>0)
      if (t==1){ //fromto
        ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
      } else if (t==2){
        rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
      } else if (t==3){ // date
        ma=a[i+1].split("#");at=v.match(ma[0]);
        if(at){
          cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
          dte=new Date(cy,cm,cd);
          if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
        }else{err=true}
      } else if (t==4){ // time
        ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
      } else if (t==5){ // check this 2
            if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!o1.checked){err=true}
      } else if (t==6){ // the same
            if(v!=MM_findObj(a[i+1]).value){err=true}
      } else if(t==7){ // Execute function with object's value as a parameter
	  	var arrFunc = a[i+1].split('#');
		if(arrFunc[1]!=""){
			eval("var resDynamicCall = "+arrFunc[1]+"('"+v+"')");
			if(resDynamicCall){	}else{ err=true;}
		}
	  }
    } 
	else if (!o.type&&o.length>0&&o[0].type=='radio'){
          at = a[i].match(/(.*)\[(\d+)\].*/i);
          o2=(o.length>1)?o[at[2]]:o;
      if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
      if (t==2){
        oo=false;
        for(j=0;j<o.length;j++){oo=oo||o[j].checked}
        if(!oo){s+='* '+a[i+3]+'\n'}
      }
    } 
	else if (o.type=='checkbox'){
      if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
    } 
	else if (o.type=='select-one'||o.type=='select-multiple'){
      if(t==1&&o.selectedIndex/1==0){err=true}
    }
	else if (o.type=='textarea'){
      if(v.length<a[i+1]){err=true}
    }
    if (err){
		extra_s = '';
		if(validChar) extra_s=' '+'Must be Valid Characters';
		s+='* '+a[i+3]+extra_s+'\n'; 
		err=false;
	}
  }
  if (s!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+s)}
  document.MM_returnValue = (s=='');
}

function addProduct(product_qty,product_id){
	if(product_qty>0){
		FireAjaxRequest("cart_action=add&product_qty="+product_qty+"&product_id="+product_id, "manage_cart.php","myCart","myCart","block");
	}else{
		alert("Please enter quantity for product");
	}
	return false;
}
function showCart(){
	FireAjaxRequest("cart_action=show", "manage_cart.php","myCart","myCart","block");
	return false;
}
function doConversion(){
	valN = document.getElementById('number').value;
	valU = document.getElementById('units').value;
	if(valN>0){
		if(valU == "KL"){
			newV = parseFloat(valN) / 0.4535924;
			strM = "<br / >" + valN + " kg(s) is " + newV.toFixed(2) + " lb(s)<br />";
		}else{
			newV = parseFloat(valN) * 0.4535924;
			strM = "<br / >" + valN + " lb(s) is " + newV.toFixed(2) + " kg(s)<br />";
		}
		
	}else{
		strM = "Please enter proper value for conversion";
	}
	document.getElementById('unitMsg').innerHTML = strM+"<br />";
}
function addLoadEvent(func) { 
  //alert("add");
  var oldonload = window.onload; 
  if (typeof window.onload != 'function') { 
    window.onload = func; 
  } else { 
    window.onload = function() { 
      if (oldonload) { 
        oldonload(); 
      } 
      func(); 
    } 
  } 
} 

function checkContactDetails(){
	var valH = $('txtHome').value;
	var valM = $('txtMobile').value;
	var valE = $('txtEmail').value;
	if((valH)||(valM)){
		return true;
	}
	if(valE){
		rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");
		if(!rx.test(valE))
			return false;
		else
			return true;
	}
	return false;
}

function checkContactDetailsR(){
	var valH = $('txtHome').value;
	var valM = $('txtMobile').value;
	if((valH)||(valM)){
		return true;
	}
	return false;
}
function toggle(objnm)
{
	//alert(document.getElementById(objnm).style.display);
	if(document.getElementById(objnm).style.display	=='none')
	{
		document.getElementById(objnm).style.display='';
		//document.getElementById("btn"+objnm).value='«';
	}
	else
	{
		document.getElementById(objnm).style.display='none';
		//document.getElementById("btn"+objnm).value='»';
	}
	var sHTML = "";
	if (objnm == "divRpt_6") {
		
		sHTML = "<a href='javascript:callEmailGraphOne();'>Send Report</a><br><br><Br><Br>\n";
		sHTML += "<br><br><br><br>\n";
		sHTML += "<div id='chart1div' style='display:none;'>\n";
			
		sHTML += "</div>\n";
		sHTML += "<div id='chart2div' style='display:none;'>";
		sHTML += "</div>\n";
		sHTML += "<br><br><Br><Br><a href='javascript:callEmailGraphOne();'>Send Report</a>\n";
		
		
		document.getElementById('div_list').innerHTML = sHTML;
		
	}
}
function ShowHideDiv(divNo,divTotal){
	for(i=1;i<=divTotal;i++){
		if(parseInt(i)==parseInt(divNo)){
			document.getElementById("div_finance_"+i).style.display = "block";
		}else{
			document.getElementById("div_finance_"+i).style.display = "none";
		}
	}
}
function popMap(zipCode){
	WP = window.open('map.php?zip='+zipCode,'dealerMap');
	WP.focus();
}
function openBannerVideo(fileName){
	BW = window.open('player.php?whichType=banner_video&file='+fileName,'bannerVideoWindow',"status,menubar,height=300,width=360");
	BW.focus();
}
function openBannerURL(intBannerID){
	//document.write("<div id='divBannerClick'></div>");	
	FireAjaxRequest("id="+intBannerID, "clickURL.php","divStatus","divStatus","none");
}

function changecss(theClass,element,value) {  
	var cssRules;  
	if (document.all) {  
		cssRules = 'rules';  
	}  
	else if (document.getElementById) {  
		cssRules = 'cssRules';  
	}  
	for (var S = 0; S < document.styleSheets.length; S++){
		for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
			if (document.styleSheets[S][cssRules][R].selectorText == theClass) {  
				document.styleSheets[S][cssRules][R].style[element] = value;  
			}  
		}  
	}       
}
