// JavaScript Document

please_wait = '<table cellpadding="3" cellspacing="1"><tr><td align="left" valign="middle"><b>please wait</b> ...</td></tr></table>';
alredy_registered = '<table border="0" cellpadding="2" cellspacing="1" bgcolor="#FF0000"><tr><td>&nbsp;</td><td bgcolor="#FFFFFF">The email address you entered has already been registered</td></tr></table>';
login_form = '<table border="0" cellspacing="1" cellpadding="2"><tr><td>Members Login</td><td><input name="email" type="text" class="inputbox" id="email" size="20" /></td><td><input name="password" type="password" class="inputbox" id="password" size="20" /></td><td><input name="button2" type="button" class="go_icon" id="button2" onclick="javscript: login_to_sys()" /></td></tr></table>';

function create_http(){
var xmlhttp = false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {

		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		} catch (E) {
			xmlhttp = false;
			}
	}

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	
	return xmlhttp;
}

function cart_login() {
	var xmlhttp = create_http();
	var email = document.getElementById("cart_email").value;
	var password = document.getElementById("cart_password").value;
	
	if(email=='' || password =='' ){
		alert("Invalid login information");
		return false;	
	}
		
	
	xmlhttp.open("GET", 'ajax-login.php?email='+email+'&password='+password);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			ret_val = xmlhttp.responseText;
			if(ret_val==0){
				alert('Sorry, Invalid login');
			}else{
				location = 'site-cart-19.html';
			}
		}else{
			login_pannel.innerHTML = please_wait;
		}
	}
	xmlhttp.send(null);
}

function chanage_button_image(button_id){
	var image_folder="images/shopping_cart/";
	var btn_profile=document.getElementById("btn_profile");
	var btn_login_settings=document.getElementById("btn_login_settings");
	var my_jobs=document.getElementById("my_jobs");
	var my_orders=document.getElementById("my_orders");

	var buttons=Array(btn_profile,btn_login_settings,my_jobs,my_orders);
	var normal_buttons=Array("my_profile.jpg","settings.jpg","my_jobs.jpg","my_orders.jpg");
	var selected_buttons=Array("my_profile_over.jpg","settings_over.jpg","my_jobs_over.jpg","my_orders_over.jpg");
	for(var i=1;i<=4;i++){
		if(i==button_id){
			buttons[i-1].src=image_folder+selected_buttons[i-1];
		}else{
			buttons[i-1].src=image_folder+normal_buttons[i-1];
		}
	}
}

function order_preview(order_id) {
	var xmlhttp = create_http();
	var breadcrumbs = document.getElementById('breadcrumbs'); // Sandaruwan
	var client_desktop = document.getElementById('client_desktop');
	var randomnumber=Math.random();
	xmlhttp.open("GET",'ajax-order-preview.php?order_id='+order_id+'&rnd='+randomnumber);	
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			client_desktop.innerHTML = xmlhttp.responseText;
			
			var breadcrumbs_text="<a href='javascript: chanage_button_image(3); load_client_desktop(0)'>Desktop</a>";
			breadcrumbs_text+="&nbsp;&raquo;&nbsp;<a href='javascript: chanage_button_image(4); load_client_desktop(3);'>My Orders</a>&nbsp;&raquo;&nbsp;<a href='#'>Order Detail</a>";				 
			breadcrumbs.innerHTML=breadcrumbs_text;
			
		}else{
			client_desktop.innerHTML = please_wait;
		}
	}
	xmlhttp.send(null);
}

function add_to_cart(site_product_id) {
	var xmlhttp = create_http();
	var randomnumber=Math.random();
	
	xmlhttp.open("GET", 'ajax-add-to-cart.php?site_product_id='+site_product_id+'&rnd='+randomnumber);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			
			
			if(xmlhttp.responseText=="true"){
				alert("Item has been added successflly");
				load_cart_summary();
			}else{
				alert("Sorry! You have already added maximum quantity of this item");
			}
		}
	}
	xmlhttp.send(null);

