// JavaScript Document

function  log_validate(){
if(document.login.name.value == "")
{
alert("Please Enter The User Id");
document.login.name.focus();
return false;
}
if(document.login.pwd.value == "")
{
alert("Please Enter The Password:");
document.login.pwd.focus();
return false;
}
return true;
}

function  forgot_validate(){
if(document.forgot.uname.value =="")
{
alert("Please Enter The User Id");
document.forgot.uname.focus();
return false;
}

return true;
}


function register_Validate()
{

if(document.register.customerName.value=="")
	{
		alert("Please enter the name");
		document.register.customerName.focus();
		return false;
	}		
	
 if (!validateEmail(document.register.emailId.value,1,1)) 
	{
		document.register.emailId.focus();
		return false;
	}	
	
	if(document.register.address.value=="")
	{
		alert("Please enter the address");
		document.register.address.focus();
		return false;
	}	
	
	if(document.register.residencePhone.value=="")
	{
		alert("Please enter the phone number");
		document.register.residencePhone.focus();
		return false;
	}	
	
	
	if(document.register.mobilePhone.value=="")
	{
		alert("Please enter the mobile number");
		document.register.mobilePhone.focus();
		return false;
	}	
	if(document.register.customerType.value=="select")
	{
		alert("please select the customer type");
		document.register.customerType.focus();
		return false;
	}
	
	if(document.register.password.value=="")
	{
		alert("Please enter the password");
		document.register.password.focus();
		return false;
	}	
	
	
	if(document.register.password2.value=="")
	{
		alert("Please enter the retype password");
		document.register.password2.focus();
		return false;
	}
	
	
	if(document.register.reference.value=="select")
	{
		alert("please select the How did you hear about Right Win Medias");
		document.register.reference.focus();
		return false;
	}
	
	if(document.register.terms.checked == false ) {
		alert("Please accept Terms And Conditions.");
		document.register.terms.focus();
		return false;
	}
	
	

return true;
}

function sellcellphone_Validate()
{
	
if(document.sellusedcellphones.state.value=="select")
	{
		alert("please select the state");
		document.sellusedcellphones.state.focus();
		return false;
	}
	if(document.sellusedcellphones.city.value=="")
	{
		alert("Please enter the city");
		document.sellusedcellphones.city.focus();
		return false;
	}	
	if(document.sellusedcellphones.noofitems.value=="select")
	{
		alert("please select the no of items");
		document.sellusedcellphones.noofitems.focus();
		return false;
	}
	
	if(document.sellusedcellphones.title.value=="")
	{
		alert("Please enter the title");
		document.sellusedcellphones.title.focus();
		return false;
	}	
		if(document.sellusedcellphones.pickup.value=="")
	{
		alert("Please enter the pickup details");
		document.sellusedcellphones.pickup.focus();
		return false;
	}	
	
	if(document.sellusedcellphones.houseHoldCategory0.value=="select")
	{
		alert("please select the category");
		document.sellusedcellphones.houseHoldCategory0.focus();
		return false;
	}
	
	if(document.sellusedcellphones.householdSubCategory0.value=="select")
	{
		alert("please select the subcategory");
		document.sellusedcellphones.householdSubCategory0.focus();
		return false;
	}
	
	if(document.sellusedcellphones.year0.value=="select")
	{
		alert("please select the year");
		document.sellusedcellphones.year0.focus();
		return false;
	}
	
	if(document.sellusedcellphones.condition0.value=="select")
	{
		alert("please select the condition");
		document.sellusedcellphones.condition0.focus();
		return false;
	}
	
		if(document.sellusedcellphones.purchasePrice0.value=="")
	{
		alert("Please enter the Purchase price");
		document.sellusedcellphones.purchasePrice0.focus();
		return false;
	}	
	
		if(document.sellusedcellphones.askingPrice0.value=="")
	{
		alert("Please enter the Asking price");
		document.sellusedcellphones.askingPrice0.focus();
		return false;
	}	
	
	if(document.sellusedcellphones.owner0.value=="select")
	{
		alert("please select the owner No");
		document.sellusedcellphones.owner0.focus();
		return false;
	}
		
	
		if(document.sellusedcellphones.itemDescription0.value=="")
	{
		alert("Please enter the Description");
		document.sellusedcellphones.itemDescription0.focus();
		return false;
	}	
	//
//	if(document.sellusedcellphones.photo.value=="")
//	{
//		alert("Please upload the photo");
//		document.sellusedcellphones.photo.focus();
//		return false;
//	}	
	

return true;
}

