var manual_or_random="manual"
var randomsetting="3 days"
function getCookie(Name){var re=new RegExp(Name+"=[^;]+","i");if(document.cookie.match(re))
return document.cookie.match(re)[0].split("=")[1]
return null}
function setCookie(name,value,days){var expireDate=new Date()
var expstring=(typeof days!="undefined")?expireDate.setDate(expireDate.getDate()+parseInt(days)):expireDate.setDate(expireDate.getDate()-5)
document.cookie=name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";}
function deleteCookie(name){setCookie(name,"moot")}
function setStylesheet(title,randomize){var i,cacheobj,altsheets=[""]
for(i=0;(cacheobj=document.getElementsByTagName("link")[i]);i++){if(cacheobj.getAttribute("rel").toLowerCase()=="alternate stylesheet"&&cacheobj.getAttribute("title")){cacheobj.disabled=true
altsheets.push(cacheobj)
if(cacheobj.getAttribute("title")==title)
cacheobj.disabled=false}}
if(typeof randomize!="undefined"){var randomnumber=Math.floor(Math.random()*altsheets.length)
altsheets[randomnumber].disabled=false}
return(typeof randomize!="undefined"&&altsheets[randomnumber]!="")?altsheets[randomnumber].getAttribute("title"):""}
function chooseStyle(styletitle,days){if(document.getElementById){setStylesheet(styletitle)
setCookie("mysheet",styletitle,days)}}
function indicateSelected(element){if(selectedtitle!=null&&(element.type==undefined||element.type=="select-one")){var element=(element.type=="select-one")?element.options:element
for(var i=0;i<element.length;i++){if(element[i].value==selectedtitle){if(element[i].tagName=="OPTION")
element[i].selected=true
else
element[i].checked=true
break}}}}
if(manual_or_random=="manual"){var selectedtitle=getCookie("mysheet")
if(document.getElementById&&selectedtitle!=null)
setStylesheet(selectedtitle)}
else if(manual_or_random=="random"){if(randomsetting=="eachtime")
setStylesheet("","random")
else if(randomsetting=="sessiononly"){if(getCookie("mysheet_s")==null)
document.cookie="mysheet_s="+setStylesheet("","random")+"; path=/"
else
setStylesheet(getCookie("mysheet_s"))}
else if(randomsetting.search(/^[1-9]+ days/i)!=-1){if(getCookie("mysheet_r")==null||parseInt(getCookie("mysheet_r_days"))!=parseInt(randomsetting)){setCookie("mysheet_r",setStylesheet("","random"),parseInt(randomsetting))
setCookie("mysheet_r_days",randomsetting,parseInt(randomsetting))}
else
setStylesheet(getCookie("mysheet_r"))}}function trim(str)
{return str.replace(/^\s+|\s+$/g,'');}
function GetXmlHttpObject()
{var xmlHttp=null;try
{xmlHttp=new XMLHttpRequest();}
catch(e)
{try
{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e)
{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}}
return xmlHttp;}
function null_value(gg,form_id)
{document.getElementById('job_err_msg').style.display='none';if(form_id=="1")
{var a=document.form_job;}
else if(form_id=="2")
{var a=document.form_job1;}
if(gg==1)
{if(a.email_job.value=='name@companyname.com')
{a.email_job.value='';if(a.phno_job.value=='')
{a.phno_job.value='10 digits mobile no.';}}
else if(a.email_job.value!=''&&a.phno_job.value=='')
{a.phno_job.value='10 digits mobile no.';}}
else if(gg==2)
{if(a.phno_job.value=='10 digits mobile no.')
{a.phno_job.value='';a.phno_job.select();if(a.email_job.value=='')
{a.email_job.value='name@companyname.com';}}}}
function null_value_blur(dd,form_id)
{document.getElementById('job_err_msg').style.display='none';if(form_id=="1")
{var a=document.form_job;}
else if(form_id=="2")
{var a=document.form_job1;}
if(dd==1)
{if(a.email_job.value=='')
{a.email_job.value='name@companyname.com';}}
else if(dd==2)
{if(a.phno_job.value=='')
{a.phno_job.value='10 digits mobile no.';}}}
function validate_jobalert(form_id)
{if(form_id=="1")
{var a=document.form_job;var b="job_err_msg";}
document.getElementById(b).style.display="none";if(trim(a.email_job.value)==""||a.email_job.value=="name@companyname.com")
{document.getElementById(b).style.display="block";document.getElementById(b).innerHTML="Please enter email address.";a.email_job.value="";a.email_job.focus();return false;}
else if((/^([a-zA-Z]([a-z0-9-_\.\+])+([a-z0-9])@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4}))$/).exec(a.email_job.value)==null)
{document.getElementById(b).style.display="block";document.getElementById(b).innerHTML="Invalid email address format.";a.email_job.focus();return false;}
else if((/^[a-zA-Z][a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$/).exec(a.email_job.value)==null)
{document.getElementById(b).style.display="block";document.getElementById(b).innerHTML="Invalid email address format.";a.email_job.focus();return false;}
else if((/^([a-zA-Z]([a-z0-9-_\.\+])+([a-z0-9])@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4}))$/).exec(a.email_job.value)==null)
{document.getElementById(b).style.display="block";document.getElementById(b).innerHTML="Invalid email address format.";a.email_job.focus();return false;}
else if(trim(a.phno_job.value)==""||a.phno_job.value=="10 digits mobile no.")
{document.getElementById(b).style.display="block";document.getElementById(b).innerHTML="Please enter mobile no.";a.phno_job.value="";a.phno_job.focus();return false;}
else if(trim(a.phno_job.value).length<10)
{document.getElementById(b).style.display="block";document.getElementById(b).innerHTML="Please enter 10 digit mobile no.";a.phno_job.value="";a.phno_job.focus();return false;}
else if(trim(a.phno_job.value).length>10)
{document.getElementById(b).style.display="block";document.getElementById(b).innerHTML="Please enter 10 digit mobile no.";a.phno_job.value="";a.phno_job.focus();return false;}
else if(isNaN(trim(a.phno_job.value)))
{document.getElementById(b).style.display="block";document.getElementById(b).innerHTML="Please enter numaric mobile no.";a.phno_job.value="";a.phno_job.focus();return false;}
add_jobalert(trim(a.email_job.value),trim(a.phno_job.value));}
function add_jobalert(email,ph)
{xmlHttp=GetXmlHttpObject()
if(xmlHttp==null)
{alert("Your browser does not support AJAX!");return;}
else
{xmlHttp.onreadystatechange=stateChanged_gallery_function;url="ajax-php/insert_jobalert.php?subJobalert=1&email_job="+email+"&phno_job="+ph+"&u="+Math.random();xmlHttp.open("GET",url,true);xmlHttp.send(null);}}
function stateChanged_gallery_function()
{if(xmlHttp.readyState==4)
{var str=xmlHttp.responseText;var str_arr=str.split("~");if(str_arr[0]=="2"){jAlert(str_arr[1],'Job Alert');}
var a=document.form_job;a.phno_job.value="10 digits mobile no.";a.email_job.value="name@companyname.com";return false;}}// XMLHttpRequest object created after checking wheather the browser are compatible with ajax.
//============================================================================================
function GetXmlHttpObject()
{ 
  var 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;
}
var subFlag=false;
function dispFunc_1(totallist,p,pg)
{
	if(p=='')
	{
		subFlag=true;
	}
	else
	{
		subFlag=false;
	}
	
	if(p=="up")
	document.getElementById('downrow').selectedIndex=document.getElementById('uprow').selectedIndex;
	else if(p=="down")
	document.getElementById('uprow').selectedIndex=document.getElementById('downrow').selectedIndex;
	
	var catid=document.getElementById('storedcatid').value; 
	
	if(selectedposition == undefined)
	selectedposition=document.getElementById('storedcatlistid').value;
	
	if (selectedposition != undefined && catid != "") 
	{
		dispFunc(catid, totallist, selectedposition, pg)
	}
}