return true;
}

function load_cart_summary() {
	var xmlhttp = create_http();
	var cart_summary = document.getElementById('cart_summary');
	var randomnumber=Math.random();
	
	xmlhttp.open("GET", 'ajax-load-cart-summary.php?rnd='+randomnumber);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			cart_summary.innerHTML = xmlhttp.responseText;
		}else{
			cart_summary.innerHTML = please_wait;
		}
	}
	xmlhttp.send(null);
}

function load_client_job_detail(job_id) {
	var xmlhttp = create_http();
	var breadcrumbs = document.getElementById('breadcrumbs'); // Sandaruwan
	var client_desktop = document.getElementById('client_desktop');
	var randomnumber=Math.random();
	
	xmlhttp.open("GET", 'ajax-client-job-detail.php?job_id='+job_id+'&rnd='+randomnumber);	
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			client_desktop.innerHTML = xmlhttp.responseText;
			
			var breadcrumbs_text="<a href='javascript: chanage_button_image(3); load_client_desktop(0)'>Desktop</a>";
			breadcrumbs_text+="&nbsp;&raquo;&nbsp;<a href='javascript: chanage_button_image(3); load_client_desktop(0)'>Jobs</a>&nbsp;&raquo;&nbsp;<a href='#' >Job Detail</a>";				 
			breadcrumbs.innerHTML=breadcrumbs_text;
		}else{
			client_desktop.innerHTML = please_wait;
		}
	}
	xmlhttp.send(null);
}


function searchTest(){
	
	var text_search=document.getElementById('text_search').value;
	
	var dropdown = document.getElementById('job_status');
	var dropdownIndex = dropdown.selectedIndex;
	var dropdownValue = document.getElementById('job_status')[dropdownIndex].value;
	
	var surveyor	 =document.getElementById('surveyor_id');
	var surveyorIndex = surveyor.selectedIndex;
	var surveyorValue = document.getElementById('surveyor_id')[surveyorIndex].value;
	
	var invoicestatus	 = document.getElementById('invoice_status');
	var invoicestatusIndex = invoicestatus.selectedIndex;
	var invoicestatusValue = document.getElementById('invoice_status')[invoicestatusIndex].value;
	
	var selectedItem  ='&dropdownValue='+dropdownValue+'&surveyorValue='+surveyorValue+'&invoicestatusValue='+invoicestatusValue+'&text_search='+text_search;
		
	var xmlhttp = create_http();
	var client_desktop = document.getElementById('client_desktop');
	var breadcrumbs = document.getElementById('breadcrumbs'); // Sandaruwan
	
	var randomnumber=Math.random();
	xmlhttp.open("GET", 'ajax-client-job-list.php?rnd='+randomnumber+selectedItem);	
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			client_desktop.innerHTML = xmlhttp.responseText;
			//sandaruwan
			var breadcrumbs_text="<a href='javascript: chanage_button_image(3); load_client_desktop(0)'>Desktop</a>";
			breadcrumbs_text+="&nbsp;&raquo;&nbsp;<a href='javascript: chanage_button_image(3); load_client_desktop(0)'>Jobs</a>";
			breadcrumbs.innerHTML=breadcrumbs_text;
		}else{
			client_desktop.innerHTML = please_wait;
		}
	}
	xmlhttp.send(null);

}