function sellcars_Validate()
{
	
if(document.frm_auto.state.value=="select")
	{
		alert("please select the state");
		document.frm_auto.state.focus();
		return false;
	}
	if(document.frm_auto.city.value=="")
	{
		alert("Please enter the city");
		document.frm_auto.city.focus();
		return false;
	}	
		if(document.frm_auto.title.value=="")
	{
		alert("Please enter the title");
		document.frm_auto.title.focus();
		return false;
	}	
		
	if(document.frm_auto.transmission.value=="select")
	{
		alert("please select the transmission");
		document.frm_auto.transmission.focus();
		return false;
	}
	
	if(document.frm_auto.autoMake.value=="select")
	{
		alert("please select the Make");
		document.frm_auto.autoMake.focus();
		return false;
	}
		if(document.frm_auto.autoModel.value=="")
	{
		alert("Please enter the model");
		document.frm_auto.autoModel.focus();
		return false;
	}	
	
	if(document.frm_auto.year.value=="select")
	{
		alert("please select the year");
		document.frm_auto.year.focus();
		return false;
	}
	
	if(document.frm_auto.noofdoor.value=="select")
	{
		alert("please select the No of Doors");
		document.frm_auto.noofdoor.focus();
		return false;
	}
	
	if(document.frm_auto.fueltype.value=="select")
	{
		alert("please select the fueltype");
		document.frm_auto.fueltype.focus();
		return false;
	}
		
	
		if(document.frm_auto.kmsdriven.value=="")
	{
		alert("Please enter the kmsdriven");
		document.frm_auto.kmsdriven.focus();
		return false;
	}	
	if(document.frm_auto.color.value=="")
	{
		alert("Please enter the color");
		document.frm_auto.color.focus();
		return false;
	}	
	
	if(document.frm_auto.askingprice.value=="")
	{
		alert("Please enter the Asking price");
		document.frm_auto.askingprice.focus();
		return false;
	}	
	if(document.frm_auto.registration.value=="")
	{
		alert("Please enter the registration No");
		document.frm_auto.registration.focus();
		return false;
	}	
	
	if(document.frm_auto.owner.value=="select")
	{
		alert("please select the owner No");
		document.frm_auto.owner.focus();
		return false;
	}
		
	
	

return true;
}


