var	categories=new Array(47);
	categories[0]='Oven';
	categories[1]='Dryer';
	categories[2]='Heater';
	categories[3]='Conditioner';
	categories[4]='Ovens1';
	categories[5]='tools';
	//categories[6]='Microwave';
	categories[6]='Toasters';
	categories[7]='ovens';
	categories[8]='Machines';
	categories[9]='maker';
	categories[10]='Iron';
	categories[11]='Dryers';
	categories[12]='Pumps';
	categories[13]='Deepwell';
	//categories[13]='Neptune';
	categories[14]='Burner';
	categories[15]='Pressure';
	categories[16]='Cleaner';
	categories[17]='Cuisinart';
	categories[18]='frige3';
	categories[19]='Freezer';
	categories[20]='Clothes';
	categories[21]='blender';
	categories[22]='Laser';
	categories[23]='Television';
	categories[24]='Televisions';
	categories[25]='Printers';
	categories[26]='Fax';
	categories[27]='Fans';
	categories[28]='Stereos';
	categories[29]='frige2';
	categories[30]='frige1';
	categories[31]='Incandescent';
	categories[32]='Lights';
	categories[33]='Computers';
	categories[34]='Florescent';
	categories[35]='Satellite';
	categories[36]='Shavers';
	categories[37]='VCRs';
	categories[38]='CDPlayers';
	categories[39]='Answering';
	categories[40]='Telephones';
	categories[41]='Radio';
	categories[42]='wmac';
	categories[43]='Other';
	categories[44]='Others';
	categories[45]='Othersa';
	categories[46]='Othersb';
	
function checkpositive(tocheck)
{  
  if(isNaN(tocheck)) 	
  	  return false;  
  a=Number(tocheck);  
  if(tocheck<0)
    return false;
  if(tocheck>0)
    return true;
   return false;
}


function validate(prefixr)
{
	var prefix = prefixr;	
	estimated = eval('document.table.'+prefix+'e.value');	
	quantity = eval('document.table.'+prefix+'q.value');					
	actual = eval('document.table.'+prefix+'a.value');
	hours = eval('document.table.'+prefix+'h.value');		
	minutes = eval('document.table.'+prefix+'m.value');
			
	wh='';
	if(checkpositive(quantity))
	{		
		if(checkpositive(actual))
		{
			wh = compute(quantity, 0, actual, converttohours(hours, minutes));
			//if(checkpositive(wh))
			{
				wh = Math.round(wh*10000)/10000;
				wh=parseFloat(wh);	
				wh = wh.toFixed( 4 );		
				assignStr = 'document.getElementById("' + prefix + 'w").childNodes[0].nodeValue = wh';
				eval(assignStr);
				eval('document.table.'+prefix+'wh.value=wh');
				computetotals();	
			}
			//else
				;//setnbsp(prefix,hours,minutes);
		}
		else
		{
			wh = compute(quantity, estimated, 0, converttohours(hours, minutes));			
			//if(checkpositive(wh))
			{			
				wh = Math.round(wh*10000)/10000;
				wh=parseFloat(wh);		
				wh = wh.toFixed( 4 );
				assignStr = 'document.getElementById("' + prefix + 'w").childNodes[0].nodeValue = wh';
				eval(assignStr);
				eval('document.table.'+prefix+'wh.value=wh');
				computetotals();
			}
			//else
			//	setnbsp(prefix,hours,minutes);		
		}
	}
	else
	{
		//eval('document.table.'+prefix+'q.focus()');			
		return false;
		//;setnbsp(prefix,hours,minutes);
	}
	return false;
}	

function setnbsp(prefixs)
{
	var prefix = prefixs;	
	assignStr = 'document.getElementById("' + prefix + 'w").childNodes[0].nodeValue = wh';		
	eval(assignStr);
	eval('document.table.'+prefix+'wh.value=wh');
	
	computetotals();	
	return false;
}