function load_client_desktop(screen_number) {
	var xmlhttp = create_http();
	var screens = new Array("ajax-client-job-list.php",
							"ajax-edit-login-settings.php",
							"ajax-edit-client-profile.php",
							"ajax-client-order-list.php",
							"ajax-client-job-detail.php");
	
	var client_desktop = document.getElementById('client_desktop');
	var breadcrumbs = document.getElementById('breadcrumbs'); // Sandaruwan
	
	//alert('awaaaaaa'+'aaaa');
	var randomnumber=Math.random();
	xmlhttp.open("GET", screens[screen_number]+'?rnd='+randomnumber);	
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			client_desktop.innerHTML = xmlhttp.responseText;
			//sandaruwan
			var breadcrumbs_text="<a href='javascript: chanage_button_image(3); load_client_desktop(0)'>Desktop</a>";
			switch(screen_number){
				case 0:
					breadcrumbs_text+="&nbsp;&raquo;&nbsp;<a href='javascript: chanage_button_image(3); load_client_desktop(0)'>Jobs</a>";
				  break;
				case 1:
					breadcrumbs_text+="&nbsp;&raquo;&nbsp;<a href='javascript: chanage_button_image(2); load_client_desktop(1)'>Settings</a>";
				  break;
				case 2:
					breadcrumbs_text+="&nbsp;&raquo;&nbsp;<a href='javascript: chanage_button_image(1); load_client_desktop(2)'>My Profile</a>";
				  break;				
				case 3:
					breadcrumbs_text+="&nbsp;&raquo;&nbsp;<a href='javascript: chanage_button_image(4); load_client_desktop(3)'>My Orders</a>";
				  break;
				case 4:
					breadcrumbs_text+="&nbsp;&raquo;&nbsp;<a href='javascript: chanage_button_image(3); load_client_desktop(0)'>Jobs</a>&nbsp;&raquo;&nbsp;<a href='javascript:load_client_desktop(4)'>Job Detail</a>";
				  break;
			}
			breadcrumbs.innerHTML=breadcrumbs_text;
		}else{
			client_desktop.innerHTML = please_wait;
		}
	}
	xmlhttp.send(null);
}


function logoff_sys() {
	var xmlhttp = create_http();
	var login_pannel = document.getElementById("login_pannel");
	var randomnumber=Math.random();
	server_page = "ajax-logout.php?&rand="+randomnumber;

	xmlhttp.open("GET", server_page);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			location = 'home.html';
		}else{
			login_pannel.innerHTML = please_wait;
		}
	}
	xmlhttp.send(null);
}

function login_to_sys() {
	var xmlhttp = create_http();
	var login_pannel = document.getElementById("login_pannel");
	var email = document.getElementById("email").value;
	var password = document.getElementById("password").value;
	
	if(email=='' || password =='' ){
		alert("Invalid login information");
		return false;	
	}
		
	
	xmlhttp.open("GET", 'ajax-login.php?email='+email+'&password='+password);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			ret_val = xmlhttp.responseText;
			if(ret_val==0){
				alert('Sorry, Invalid login');
				login_pannel.innerHTML = login_form;
			}else if(ret_val==1){
				location = 'desktop.html';
			}else{
				location='client/auto-logon.php?key='+ret_val;	
			}
		}else{
			login_pannel.innerHTML = please_wait;
		}
	}
	xmlhttp.send(null);
}



function check_email_availability(email){
	var xmlhttp = create_http();
	var email_message = document.getElementById('email_message');
	var email_box = document.getElementById('email');
	var randomnumber=Math.random();
	server_page = "ajax-check-email-availability.php?email="+email+"&rand="+randomnumber;
	xmlhttp.open("GET", server_page);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			if(xmlhttp.responseText==1){
				email_message.innerHTML = alredy_registered;
				email_box.value = '';
				email_box.focus();
			}else{
				email_message.innerHTML = '';
			}
		}else{
			email_message.innerHTML = please_wait;
		}
	}
	xmlhttp.send(null);	
	
}

