// JavaScript Document
function isValidEmail(emailid)	// Email Validation
{		
	var email=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	return email.test(emailid);
}
function LTrim( value ) 
{
 var re = /\s*((\S+\s*)*)/;
 return value.replace(re, "$1");
}


function RTrim( value )
{
 var re = /((\s*\S+)*)\s*/;
 return value.replace(re, "$1");
}


function trim( value )
{
  return LTrim(RTrim(value));
}



function iPhoneLoginForm()
{

	if(trim(document.getElementById('useremail').value)=="" || trim(document.getElementById('useremail').value)=="Email" )
	{
		document.getElementById('useremail').focus();
		alert("Please enter your email.");
		return false;
	}
	if(isValidEmail(trim(document.getElementById('useremail').value)) == false) 
	{
		document.getElementById('useremail').focus();
		alert("Please enter valid email.");
		return false;
	}
	
	if(trim(document.getElementById('userpassword').value)=="" || trim(document.getElementById('userpassword').value)=="Password"  )
	{
		document.getElementById('userpassword').focus();
		alert("Please enter your password.");
		return false;
	}
return true;
}

function iPhoneAccountForm()
{

	if(trim(document.getElementById('txtFName').value)=="" || trim(document.getElementById('txtFName').value)=="First Name" )
	{
		document.getElementById('txtFName').focus();
		alert("Please enter first name.");
		return false;
	}
	if(trim(document.getElementById('txtLName').value)=="" || trim(document.getElementById('txtLName').value)=="Last Name" )
	{
		document.getElementById('txtLName').focus();
		alert("Please enter last name.");
		return false;
	}
	
	if(trim(document.getElementById('txtEmail').value)=="" || trim(document.getElementById('txtEmail').value)=="Email" )
	{
		document.getElementById('txtEmail').focus();
		alert("Please enter email address.");
		return false;
	}
	
	if(isValidEmail(trim(document.getElementById('txtEmail').value)) == false) 
	{
		document.getElementById('txtEmail').focus();
		alert("Please enter valid email.");
		return false;
	}
	
	if(trim(document.getElementById('txtPhone').value)=="" || trim(document.getElementById('txtPhone').value)=="Phone Number"  )
	{
		document.getElementById('txtPhone').focus();
		alert("Please enter your phone number.");
		return false;
	}
	
	if(trim(document.getElementById('txtOldPassword').value)=="" || trim(document.getElementById('txtOldPassword').value)=="Old Password")
	{	
		if(trim(document.getElementById('txtNewPassword').value)!="" && trim(document.getElementById('txtNewPassword').value)!="New Password"){
			document.getElementById('txtOldPassword').focus();
			document.getElementById('txtOldPassword').value='';
			alert("Please enter old password.");
			return false;
		}
	}
	if(trim(document.getElementById('txtOldPassword').value)!="" && trim(document.getElementById('txtOldPassword').value)!="Old Password")
	{	
		if(trim(document.getElementById('txtNewPassword').value)=="" || trim(document.getElementById('txtNewPassword').value)=="New Password"){
			document.getElementById('txtNewPassword').focus();
			alert("Please enter new password.");
			return false;
		}
	}
	
	if(trim(document.getElementById('txtOldPassword').value)!="" && trim(document.getElementById('txtOldPassword').value)!="Old Password")
	{	
		if(trim(document.getElementById('txtNewPassword').value)=="" || trim(document.getElementById('txtNewPassword').value)!="New Password"){
			if(trim(document.getElementById('txtRePassword').value)=="" || trim(document.getElementById('txtRePassword').value)=="Retype New Password"){
			document.getElementById('txtNewPassword').focus();
			alert("Please enter confirm password.");
			return false;
			}
		}
	}

if(trim(document.getElementById('txtNewPassword').value)=="New Password" && trim(document.getElementById('txtRePassword').value)!="Retype New Password"){
	document.getElementById('txtNewPassword').focus();
	alert("Please enter new password.");
	return false;
}
	
if(trim(document.getElementById('txtNewPassword').value)!="" && trim(document.getElementById('txtNewPassword').value)!="New Password"){
	if(trim(document.getElementById('txtNewPassword').value)!=trim(document.getElementById('txtRePassword').value))
	{
			alert("New password and confirm password should be same");
			document.getElementById('txtRePassword').value="";
			document.getElementById("txtRePassword").focus();
			return false;
	}
}

return true;
}

