
//---------------------only typing numbers---------------------//
function validChars(e, goods) {
	var key, keychar;
	key = (window.event) ? window.event.keyCode : ((e) ? e.which : null);
	if (key == null) return true;

	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();

	if (goods.indexOf(keychar) != -1)
		return true;

	if (key==null || key==0 || key==8 || key==9 || key==13 || key==27)
		return true;

	return false;
}
//--------------------------------------------------------------------

//function for directing to procucts.php
function searchBargainOffers(id){
	
	
	
	if(id=="1"){//for searching tyres
		
		//initial valued for all 3 r set to null
		mcat=scat=size=null;
		
		mcat=document.getElementById('maincats');
		scat=document.getElementById('subcats');
		size=document.getElementById('sizes');
		lot=document.getElementById('lots');	
		
		mcatVal=mcat.options[mcat.selectedIndex].value;
		scatVal=scat.options[scat.selectedIndex].value;
		sizeVal=size.options[size.selectedIndex].value;
		lotVal=lot.options[lot.selectedIndex].value;
		
		//redirect toa different page for bicycle tyres
		
		
		
	  
		location.href = "http://www.dsitire.com/productsOffers.php?lot="+lotVal+"&frm=tr&mcat="+ mcatVal+"&scat="+scatVal+"&size="+sizeVal+"&cur=0&limit=9&str=1";
		
	
	}
	else if(id == "2"){//for searching tubes
		
		tcat=document.getElementById('tubecat');
		rubt=document.getElementById('rubbert');
		size=document.getElementById('sizet');	
		proct=document.getElementById('processt');	
		valve=document.getElementById('valvet');	
		lot=document.getElementById('lots');	
		
		rubtVal=rubt.options[rubt.selectedIndex].value;
		valvetVal=valve.options[valve.selectedIndex].value;
		prctVal=proct.options[proct.selectedIndex].value;
		tcatVal=tcat.options[tcat.selectedIndex].value;
		sizetVal=size.options[size.selectedIndex].value;
		lotVal=lot.options[lot.selectedIndex].value;
		
		location.href = "http://www.dsitire.com/productsOffers.php?lot="+lotVal+"frm=tb&tcat="+tcatVal+"&size="+sizetVal+"&rubbert="+rubtVal+"&process="+prctVal+"&valve="+valvetVal+ "&cur=0&limit=9&str=1";
	
	}
	

}



//function for directing to procucts.php
function search(id){
	
	
	
	if(id=="1"){//for searching tyres
		
		//initial valued for all 3 r set to null
		mcat=scat=size=null;
		
		mcat=document.getElementById('maincats');
		scat=document.getElementById('subcats');
		size=document.getElementById('sizes');	
		
		
		mcatVal=mcat.options[mcat.selectedIndex].value;
		scatVal=scat.options[scat.selectedIndex].value;
		sizeVal=size.options[size.selectedIndex].value;
		
		
		//redirect toa different page for bicycle tyres
		
		
		
	   if(mcatVal=='bicycle')
	   {
	   
	location.href = "http://www.dsitire.com/productsBicycle.php?frm=tr&mcat="+ mcatVal+"&scat="+scatVal+"&size="+sizeVal+"&cur=0&limit=9&str=1";
		}
		else // for other main tyre categories
		{	
		location.href = "http://www.dsitire.com/products.php?frm=tr&mcat="+ mcatVal+"&scat="+scatVal+"&size="+sizeVal+"&cur=0&limit=9&str=1";
		}
	
	}
	else if(id=="2")
	{//for searching tubes
		
		
		
		tcat=document.getElementById('tubecat');
		rubt=document.getElementById('rubbert');
		size=document.getElementById('sizet');	
		proct=document.getElementById('processt');	
		valve=document.getElementById('valvet');	
		
		rubtVal=rubt.options[rubt.selectedIndex].value;
		valvetVal=valve.options[valve.selectedIndex].value;
		prctVal=proct.options[proct.selectedIndex].value;
		tcatVal=tcat.options[tcat.selectedIndex].value;
		sizetVal=size.options[size.selectedIndex].value;
		
		location.href = "http://www.dsitire.com/productsTubes.php?frm=tb&tcat=" + tcatVal + "&size=" + sizetVal + "&rubbert=" +rubtVal+ "&process=" +prctVal+ "&valve=" +valvetVal+ "&cur=0&limit=9&str=1";
	
	}
	if(id == "3")
	{//for searching with thread pattern
		
		
		
		thrd=document.getElementById('id');
		threadVal=thrd.options[thrd.selectedIndex].value;
		//variable holding the index value fro seperation 
		
		//this is to seperate out the option value
		//coming as 'sri number#maincat'
		seperation=threadVal.indexOf('#');
		mcatVal=threadVal.substring(seperation+1);
		thread=threadVal.substring(0,seperation);

		defThrd=thrd.options[1].value;
		defDeperation=defThrd.indexOf('#');
		defMcatVal=defThrd.substring(seperation+1);
		defThrd=defThrd.substring(0,defDeperation);
		////////////////////////////////////////////////	
	
		
		if(mcatVal=='bicycle' || defMcatVal=='bicycle')
		{
			
		    location.href = "http://www.dsitire.com/productsBicycle.php?frm=thrd&thread=" + thread + "&mcat="+ mcatVal+"&limit=" + '9'+"&str=1&defThrd="+defThrd;	
		    	
		}
		else
		{
			
			location.href = "http://www.dsitire.com/products.php?frm=thrd&thread=" + thread +"&limit=" + '9'+"&str=1&defThrd="+defThrd;	
					
		}
		
	}
	

}