function validate_client_registraion_form(form){
	if(form.first_name.value==''){
		alert("Please enter your first name");
		form.first_name.focus();
		return false;
	}
	
	if(form.last_name.value==''){
		alert("Please enter your last name");
		form.last_name.focus();
		return false;
	}
	
	if(form.account_type.options[form.account_type.selectedIndex].value==0){
		alert("Please select your Account Type");
		form.account_type.focus();
		return false;
	}	
	
	if (form.email.value.indexOf("@") <= 0 || form.email.value.indexOf(".") <= 0 ){
		alert("The format of the \"e-mail\" address is incorrect. Please enter in the format 'john@aol.com'");
		form.email.focus();
		return false;
	}

	if(form.password.value==''){
		alert("Please enter a password");
		form.password.focus();
		return false;
	}	

	if(form.password.value != form.password_confirmation.value){
		alert("Password and Password Confirmation do not match each other");
		form.password_confirmation.focus();
		return false;
	}	
	
	if(form.billing_address1.value==''){
		alert("Please enter Billing Address");
		form.billing_address1.focus();
		return false;
	}
	if(form.billing_city.value==''){
		alert("Please enter Billing City");
		form.billing_city.focus();
		return false;
	}
	if(form.billing_state.value==''){
		alert("Please enter Billing County");
		form.billing_state.focus();
		return false;
	}
	if(form.billing_postcode.value==''){
		alert("Please enter Billing Post Code");
		form.billing_postcode.focus();
		return false;
	}
	if(form.billing_telephone_direct.value==''){
		alert("Please enter Billing Direct Telephone");
		form.billing_telephone_direct.focus();
		return false;
	}
	//--Office
	if(form.office_name.value==''){
		alert("Please enter Office Name");
		form.office_name.focus();
		return false;
	}
	if(form.office_address1.value==''){
		alert("Please enter Office Address");
		form.office_address1.focus();
		return false;
	}
	if(form.office_city.value==''){
		alert("Please enter Office City");
		form.office_city.focus();
		return false;
	}
	if(form.office_state.value==''){
		alert("Please enter Office County");
		form.office_state.focus();
		return false;
	}
	if(form.office_postcode.value==''){
		alert("Please enter Office Post Code");
		form.office_postcode.focus();
		return false;
	}
	if(form.office_telephone_direct.value==''){
		alert("Please enter Office Direct Telephone");
		form.office_telephone_direct.focus();
		return false;
	}

	validation_code = String(form.validation_code.value);
	if(isNaN(parseInt(form.validation_code.value)) || validation_code.length <4){
		alert("Please enter validation code as shown on screen");
		form.validation_code.focus();
		return (false);	
	}		
	return true;
}

function validate_client_profile_form(form){
	//billing
	if(form.first_name.value==''){
		alert("Please enter your first name");
		form.first_name.focus();
		return false;
	}
	
	if(form.last_name.value==''){
		alert("Please enter your last name");
		form.last_name.focus();
		return false;
	}
	
	if(form.account_type.options[form.account_type.selectedIndex].value==0){
		alert("Please select your Account Type");
		form.account_type.focus();
		return false;
	}	
	
	if(form.billing_address1.value==''){
		alert("Please enter Billing Address");
		form.billing_address1.focus();
		return false;
	}
	
	if(form.billing_city.value==''){
		alert("Please enter Billing City");
		form.billing_city.focus();
		return false;
	}
	
	if(form.billing_state.value==''){
		alert("Please enter Billing County");
		form.billing_state.focus();
		return false;
	}
	
	if(form.billing_postcode.value==''){
		alert("Please enter Billing Post Code");
		form.billing_postcode.focus();
		return false;
	}
	
	if(form.billing_telephone_direct.value==''){
		alert("Please enter Billing Direct Telephone");
		form.billing_telephone_direct.focus();
		return false;
	}
	
	//--Office or home
	if(form.office_name.value==''){
		alert("Please enter Office Name");
		form.office_name.focus();
		return false;
	}
	if(form.office_address1.value==''){
		alert("Please enter Office Address");
		form.office_address1.focus();
		return false;
	}
	if(form.office_city.value==''){
		alert("Please enter Office City");
		form.office_city.focus();
		return false;
	}
	if(form.office_state.value==''){
		alert("Please enter Office County");
		form.office_state.focus();
		return false;
	}
	if(form.office_postcode.value==''){
		alert("Please enter Office Post Code");
		form.office_postcode.focus();
		return false;
	}
	if(form.office_telephone_direct.value==''){
		alert("Please enter Office Direct Telephone");
		form.office_telephone_direct.focus();
		return false;
	}
	return true;
}