function iPhoneRegistrationForm()
{

	if(trim(document.getElementById('txtFName').value)=="" || trim(document.getElementById('txtFName').value)=="First Name" )
	{
		document.getElementById('txtFName').focus();
		alert("Please enter first name.");
		return false;
	}
	if(trim(document.getElementById('txtLName').value)=="" || trim(document.getElementById('txtLName').value)=="Last Name" )
	{
		document.getElementById('txtLName').focus();
		alert("Please enter last name.");
		return false;
	}
	
	if(trim(document.getElementById('txtEmail').value)=="" || trim(document.getElementById('txtEmail').value)=="Email" )
	{
		document.getElementById('txtEmail').focus();
		alert("Please enter email address.");
		return false;
	}
	
	if(isValidEmail(trim(document.getElementById('txtEmail').value)) == false) 
	{
		document.getElementById('txtEmail').focus();
		alert("Please enter valid email.");
		return false;
	}
	
	if(trim(document.getElementById('txtPhone').value)=="" || trim(document.getElementById('txtPhone').value)=="Phone Number"  )
	{
		document.getElementById('txtPhone').focus();
		alert("Please enter your phone number.");
		return false;
	}
	

if(trim(document.getElementById('txtNewPassword').value)=="" || trim(document.getElementById('txtNewPassword').value)=="Password"){	
			document.getElementById('txtNewPassword').focus();
			alert("Please enter new password.");
			return false;
		}
		
	

if(trim(document.getElementById('txtRePassword').value)=="" ||  trim(document.getElementById('txtRePassword').value)=="Confirm Password"){
	document.getElementById('txtRePassword').focus();
	alert("Please enter confirm password.");
	return false;
}
	

if(trim(document.getElementById('txtNewPassword').value)!=trim(document.getElementById('txtRePassword').value))
{
		alert("New password and confirm password should be same");
		document.getElementById('txtRePassword').value="";
		document.getElementById("txtRePassword").focus();
		return false;
}
	return true;
}

function iPhoneForgotForm()
{

	if(trim(document.getElementById('useremail').value)=="" || trim(document.getElementById('useremail').value)=="Email" )
	{
		document.getElementById('useremail').focus();
		alert("Please enter your email.");
		return false;
	}
	if(isValidEmail(trim(document.getElementById('useremail').value)) == false) 
	{
		document.getElementById('useremail').focus();
		alert("Please enter valid email.");
		return false;
	}
	return true;
}

function iPhoneDealsForm()
{

	if(trim(document.getElementById('deal_title').value)=="" || trim(document.getElementById('deal_title').value)=="Deal Title" )
	{
		document.getElementById('deal_title').focus();
		alert("Please enter your deal title.");
		return false;
	}
	
	if(trim(document.getElementById('default-usage-select').value)=="" )
	{
		document.getElementById('default-usage-select').focus();
		alert("Please select deal category.");
		return false;
	}

	
	if(trim(document.getElementById('dealsIntroduction').value)=="" || trim(document.getElementById('dealsIntroduction').value)=="Deal Description" )
	{
		document.getElementById('dealsIntroduction').focus();
		alert("Please enter your deal description.");
		return false;
	}

	
	if(trim(document.getElementById('regularPrice').value)=="" || trim(document.getElementById('regularPrice').value)=="Regular Price" )
	{
		document.getElementById('regularPrice').focus();
		alert("Please enter deal price.");
		return false;
	}

	if(trim(document.getElementById('salePrice').value)=="" || trim(document.getElementById('salePrice').value)=="Deal Price" )
	{
		document.getElementById('salePrice').focus();
		alert("Please enter regular price.");
		return false;
	}
		if(!iPhoneSPrice()){
			return false;	
		}
	
}



function iPhoneRPrice()
{
	if(trim(document.getElementById('default-usage-select').value)=="" )
	{
		document.getElementById('default-usage-select').focus();
		document.getElementById('regularPrice').value='';
		alert("Please select deal category first.");
		return false;
	}
}