var selectedposition;
function dispFunc(catid,num,id,pg)
{
	//var listsel=document.getElementsByName('testID'); 	
	if(pg == undefined || pg<1){
		pg=1;
	}
	selectedposition=id;
	document.getElementById('storedcatid').value=catid;
	var numRows=document.getElementById('uprow')[document.getElementById('uprow').selectedIndex].text;	
	pagination(catid,pg,numRows,num,id);
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	}
	else
	{		 
		var sel_id=id;
		for(var i=1; i<=num; i++)
		{
			var temp_id1="testID"+i;
			var temp_id=document.getElementById(temp_id1).value;			
			var arrow_id='arraow_'+i;			
			if (temp_id == id) {
				document.getElementById(sel_id).className = "prodBoxLiActive infowayBg";
				document.getElementById(arrow_id).className = "arrow infoway";
			}
			else
			{
				document.getElementById(temp_id).className = "";
				document.getElementById(arrow_id).className = "infoway";
			}
		}
		
		xmlHttp.onreadystatechange=stateChangedproductdetails;
		url="../ajax-php/dispProduct.php?cat_id="+catid+"&numrows="+numRows+"&pagenum="+pg+"&u="+Math.random();
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null); 	
	}	
}

function stateChangedproductdetails()
{
 if (xmlHttp.readyState==4)
 { 
  var str=xmlHttp.responseText;
  var arr=str.split("::##::");
  var catname=arr[0];
  var description=arr[1];
  var productlist=arr[2];
  var logopath=arr[3];
  
  document.getElementById("categorynameDisp").innerHTML=catname;
  document.getElementById("dispDesc").innerHTML=description;
  document.getElementById("targetPrShow").innerHTML=productlist;  
  //document.getElementById("productlogopathid").src=logopath;
 }
}
function pagination(catid,pg,numrows,totalcat,catlistid)
{
	xmlHttp1=GetXmlHttpObject()
	if (xmlHttp1==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	else
	{		 
		xmlHttp1.onreadystatechange=stateChangedPagination;
		url="../ajax-php/dispProduct.php?pagination_cat_id="+catid+"&pg_num="+pg+"&numrows="+numrows+"&t_cat="+totalcat+"&catlistid="+catlistid+"&u="+Math.random();			
		xmlHttp1.open("GET",url,true);
		xmlHttp1.send(null); 	
	}
}
function stateChangedPagination()
{
 if (xmlHttp1.readyState==4)
 { 
  var str1=xmlHttp1.responseText;
  var str_arr=str1.split("~");
  var str=str_arr[1];
  var pg_num=str_arr[0];
  document.getElementById("numproductdispid").innerHTML = str_arr[2];
  if (str != "") {  	
	if (subFlag) 
	{
	document.getElementById("tt11").value = pg_num;
	document.getElementById("tt22").value = pg_num;
	}
	document.getElementById("paginationblock1").style.display = "block";
	document.getElementById("paginationblock2").style.display = "block";
	document.getElementById("selectblock1").style.display = "block";
	document.getElementById("selectblock2").style.display = "block";
	document.getElementById("paginationID1").innerHTML = str;
  	document.getElementById("paginationID2").innerHTML = str;
	document.getElementById("paginationID1").className="paginetion";
	document.getElementById("paginationID2").className="paginetion";
  }
  else
  {
  	document.getElementById("tt11").value="";
	document.getElementById("tt22").value="";
	document.getElementById("paginationblock1").style.display = "none";
	document.getElementById("paginationblock2").style.display = "none";
	if(document.getElementById('uprow').options[document.getElementById('uprow').selectedIndex].value>4)
	{
		document.getElementById("selectblock1").style.display = "block";
		document.getElementById("selectblock2").style.display = "block";
	}
	else
	{
		document.getElementById("selectblock1").style.display = "none";
		document.getElementById("selectblock2").style.display = "none";
	}
	
	document.getElementById("paginationID1").innerHTML = "";
  	document.getElementById("paginationID2").innerHTML = "";
	document.getElementById("paginationID1").className="paginetion_noBorder";
	document.getElementById("paginationID2").className="paginetion_noBorder";
  }
 }
}
// Products downlod
function download(product_id)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	else
	{		 
		xmlHttp.onreadystatechange=stateChangedDownload;
		url="../ajax-php/dispProduct.php?download_id="+product_id+"&u="+Math.random();			
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null); 	
	}
}
function stateChangedDownload()
{
	if (xmlHttp.readyState == 4) {
		var str1 = xmlHttp.responseText;
		var str1_arr=str1.split("~");
		if (str1_arr[0] == 1) {
			window.location.href = str1_arr[1];
		}
		else
		{
			jAlert(str1_arr[1], 'Error');//alert(str1_arr[1])
			return false;
		}
	}
}
// JavaScript Document
function keyRestrict_product(e, validchars,p1,p2,p3) { 
	var key='', keychar='';
	key = getKeyCode(e);
	if (key == null) return true;
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	validchars = validchars.toLowerCase();
	if (validchars.indexOf(keychar) != -1)
	  return true;
	if ( key==null || key==0 || key==8 || key==9 || key==27 )
	 return true;
	else if(key==13)
	dispFunc_1(p1,p2,p3);
	else
	return false;
}
function getKeyCode(e) {
	if (window.event)
	return window.event.keyCode;
	else if (e)
	return e.which;
	else
	return null;
}