function validate_contact_form(form){
	if(form.name.value==''){
		alert("Please enter your name");
		form.name.focus();
		return false;
	}	
	if (form.email.value.indexOf("@") <= 0 || form.email.value.indexOf(".") <= 0 ){
		alert("The format of the \"e-mail\" address is incorrect. Please enter in the format 'john@aol.com'");
		form.email.focus();
		return(false);
	}
	if(form.message.value==''){
		alert("Please enter your message");
		form.message.focus();
		return false;
	}	
	
	validation_code = String(form.validation_code.value);
	if(isNaN(parseInt(form.validation_code.value)) || validation_code.length <4){
		alert("Please enter validation code as shown on screen");
		form.validation_code.focus();
		return false;	
	}		
	return true;
}

// cart checkout
function delivery_same_as_billing(the_form){
	
	if( the_form.billing_same_as_office.checked){
		the_form.delivery_first_name.value = the_form.billing_first_name.value ;
		the_form.delivery_last_name.value = the_form.billing_last_name.value ;
		the_form.delivery_email.value = the_form.billing_email.value ;
		the_form.delivery_address1.value = the_form.billing_address1.value ;
		the_form.delivery_address2.value = the_form.billing_address2.value ;
		the_form.delivery_address3.value = the_form.billing_address3.value ;
		the_form.delivery_city.value = the_form.billing_city.value ;
		the_form.delivery_state.value = the_form.billing_state.value ;
		the_form.delivery_country.value = the_form.billing_country.value ;
		the_form.delivery_zipcode.value = the_form.billing_zipcode.value ;
		the_form.delivery_telephone.value = the_form.billing_telephone.value ;
		the_form.delivery_telephone_direct.value = the_form.billing_telephone_direct.value ;
		the_form.delivery_mobile.value = the_form.billing_mobile.value ;
		the_form.delivery_fax.value = the_form.billing_fax.value ;

	}else{
		the_form.delivery_first_name.value  = '';
		the_form.delivery_last_name.value  = '';
		the_form.delivery_email.value  = '';
		the_form.delivery_address1.value  = '';
		the_form.delivery_address2.value  = '';
		the_form.delivery_address3.value  = '';
		the_form.delivery_city.value  = '';
		the_form.delivery_state.value  = '';
		the_form.delivery_country.value  = 218;
		the_form.delivery_zipcode.value  = '';
		the_form.delivery_telephone.value  = '';
		the_form.delivery_telephone_direct.value  = '';
		the_form.delivery_mobile.value  = '';
		the_form.delivery_fax.value  = '';

	}

}