function iPhoneSPrice()
{
	var set=0;
	var rate = parseFloat(trim(document.getElementById('discount').value));
	var regular = parseFloat(trim(document.getElementById('regularPrice').value));
	var sale = parseFloat(trim(document.getElementById('salePrice').value));
	
	if(isNaN(rate)){rate=0;}else{rate=rate;}
	if(isNaN(regular)){regular=0;}else{regular=regular;}
	if(isNaN(sale)){sale=0;}else{sale=sale;}
	
	var minium = (parseFloat(rate)*parseFloat(regular)/100);
	var minsale = regular-minium;
	if(sale > minsale){
		alert('Sale price can not more than '+minsale);			
		document.getElementById('salePrice').value = '';
		document.getElementById('salePrice').focus();
		return false;
	}else{
		return true;
	}		
}

function iPhoneJobsSForm()
{

	if(trim(document.getElementById('job_title').value)=="" || trim(document.getElementById('job_title').value)=="Job Title" )
	{
		document.getElementById('job_title').focus();
		alert("Please enter your job title.");
		return false;
	}
	
	if(trim(document.getElementById('default-usage-select').value)=="" )
	{
		document.getElementById('default-usage-select').focus();
		alert("Please select deal category.");
		return false;
	}

	
	if(trim(document.getElementById('jobIntroduction').value)=="" || trim(document.getElementById('jobIntroduction').value)=="Job Description" )
	{
		document.getElementById('jobIntroduction').focus();
		alert("Please enter your job description.");
		return false;
	}

}

function anyChecked(boxes) 
	{ 
		for( var i=0; i < boxes.length; i++ ) {
			if( boxes[i].checked == true) {
				return (true);
			} 
		}
		return (false);
	}

function iPhoneLocationSForm()
{

var boxes = document.getElementsByName('deals[]');
	

	if(trim(document.getElementById('businessName').value)=="" || trim(document.getElementById('businessName').value)=="Business Name" )
	{
		document.getElementById('businessName').focus();
		alert("Please enter your business name.");
		return false;
	}
	
	if(trim(document.getElementById('address').value)=="" || trim(document.getElementById('address').value) == 'Number of place/street name/unit number')
	{
		document.getElementById('address').focus();
		alert("Please enter your address.");
		return false;
	}
	
	if(trim(document.getElementById('postalCode').value)=="" || trim(document.getElementById('postalCode').value)=="Postal Code" )
	{
		document.getElementById('postalCode').focus();
		alert("Please enter your postal code.");
		return false;
	}

	if(trim(document.getElementById('phoneNumber').value)=="" || trim(document.getElementById('phoneNumber').value)=="Phone Number" )
	{
		document.getElementById('phoneNumber').focus();
		alert("Please enter your phone number.");
		return false;
	}
	if(trim(document.getElementById('fax').value)=="" || trim(document.getElementById('fax').value)=="Fax Number" )
	{
		document.getElementById('fax').focus();
		alert("Please enter your fax number.");
		return false;
	}

	if(trim(document.getElementById('fax').value)=="" || trim(document.getElementById('fax').value)=="Fax Number" )
	{
		document.getElementById('fax').focus();
		alert("Please enter your fax number.");
		return false;
	}
	
	if(trim(document.getElementById('default-usage-select').value)=="" )
	{
		document.getElementById('default-usage-select').focus();
		alert("Please select country.");
		return false;
	}
	if(trim(document.getElementById('state').value)=="" || trim(document.getElementById('state').value)=="Province/State" )
	{
		document.getElementById('state').focus();
		alert("Please enter your state.");
		return false;
	}

	if(trim(document.getElementById('city').value)=="" || trim(document.getElementById('city').value)=="City" )
	{
		document.getElementById('city').focus();
		alert("Please enter your city.");
		return false;
	}
	
	if(!anyChecked(boxes)){
		document.getElementById('deals').focus();
		alert('Please select at least one category');
		return false;
	}
	

}

function iCalculatPrice(val)
{
	alert(val);
}




