// JavaScript Document

var http_request = false;
   function makeRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      http_request.onreadystatechange = alertContents;
      http_request.open('GET', url + parameters, true);
      http_request.send(null);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('theresponse').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function getFormData() {
   
      var getstr = "?";
	  getstr += "adminpwd=" + document.getElementById('adminpwd').value + "&";
	  getstr += "adminemail=" + document.getElementById('adminemail').value + "&";
	  getstr += "orderfootertxt=" + document.getElementById('orderfootertxt').value + "&";
	  getstr += "orderemailtxt=" + document.getElementById('orderemailtxt').value + "&";
	  if(document.getElementById('copyordertobcn').checked)
	  {
	  getstr += "copyordertobcn=y&";
	  }else{
	  getstr += "copyordertobcn=n&";
	  }
	  if(document.getElementById('alwaysemailsupplier').checked)
	  {
	  getstr += "alwaysemailsupplier=y&";
	  }else{
	  getstr += "alwaysemailsupplier=n&";
	  }
	 
	  getstr += "action=" + document.getElementById('action').value;
	  
      makeRequest('updateSystemSettings.asp', getstr);
   }
   
   function remResponse(){
   
   document.getElementById('theresponse').innerHTML=''; 
   
   }
   
   
   
   
   function validate_form ( )
{
    valid = true;
	
	document.contact_form.contact_name.style.border='1px solid #4db2eb';
	document.contact_form.contact_phone.style.border='1px solid #4db2eb';
	document.contact_form.contact_email.style.border='1px solid #4db2eb';
	document.contact_form.contact_region.style.border='1px solid #4db2eb';
	
    if ( document.contact_form.contact_name.value == "Name" || document.contact_form.contact_name.value == "")
    {
        document.contact_form.contact_name.style.border='1px solid red';
        valid = false;
    }
	if ( document.contact_form.contact_email.value == "Email" || document.contact_form.contact_email.value == "")
    {
        document.contact_form.contact_email.style.border='1px solid red';
        valid = false;
		 
    } else {
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   		var eaddress = document.contact_form.contact_email.value;
   		if(reg.test(eaddress) == false) {
		document.contact_form.contact_email.style.border='1px solid red';
      	valid = false;
    	}
	}
	
	
	if ( document.contact_form.contact_phone.value == "Phone Number" || document.contact_form.contact_phone.value == "")
    {
        document.contact_form.contact_phone.style.border='1px solid red';
        valid = false;
    }
	 if ( document.contact_form.contact_region.selectedIndex == 0 )
    {
        document.contact_form.contact_region.style.border='1px solid red';
        valid = false;
    }

    return valid;
}

function clearInput(obj){
if(obj.value=='Name' || obj.value=='Email' || obj.value=='Phone Number' || obj.value=='Comments'){
obj.style.border='1px solid #4db2eb';
obj.value='';
}
}

function checkInput(){
	if ( document.contact_form.contact_name.value == "" ) {
	document.contact_form.contact_name.value="Name"
	}
	if ( document.contact_form.contact_phone.value == "" ) {
	document.contact_form.contact_phone.value="Phone Number"
	}
	if ( document.contact_form.contact_email.value == "" ) {
	document.contact_form.contact_email.value="Email"
	}
	if ( document.contact_form.contact_comments.value == "" ) {
	document.contact_form.contact_comments.value="Comments"
	}
}