//validation for cart checkout
function validate_cart_checkout(the_form){

/*billing details*/
	if(the_form.billing_first_name.value==''){
		alert('Please enter billing first name.'); the_form.billing_first_name.focus(); return(false);
	}
	if(the_form.billing_last_name.value==''){
		alert('Please enter billing last name.'); the_form.billing_last_name.focus(); return(false);
	}

	if(the_form.billing_email.value==''){
		alert('Please enter billing e-mail address'); the_form.billing_email.focus(); return(false);
	}

	if (the_form.billing_email.value.indexOf("@") <= 0 || the_form.billing_email.value.indexOf(".") <= 0 ){
		alert("The format of the \"e-mail\" address is incorrect. Please enter in the format 'john@aol.com'");
		the_form.billing_email.focus(); return (false);
	}	
	
	if(the_form.billing_address1.value==''){
		alert('Please enter billing address 1'); the_form.billing_address1.focus(); return(false);
	}
	
	if(the_form.billing_city.value==''){
		alert('Please enter billing city'); the_form.billing_city.focus(); return(false);
	}
	
	if(the_form.billing_state.value==''){
		alert('Please enter billing County'); the_form.billing_state.focus(); return(false);
	}
	
	if(the_form.billing_country.value==''){
		alert('Please enter billing country'); the_form.billing_country.focus(); return(false);
	}
	
	if(the_form.billing_zipcode.value==''){
		alert('Please enter billing post code'); the_form.billing_zipcode.focus(); return(false);
	}
	
	if(the_form.billing_telephone_direct.value==''){
		alert('Please enter billing telephone number'); the_form.billing_telephone_direct.focus(); return(false);
	}
	//if(the_form.billing_fax.value==''){
	//	alert('Please enter billing fax number'); the_form.billing_fax.focus(); return(false);
	//}	
	
	/*delivary details*/
	if(the_form.delivery_first_name.value==''){
		alert('Please enter Property first name.'); the_form.delivery_first_name.focus(); return(false);
	}
	if(the_form.delivery_last_name.value==''){
		alert('Please enter Property last name.'); the_form.delivery_last_name.focus(); return(false);
	}

	if(the_form.delivery_email.value==''){
		alert('Please enter Property e-mail address'); the_form.delivery_email.focus(); return(false);
	}

	if (the_form.delivery_email.value.indexOf("@") <= 0 || the_form.delivery_email.value.indexOf(".") <= 0 ){
		alert("The format of the \"e-mail\" address is incorrect. Please enter in the format 'john@aol.com'");
		the_form.delivery_email.focus(); return (false);
	}	
	
	if(the_form.delivery_address1.value==''){
		alert('Please enter Property address 1'); the_form.delivery_address1.focus(); return(false);
	}

	
	if(the_form.delivery_city.value==''){
		alert('Please enter Property city'); the_form.delivery_city.focus(); return(false);
	}
	
	if(the_form.delivery_state.value==''){
		alert('Please enter Property County'); the_form.delivery_state.focus(); return(false);
	}
	
	if(the_form.delivery_country.value==''){
		alert('Please enter Property country'); the_form.delivery_country.focus(); return(false);
	}
	
	if(the_form.delivery_zipcode.value==''){
		alert('Please enter Property post code'); the_form.delivery_zipcode.focus(); return(false);
	}
	
	if(the_form.delivery_telephone_direct.value==''){
		alert('Please enter Property telephone number'); the_form.delivery_telephone_direct.focus(); return(false);
	}
	
	/*if(the_form.delivery_telephone.value==''){
		alert('Please enter Alternative Phone number'); the_form.delivery_telephone.focus(); return(false);
	}*/
	//if(the_form.delivery_fax.value==''){
	//	alert('Please enter delivery fax number'); the_form.delivery_fax.focus(); return(false);
	//}	
 
	return(true);
}

 

function get_detail(email,error_display,sql_id,error_count,system_order_id) {
	var xmlhttp = create_http();
	var container = document.getElementById(error_display);
	var error_container = document.getElementById('error_container');
	var randomnumber=Math.random();
	container.innerHTML ='';
	 
	
	
	server_page = "ajax-check-site-edit.php?email="+email+"&rand="+randomnumber+"&sql_id="+sql_id+"&system_order_id="+system_order_id;
	xmlhttp.open("GET", server_page);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		 
			document.getElementById('error_div').innerHTML=xmlhttp.responseText;
			
			if(get_error_message(document.getElementById('error_div').innerHTML)==true && email!=''){
				error_count ++;
				error_container.value = error_count;
				if(error_container.value>0){ 
					switch(sql_id){
						case 1:{
							document.getElementById('email').select();
							document.getElementById('email').focus();
						}break;
						
						case 2:{
							document.getElementById('sub_domain').select();
							document.getElementById('sub_domain').focus();
						}break;
						
						case 3:{
							document.getElementById('live_domain').select();
							document.getElementById('live_domain').focus();
						}break;
					} 
					document.forms["site_info"].save.disabled=true;
				}
				
			}else{
				error_count --;
				error_container.value = error_count;
				if(error_container.value==0){
					document.forms["site_info"].save.disabled=false;
					document.getElementById('error_div').innerHTML=""; 
				}
			}
		}else{
			document.getElementById('error_div').innerHTML=""; 
		}
	}
	xmlhttp.send(null);
}