function computetotals()
{
	sumtotal =0.0;
	
	for (i=0;i<categories.length;i++)
	{
		assignStr='document.getElementById("' + categories[i] + 'w").childNodes[0].nodeValue';				
		returnvalue = eval(assignStr);		
		if(checkpositive(returnvalue))		
			sumtotal = parseFloat(returnvalue)  + parseFloat(sumtotal);				
	}
	totalv = parseFloat(sumtotal);
	totalv = totalv.toFixed( 4 );
	document.getElementById('total').childNodes[0].nodeValue = totalv;		
	document.table.totalv.value = totalv;		
	
	tenv = parseFloat((sumtotal * 10)/100);
	tenv = tenv.toFixed( 4 );
	document.getElementById('ten').childNodes[0].nodeValue = tenv;		
	document.table.tenv.value = tenv;		
	
	totaltenv = parseFloat(tenv) + parseFloat(totalv);
	totaltenv = totaltenv.toFixed( 4 );
	document.getElementById('totalten').childNodes[0].nodeValue = totaltenv;		
	document.table.totaltenv.value = totaltenv;		
	
	return false;
}
	
function compute(quantity, estimated, actual, hours)
{
	if(hours >0){		
		if(actual >0){
			return (actual * quantity * hours)
		}
		if (estimated >0){
			return (estimated * quantity * hours)
		}			
	}
	else
		return 0;
	return 0;
}


function converttohours(hours, minutes)
{
	if(checkpositive(hours)){
		if(checkpositive(minutes)){			
			fhours = parseFloat(hours) + parseFloat(minutes/60);
			return fhours;
		}
		else{
			return hours;
		}			
	} 
	if (checkpositive(minutes)){
		ahours = parseFloat(minutes/60);
		return ahours;
	}
	
	return 0;
}


function checkNumber(stra, param)
{	
	str = eval('document.table.'+(stra+param)+'.value');		
	str = str.replace(/^\s*|\s*$/g,"");
	var Chars = "0123456789";
	for(var k=0;k<str.length;k++){
		if(Chars.indexOf(str.charAt(k)) == -1)	{		
			if('h'==param)
				ele ="Hrs";
			if('a'==param)
				ele ="Actual Wattage";
			if('q'==param)
				ele ="# of Units";
			if('m'==param)
				ele ="Minutes";
				
			alert("Please enter positive value for : " + ele);
			eval('document.table.'+stra+param+'.focus()');
			return false;
		}		
	}
	//eval('document.user.Ovengo.value=str');			
	//alert(' the value is : ' + document.user.Ovengo.value);
	
	validate(stra);
	return true;
}

function checkPhoneNumber(pstra)
{
	strp = eval('document.user.'+pstra+'.value');	
	if(!strp)
		return false;
	var Chars = "0123456789-()";
	/*if(strp.length<12)
	{
		//alert(" Please enter valid number for : " + pstra);
		//eval('document.user.'+pstra+'.focus()');
		return false;
	}
	for(var l=0;l<strp.length;l++)
	{
		if(Chars.indexOf(strp.charAt(l)) == -1)
		{
			//alert(" Please enter valid number for : " + pstra);			
			//eval('document.user.'+pstra+'.focus()');
			return false;
		}
	}*/
	return true;
}


function checkemail()
{
	var testresults=false;
	stre = document.user.email.value;	
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(stre))
		testresults=true
	else
	{
		//alert("Please input a valid email address!");
		//document.user.email.focus();
		testresults=false		
	}
	return (testresults)
}

function checkname()
{	
	str = document.user.cusname.value;
	//str = str.replace(/^\s*|\s*$/g,"");
	var filter = /^([a-zA-Z ][\w. ]+)$/;	
	if(filter.test(str))	
	    return true;		
	else
	    return false;
}

function checklastname()
{	
	str = document.user.lastname.value;
	//str = str.replace(/^\s*|\s*$/g,"");
	var filter = /^([a-zA-Z ][\w. ]+)$/;	
	if(filter.test(str))	
	    return true;		
	else
	    return false;
}