function email_validate(caller,destinpage){
	
	value=caller.value;
	error=0;//indicate error exists
	missingAt=1;//implies @ is absent
	missingDot=1;//implies . is absent
	
	if(value!="")
	{
		for(i=0;i<=value.length;i++){
			if(value.charAt(i)=='@')
			missingAt=0;
			
			if(missingAt==0 && value.charAt(i)=='.')
			missingDot=0;
		}
		
		if(missingAt || missingDot)
		error=1;
		
	}
	else
	 error=1;
	
	
	if(error)
	{
	 
  
	if(destinpage!='null')
	 location.href = destinpage;	
	 
	 alert('Invalid e-mail address format.');
	 caller.value="";
	 caller.focus();
	 return false;
	}
	
}

function checkCurrentPw(){
	
	enteredPw=oldpwd=document.getElementById('oldpwd');
	currentPw=oldpwd=document.getElementById('curpw');
	if(enteredPw.value!=currentPw.value)
	{
		alert('Invalid Current Password.');
		enteredPw.value='';
		enteredPw.focus();
		return false;
		
	}
	return true;
}



function check_pwdconfirmation(pwd,cpwd){
	
	oldpwd=document.getElementById('oldpwd');
	newpwd=document.getElementById('newpwd');
	confpwd=document.getElementById('confpwd');
	
	
	
	
	
  
	if(pwd.value!=cpwd.value)
	{
			alert('New Password and Confirmation must be identical.');
			cpwd.value="";
			cpwd.focus();
			error=1;
			
	}
	else	
	if(newpwd.value=="" || confpwd.value=="")
	{
		alert('All fields need to be complete in full.');
		
		if(oldpwd.value=="")
			oldpwd.focus();
		else if(newpwd.value=="")
			newpwd.focus();
		else 
			confpwd.focus();
		
		
		
		return false;
	}
	
	if(error==1)
	 return false;
		
}

function validateDisponDate(){
	
	dispon=document.addownload.dispon.value;
	addon=document.addownload.addon.value;
	
	dateD= value1.substring (0, dispon.indexOf ("-"));
    monthD = value1.substring (dispon.indexOf ("-")+1, dispon.lastIndexOf ("-"));
    yearD = value1.substring (dispon.lastIndexOf ("-")+1,dispon.length);

    dateA= value1.substring (0, addon.indexOf ("-"));
    monthA = value1.substring (addon.indexOf ("-")+1, addon.lastIndexOf ("-"));
    yearA = value1.substring (addon.lastIndexOf ("-")+1,addon.length);
    
    alert(dateD+'/'+monthD+'/'+yearD);
     alert(dateA+'/'+monthA+'/'+yearA);
	
}

//function for validating news details
function validateNewsDetailsInput(flag){
	
	
	
	archon=document.getElementById('archon');
	title=document.getElementById('title');
	details=document.getElementById('details');
	adon=document.getElementById('adon');
	dispon=document.getElementById('dispon');
	if(flag=='edit' && details.value=="")
	{
		alert('All fields need to be complete in full.');
	    return false;
		
	}
	else{
		if(title.value=="" || details.value=="" || adon.value=="" || dispon.value=="" || archon.value==""){
			alert('Fields maked with * need to be complete in full');	
			return false;
		}
	}
}


//this is to check whether username password fiels are empty
function loginValidate(){
	
	
	
	unam=document.index.username.value;
	pwd=document.index.password.value;
	
	if(unam=="" || pwd=="")
	{
	  alert('All fields need to be complete in full.');
	  //a flag indication that this page contains empty fields
	  document.index.empty.value=1;
	  return false;
	}
}

//functions bellow are for interface perposes only from inf design//////////////

function pop_up(url)
{
  window.open(url,'new_window','height=600,width=445,left=0,top=0');
}

function pop_up_close()
{
  self.close();
}

//to confirm deletion
function confirmAction(msg,checked){

	
	if(checked==0)
	{
		alert('Please select picture(s) to remove.')
		return false;
	}
	else
	{
	result=confirm(msg);
	}
	return result;
}

//function to validate user details pages
function validateUserDetails(){
	name=document.getElementById('name');
	company=document.getElementById('company');
	addr=document.getElementById('addr');
	country=document.getElementById('country');
	tp=document.getElementById('tp');
	fax=document.getElementById('fax');
	email=document.getElementById('email');
	
	if(name.value=="" || company.value==""||addr.value==""||country.selectedIndex==0||tp.value==""||fax.value==""||email.value==""){
	  alert('All fields need to be complete in full.');
	  
	  return false;
	}
}

//function for rstricting alphabetical characters and allow only numeric values
/*
function onlyDigits(event,input) {
 if (window.event.keyCode < 46 || window.event.keyCode > 57) {
      window.event.keyCode = 0;
      _ret = false;
    }
}*/
////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