function get_error_message(message){
	if(message=='Sorry, this email address is already in use. Please use another'){
		return true;
	}else if(message=='Sorry, this sub domain is already in use. Please use another'){
		return true;
	}else if(message=='Sorry, this live domain is already in use. Please use another'){
		return true;
	}else{
		return false;	
	}
}

function change_address_infomation_text(selObj){
	home_div = document.getElementById('home_address_info');
	headoffice_div = document.getElementById('headoffice_address_info');
	
	if(selObj.options[selObj.selectedIndex].value!=3){
		home_div.style.display = 'none';
		headoffice_div.style.display = 'block';
	}else{
		home_div.style.display = 'block';
		headoffice_div.style.display = 'none';
	}	
}
//office_  billing_
function others_same_as_billing(the_form){
	if( the_form.others_same_as_office.checked){
		the_form.billing_address1.value = the_form.office_address1.value;
		the_form.billing_address2.value = the_form.office_address2.value;
		the_form.billing_address3.value = the_form.office_address3.value;
		the_form.billing_city.value = the_form.office_city.value;
		the_form.billing_state.value = the_form.office_state.value;
		the_form.billing_country.value = the_form.office_country.value;
		the_form.billing_postcode.value = the_form.office_postcode.value;
		the_form.billing_telephone_direct.value = the_form.office_telephone_direct.value;
		the_form.billing_telephone.value = the_form.office_telephone.value;
		the_form.billing_mobile.value = the_form.office_mobile.value;
		the_form.billing_fax.value = the_form.office_fax.value;
	}else{
		the_form.billing_address1.value = '';
		the_form.billing_address2.value = '';
		the_form.billing_address3.value = '';
		the_form.billing_city.value = '';
		the_form.billing_state.value = '';
		the_form.billing_country.value = 218; // default country United Kingdom
		the_form.billing_postcode.value = '';
		the_form.billing_telephone_direct.value = '';
		the_form.billing_telephone.value = '';
		the_form.billing_mobile.value = '';
		the_form.billing_fax.value = '';
	}
}


function agree_terms_and_condition(id){
	var chkItem = document.getElementById(id);
	if(chkItem.checked){
		//if(confirm('Are you sure that you need to confirm and pay ?')){
			location='confirm-order.php';
		//}
	}else{
		alert("You must accept the terms and conditions before placing your order");
	}
}

function ask_for_credit_payment(){ 
	if(document.getElementById("credit_payment").checked){ 
		var confirmed=confirm("Are you sure you want to proceed?");
		
		if(confirmed==true){
			return true;
		}else{
			return false;	
		}
	}else{
		return false;
	}
}

function enable_credit_payment(){
	if(document.getElementById("credit_payment").checked){
		document.getElementById("btnProceed").disabled=false; 
		if(document.getElementById("img_google_checkout")!=null){
			document.getElementById("img_google_checkout").disabled=true; 
		}
		if(document.getElementById("img_paypal_checkout")!=null){
			document.getElementById("img_paypal_checkout").disabled=true; 
		}
		
	}else{
		document.getElementById("btnProceed").disabled=true;
		if(document.getElementById("img_google_checkout")!=null){
			document.getElementById("img_google_checkout").disabled=false; 
		}
		if(document.getElementById("img_paypal_checkout")!=null){
			document.getElementById("img_paypal_checkout").disabled=false; 
		}
	}
}

//____________________________________________________________________________________________________________________________

function load_search_result() {	
	var xmlhttp = create_http();
	var search_key = 0;
	var search_result = document.getElementById('search_result');
	var randomnumber=Math.random();
	
	search_key = document.getElementById('search_key').value;
	
	xmlhttp.open("GET", 'ajax-show-search-result.php?search_key='+search_key+'&rnd='+randomnumber);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			search_result.innerHTML = xmlhttp.responseText;
		}else{
			search_result.innerHTML = please_wait;
		}
	}
	xmlhttp.send(null);
}