function checklastcontact()
{
	if (!document.user.phone.value)
	    return document.user.work.value;
	else		
	    return document.user.phone.value;
}

function clearcon(str)
{
	if(str=='phone')
		document.user.phone.value='';
	else
		document.user.work.value='';
}

function checkcontacts()
{
	if(checkname() || checklastname()){
		if(checkPhoneNumber('phone') || checkPhoneNumber('work')){
			if (checkemail()){					
//to=document.user.email.value; 
//cc = "traviss@mobilesolarpower.net";										    
 //name1=document.user.cusname.value;																	

//var sub="Enquiry-data for Mobile Solar Power, by : " + name1 + "'s contact # : " +checklastcontact()  ;			
			//document.table.action="mailto:"+to+"?CC="+cc+"&subject="+sub;				
			
			
				document.table.cusname.value=document.user.cusname.value;
				document.table.lastname.value=document.user.lastname.value;
				//alert("The last name is : ");
				document.table.add1.value=document.user.add1.value;
				document.table.add2.value=document.user.add2.value;
				document.table.los.value=document.user.los.value;
				document.table.phone.value=document.user.phone.value;
				document.table.work.value=document.user.work.value;
				document.table.fax.value=document.user.fax.value;				
				document.table.email.value=document.user.email.value;
				
				document.table.action='sendmail.php';
				document.table.submit();			
				//document.location.href="http://www.mobilesolarpower.net";
				//return true;
			}
			else{
				alert("Please enter valid email address");
				return false;
			}
		}
		else{
			if(checkemail())			
				alert("Please enter valid contact [phone or work] in the format: xxx-xxx-xxxx");
			else
				alert("Please enter valid contact [phone or work] in the format: xxx-xxx-xxxx \n\n Also enter valid email address");
			return false;
		}
	}
	else{
		if(!(checkname() || checklastname()) && !checkemail() && !(checkPhoneNumber('phone') || checkPhoneNumber('work')))
			alert("Please enter your name \n\n Valid contact [phone or work] in the format: xxx-xxx-xxxx \n\n Valid email address");		
		else if(!(checkname() || checklastname()) && !checkemail())
			alert("Please enter your name \n\n Valid email address");		
		else if(!(checkname() || checklastname()) && !(checkPhoneNumber('phone') || checkPhoneNumber('work')))
			alert("Please enter your name \n\n Please enter valid contact [phone or work] in the format: xxx-xxx-xxxx");		
		else if(!(checkname() || checklastname()))
			alert("Please enter your name");		
		return false;		
	}
		
}


function checkcontacts1()
{
		subject="Enquiry for Mobile Solar Power"
		cc = "@yahoo.com"
		to = "@gmail.com";
		name1="";								
		body1="Thank you " + name1 +"\n We will get back yo you soon \n regards \n MSP Team";				
		subject1="Data from user " + to
		//document.table.action="mailto:"+to+"?&cc="+cc+"&subject="+subject1;				
		//document.table.submit();			
		return true;
		
}

function setvalues()
{
	for(k=0;k<categories.length;k++){
		validate(categories[k]);
	}
	//return 0;
}

function resettable()
{
	//alert("cate are : ");
	document.table.reset();
	spac='';
	for(b=0;b<categories.length;b++)
	{
	eval('document.getElementById("' + categories[b] + 'w").childNodes[0].nodeValue = spac');
	eval('document.table.'+categories[b]+'wh.value=spac');
	}
	document.table.totalv.value=spac;
	document.table.tenv.value=spac;
	document.table.totaltenv.value=spac;
	eval('document.getElementById("total").childNodes[0].nodeValue = spac');
	eval('document.getElementById("ten").childNodes[0].nodeValue = spac');
	eval('document.getElementById("totalten").childNodes[0].nodeValue = spac');
}


function resetcontacts()
{
   document.user.reset();
}