function sellbikes_Validate()
{
	
if(document.frm_bike.state.value=="select")
	{
		alert("please select the state");
		document.frm_bike.state.focus();
		return false;
	}
	if(document.frm_bike.city.value=="")
	{
		alert("Please enter the city");
		document.frm_bike.city.focus();
		return false;
	}	
		if(document.frm_bike.title.value=="")
	{
		alert("Please enter the title");
		document.frm_bike.title.focus();
		return false;
	}	
		
	if(document.frm_bike.transmission.value=="select")
	{
		alert("please select the transmission");
		document.frm_bike.transmission.focus();
		return false;
	}
	
	if(document.frm_bike.bikeMake.value=="select")
	{
		alert("please select the Make");
		document.frm_bike.bikeMake.focus();
		return false;
	}
		if(document.frm_bike.bikeModel.value=="")
	{
		alert("Please enter the model");
		document.frm_bike.bikeModel.focus();
		return false;
	}	
	
	if(document.frm_bike.year.value=="select")
	{
		alert("please select the year");
		document.frm_bike.year.focus();
		return false;
	}
	
	if(document.frm_bike.start.value=="select")
	{
		alert("please select the startmethod");
		document.frm_bike.start.focus();
		return false;
	}
	
	if(document.frm_bike.fueltype.value=="select")
	{
		alert("please select the fueltype");
		document.frm_bike.fueltype.focus();
		return false;
	}
		
	if(document.frm_bike.engine.value=="select")
	{
		alert("please select the engine");
		document.frm_bike.engine.focus();
		return false;
	}
		
	if(document.frm_bike.color.value=="")
	{
		alert("Please enter the color");
		document.frm_bike.color.focus();
		return false;
	}	
	
		if(document.frm_bike.kmsdriven.value=="")
	{
		alert("Please enter the kmsdriven");
		document.frm_bike.kmsdriven.focus();
		return false;
	}	
	
		if(document.frm_bike.cc.value=="")
	{
		alert("Please enter the Engine Capacity(in cc)");
		document.frm_bike.cc.focus();
		return false;
	}	
	
	if(document.frm_bike.askingprice.value=="")
	{
		alert("Please enter the Asking price");
		document.frm_bike.askingprice.focus();
		return false;
	}	
	if(document.frm_bike.registration.value=="")
	{
		alert("Please enter the registration No");
		document.frm_bike.registration.focus();
		return false;
	}	
	
	if(document.frm_bike.owner.value=="select")
	{
		alert("please select the owner No");
		document.frm_bike.owner.focus();
		return false;
	}
		
	
	

return true;
}

	
function sellexchangeitems_Validate()
{
	
if(document.frm_home.state.value=="select")
	{
		alert("please select the state");
		document.frm_home.state.focus();
		return false;
	}
	if(document.frm_home.city.value=="")
	{
		alert("Please enter the city");
		document.frm_home.city.focus();
		return false;
	}	
	
	if(document.frm_home.title.value=="")
	{
		alert("Please enter the title");
		document.frm_home.title.focus();
		return false;
	}	
		
	if(document.frm_home.exchangeCategory.value=="select")
	{
		alert("please select the category");
		document.frm_home.exchangeCategory.focus();
		return false;
	}
	
	if(document.frm_home.exchangeSubCategory.value=="")
	{
		alert("please enter the subcategory");
		document.frm_home.exchangeSubCategory.focus();
		return false;
	}
	
	if(document.frm_home.exchangeDuration.value=="select")
	{
		alert("please select the exchange duration");
		document.frm_home.exchangeDuration.focus();
		return false;
	}
	
	return true;
}

function frm_contact_validate()
{
	
if(document.contact.name.value=="")
	{
		alert("Please enter the name");
		document.contact.name.focus();
		return false;
	}	
	if(document.contact.organisation.value=="")
	{
		alert("Please enter the organisation");
		document.contact.organisation.focus();
		return false;
	}	
	
	if(document.contact.phone.value=="")
	{
		alert("Please enter the phone");
		document.contact.phone.focus();
		return false;
	}	
		
 if (!validateEmail(document.contact.email.value,1,1)) 
	{
		document.contact.email.focus();
		return false;
	}	
	
	if(document.contact.message.value=="")
	{
		alert("Please enter the message");
		document.contact.message.focus();
		return false;
	}	
	
	return true;
}

function validateEmail(addr,man,db) {
	if (addr == '' && man) {
	   if (db) alert('Email Address Is Mandatory');
	   return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  if (db) alert('Email Address Contains Invalid Characters');
		  return false;
	   }
	}
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  if (db) alert("Email Address Contains Non Ascii Characters.");
		  return false;
	   }
	}

	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   if (db) alert('Email Address Must Contain An @');
	   return false;
	}
	if (atPos == 0) {
	   if (db) alert('Email Address Must Not Start With @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   if (db) alert('Email Address Must Contain Only One @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   if (db) alert('Email Address Must Contain A Period In The Domain Name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   if (db) alert('Period Must Not Immediately Follow @ In Email Address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   if (db) alert('Period Must Not Immediately Precede @ In Email Address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	   if (db) alert('Two Periods Must Not Be Adjacent In Email Address');
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   if (db) alert('Invalid Primary Domain In Email Address');
	   return false;
	}
return true;
}

function citysearch_Validate()
{

	if(document.citysearch.category.value=="select")
	{
		alert("please select the category ");
		document.citysearch.category.focus();
		return false;
	}
		if(document.citysearch.subcategory.value=="select")
	{
		alert("please select the subcategory ");
		document.citysearch.subcategory.focus();
		return false;
	}
		if(document.citysearch.city.value=="select city")
	{
		alert("please select the city");
		document.citysearch.city.focus();
		return false;
	}

return true;
}

