

/** used on registration page to copy billing details to delivery details**/
function setDeliveryAddress(){
	document.getElementById('delivery_name').value = document.getElementById('business_name').value;
	document.getElementById('delivery_address_1').value = document.getElementById('address_1').value;
	document.getElementById('delivery_address_2').value = document.getElementById('address_2').value;
	document.getElementById('delivery_address_3').value = document.getElementById('address_3').value;
	document.getElementById('delivery_city').value = document.getElementById('city').value;
	document.getElementById('delivery_postcode').value = document.getElementById('postcode').value;
	document.getElementById('delivery_county').selectedIndex = document.getElementById('county').selectedIndex;
	document.getElementById('delivery_country_id').selectedIndex = document.getElementById('country_id').selectedIndex;
	document.getElementById('delivery_country_name').value = document.getElementById('country_name').value;
}

function setMainImage(img, img2){
	document.getElementById('thumbnail_image').src = img2;
	document.getElementById('main_image').src=img;
		
}

function goToCategory(cat){
	if(cat=="ranges")
		window.location="/all_ranges.php";
	else
		window.location="/category_page.php?id="+cat;	
}

//validation function for order form
function validateOrderForm(){
	if(!validate())
		return false
	return true;
}


//validation function for registration form
function validateRegistration(){
	if(!validate())
		return false
	if(!validateEmailAddress('email_address'))
		return false
	if((document.getElementById('country_id').selectedIndex==0) && (document.getElementById('country_name').value=="")){
		alert("Please Select a Country");
		return false;
	}
	if((document.getElementById('delivery_country_id').selectedIndex==0) && (document.getElementById('delivery_country_name').value=="")){
		alert("Please Select a Delivery Country");
		return false;
	}
		
		
	return true;
}

function validateForm(){
	if(!validate())
		return false
	if(!validateEmailAddress('email_address'))
		return false
	return true;
}

function validateLogin(){
	if(document.getElementById('login_password').value="")
		return false
	if(!validateEmailAddress('login_username'))
		return false
	return true;
}
//check that all fields with classname 'required' are filled in
function validate(){
var elems=document.getElementsByTagName('input'); 
for(var i=0;i<elems.length;i++){
	if((elems[i].className=='required')&&(elems[i].value=="")){
		alert("Please fill in all required fields");
		return false;
	}
}
return true;
}


/*** This validation function checks that an email address contains both '@' and '.' **/
function validateEmailAddress(email_address){
var email = document.getElementById(email_address).value;
	if((email.indexOf('@')==-1)||(email.indexOf('.')==-1)){
		alert("Invalid email address");
		return false;
	}
	else
		return true;
}






/**************** AJAX STUFF **************/

function updateOrder(){
	var text = document.getElementById('instructions').value;
	var url='/ajax/updateSession.php?sess=order&field=instructions&value='+text;
	http.open("GET", url, true);
	http.send(null);
}

function handleUpdateSubSectionMenu() {
  if (http.readyState == 4) {
    // Split the comma delimited response into an array
    results = http.responseText;
    document.getElementById('subsection_menu').innerHTML = results;

  }
  
}
function updateSubSectionMenu(root_dir, type) {
	document.getElementById('subsection_menu').innerHTML = 'Updating......';
 	var a_f = document.getElementById('section').value;
	var url=root_dir+'ajax/subsectionMenu.php?check=suscms&type='+type+'&section='+a_f+'';
	http.open("GET", url, true);
	http.onreadystatechange = handleUpdateSubSectionMenu;
	http.send(null);

}

function setSectionID(value){
	document.getElementByID('section_id').value=value;
}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object