function load_search_result1(header_search) {	
	var xmlhttp = create_http();
	var search_key = 0;	
	var search_result = document.getElementById('search_result');
	var randomnumber=Math.random();
	
	if(header_search!=''){
	    search_key = header_search;			
	} else{
		search_key = document.getElementById('search_key').value;
	}
	
	
	xmlhttp.open("GET", 'ajax-show-search-result.php?search_key='+search_key+'&rnd='+randomnumber);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			search_result.innerHTML = xmlhttp.responseText;
		}else{
			search_result.innerHTML = please_wait;
		}
	}
	xmlhttp.send(null);
}


function validate_add_testimonials(form){
	if(form.first_name.value==''){
		alert("Please enter your First name");
		form.first_name.focus();
		return false;
	}	
	
	if(form.last_name.value==''){
		alert("Please enter your Last name");
		form.last_name.focus();
		return false;
	}
	
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var address = form.email.value;
	if (reg.test(address) == false ){
		alert("Please Enter Valid Email Address");
		form.email.focus();
		return(false);
	}
	
	if(form.testimonial.value==''){
		alert("Please enter your Comments");
		form.testimonial.focus();
		return false;
	}	
	
	validation_code = String(form.validation_code.value);
	if(isNaN(parseInt(validation_code)) || validation_code.length <4){
		alert("Please enter validation code as shown on screen");
		form.validation_code.focus();
		return false;	
	}		
	return true;
}


function validate_subscribe_newsletters(form){
//alert(document.getElementById("email_error").value);
	if(form.first_name.value==''){
		alert("Please enter your First name");
		form.first_name.focus();
		return false;
	}
	
	if(form.last_name.value==''){
		alert("Please enter your Last name");
		form.last_name.focus();
		return false;
	}
	
	if(form.email.value==''){
		alert("Please enter your Email Address");
		form.email.focus();
		return false;
	}
	
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	
	if(reg.test(form.email.value) == false){
		alert("Please enter Valid Email Address");
		form.email.focus();
		return false;
	}

	/*if(!validate_text("first_name","Please enter a valid First Name"))return false;
	if(!validate_text("last_name","Please enter a valid Last Name"))return false;
	
	var valid=validate_email(document.getElementById("email").value);
	
	if(valid==false){
		alert('Please enter a valid Email Address');
		document.getElementById("email").focus();
		return false;
	}*/
	
	//if(!validate_text("address","Please enter a valid Address"))return false;
//	if(!validate_text("city","Please enter a valid City"))return false;
//	if(!validate_text("county","Please enter a valid County"))return false;
//	if(!validate_text("postcode","Please enter a valid Post Code"))return false;
//	if(!validate_text("phone_daytime","Please enter a valid Phone Day"))return false;
//	if(!validate_text("phone_evening","Please enter a valid Phone Evening"))return false;
//	if(!validate_text("phone_mobile","Please enter a valid Phone Mobile"))return false;
//	if(!validate_text("phone_fax","Please enter a valid Fax"))return false;
	return true;
}

function check_reference(order_ref){
	var rand = Math.random()*50000;
	xmlHttp=create_http()
	if (xmlHttp != null) {			
		xmlHttp.open("GET", "ajax-check-order-referece.php?order_ref="+order_ref+"&rand"+rand, true);
		xmlHttp.onreadystatechange = set_order_ref_output;
		xmlHttp.send(null);
	}

}
function set_order_ref_output(){
	//document.getElementById('clent_ref_out').value = "Please Wait..."
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200){	
		if(xmlHttp.responseText == " "){
			//document.getElementById('order_ref_out').style.color= "#FF0000";	
			document.getElementById('order_ref_out').innerHTML = xmlHttp.responseText;
			document.getElementById('continue').disabled = false;
		} else {
			//document.getElementById('order_ref_out').style.color= "#D32929";	
			document.getElementById('order_ref_out').innerHTML = xmlHttp.responseText;
			document.getElementById('purchase_order_number').focus();
			document.getElementById('continue').disabled = true;			
		}	
	}
}
