// JavaScript Document

// -----------------------------------------------
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}






function validate_newsletter_form(current_form){
	var message = '';
	if(current_form.user_name.value=='')
		message = message + 'User Name\n';
	
	if(echeck(current_form.user_email.value)==false)
		message = message + 'Email Address\n';
		
		
	if(message=='')
		return true;
	else
		alert('Please check on below fields\n'+ message);
		return false;					
}


function caption_for_homepage(){
	var time_ = new Date();
	greeting = '';
	
	if(time_.getHours()>=0 && time_.getHours() <12)
		greeting = 'Good Morning ';
	if(time_.getHours()>=12 && time_.getHours() <=15)
		greeting = 'Good After Noon ';
	if(time_.getHours()>15 && time_.getHours() <23)
		greeting = 'Good Evening ';	
	
	document.getElementById('main_caption').innerHTML = greeting;
}


function change_company_id(current_form){
	current_form.shipping_zone_id.value = -1;
	current_form.submit();
}


function validate_form(current_form){
	var message = '';
	if(current_form.customer_first_name.value=='')
		message = message + 'First Name\n';
	
	if(current_form.customer_last_name.value=='')
		message = message + 'Last Name\n';

	if(current_form.customer_email.value=='')
		message = message + 'Email\n';

	if(current_form.customer_company.value=='')
		message = message + 'Company \n';

	if(current_form.customer_street_address.value=='')
		message = message + 'Street Address\n';

	if(current_form.customer_post_code.value=='')
		message = message + 'Postal Code\n';

	if(current_form.customer_city.value=='')
		message = message + 'City\n';
		
	
	if(current_form.customer_telephone.value=='')
		message = message + 'Telephone\n';

	if(current_form.customer_password.value=='')
		message = message + 'Password\n';


	if(current_form.customer_password_conf.value=='')
		message = message + 'Password Confirm\n';

	if(current_form.customer_password_conf.value!=current_form.customer_password.value)
		message =  message + 'Passwords does not match\n';	

	if(!current_form.agree.checked){
		alert("We are sorry, It is not advisable to continue without agreeing to our terms and conditions");
		current_form.agree.focus();
		return false;
	}
	
	if(message=='')
		return true;
	else
		alert('Please check on below fields\n'+ message);
		return false;			
	
	}



function check_contact_form(current_form){
	var message = '';
	if(current_form.email.value=='')
		message = message + 'email address\n';
	
	if(current_form.name.value=='')
		message = message + 'name\n';
		
	if(message=='')
		return true;
	else
		alert('Please check on below fields\n'+ message);
		return false;		
}


function check_values(current_form){
	var message = '';
	if(current_form.billing_first_name.value=='')
		message = message + 'first name of billing info\n';
	
	if(current_form.billing_last_name.value=='')
		message = message + 'last name of billing info\n';

	if(current_form.billing_company.value=='')
		message = message + 'company of billing info\n';

	if(current_form.billing_address.value=='')
		message = message + 'address of billing info\n';

	if(current_form.billing_city.value=='')
		message = message + 'city of billing info\n';
		
	if(current_form.billing_state.value=='')
		message = message + 'state of billing info\n';
	
	if(current_form.billing_country.value=='')
		message = message + 'country of billing info\n';
	
	if(current_form.billing_phone.value=='')
		message = message + 'telephone of billing info\n';
		
	if(current_form.billing_email.value=='')
		message = message + 'email of billing info\n';
		
	if(current_form.shipping_first_name.value=='')
		message = message + 'first name of shipping info\n';
	
	if(current_form.shipping_last_name.value=='')
		message = message + 'last name of shipping info\n';

	if(current_form.shipping_company.value=='')
		message = message + 'company of shipping info\n';
		
	if(current_form.shipping_address.value=='')
		message = message + 'address of shipping info\n';

	if(current_form.shipping_city.value=='')
		message = message + 'city of shipping info\n';

	if(current_form.shipping_post_code.value=='')
		message = message + 'Zip Code of shipping info\n';

	if(current_form.shipping_state.value=='')
		message = message + 'state of shipping info\n';
	
	if(current_form.shipping_country.value=='')
		message = message + 'country of shipping info\n';
	
	if(current_form.shipping_phone.value=='')
		message = message + 'telephone of shipping info\n';
		
	if(current_form.shipping_email.value=='')
		message = message + 'email of shipping info\n';
	
	if(message=='')
		return true;
	else
		alert('Please check on below fields\n'+ message);
		return false;
	}
	
	
function bill_to_ship(){
	if(header_info.copydata.checked){
		 header_info.shipping_first_name.value	= header_info.billing_first_name.value ;
		 header_info.shipping_last_name.value	= header_info.billing_last_name.value ;
		 header_info.shipping_company.value	= header_info.billing_company.value ;
		 header_info.shipping_address.value	= header_info.billing_address.value ;
		 header_info.shipping_city.value	= header_info.billing_city.value ;
		 header_info.shipping_state.value	= header_info.billing_state.value ;
		 header_info.shipping_phone.value	= header_info.billing_phone.value ;
		 header_info.shipping_email.value	= header_info.billing_email.value ;
		 header_info.shipping_country.value	= header_info.billing_country.value ;
		 header_info.shipping_post_code.value = header_info.billing_post_code.value ;
		}
	else{
		 header_info.shipping_first_name.value	= '' ;
		 header_info.shipping_last_name.value	= '' ;
		 header_info.shipping_company.value	= '' ;
		 header_info.shipping_address.value	= '' ;
		 header_info.shipping_city.value	= '' ;
		 header_info.shipping_state.value	= '' ;
		 header_info.shipping_phone.value	= '' ;
		 header_info.shipping_email.value	= '' ;
		 header_info.shipping_country.value	= '' ;
		 header_info.shipping_post_code.value	= '' ;

		}
	}
	
	
function gotoadvert(advert_url,advert_id){
	location = 'advert_update_clicks.php?advert_url='+advert_url+'&advert_id='+advert_id ;
	
}




