function validateegl() {
 var reportnum = $F('reportnum');
 var RE = /^(.*)$/i; 
 if (reportnum.match(RE)) {
/*
	Pull back any info available for this certificate
*/   
   var url = 'https://www.diamonds2cash.com/webservice/egl/index.php';
   var pars = 'reportnum=' + reportnum;

   var myAjax = new Ajax.Updater(
		{success: 'ajworkspace'}, 
		url, 
		{
			method: 'get', 
			parameters: pars, 
			evalScripts:true
		});
   return true; 
   
 } else { 
   alert( "Please confirm the EGL report number has been entered correctly." ); 
   return false; 
 } 
}

function validateags() {
   return true; 
}

function validategia() {
 /* Step 1, validate the report number */
 var reportnum = $F('reportnum');
 var caratweight = $F('weight');

 var RE = /([0-9+]{7,8})/i; 
 if (reportnum.match(RE)) {
   /* Step 2, validate carat weight */
   var RE_WEIGHT = /([0-9+]{1,2}\.[0-9+]{1,2})/i; 
   if (caratweight.match(RE_WEIGHT)) {
	   var url = 'https://www.diamonds2cash.com/webservice/gia/index.php';
	   var pars = 'reportnum=' + reportnum + '&caratweight=' + caratweight;
	   var myAjax = new Ajax.Updater(
			{success: 'ajworkspace'}, 
			url, 
			{
				method: 'get', 
				parameters: pars, 
				evalScripts:true
			});
	   return true; 

   } else {
     return false;
   }
 } else { 
   return false; 
 } 
}

function updatehelp(section) {
  if ($F('helpid') != section) {
  	   $('helpid').value = section;
	   var url = 'https://www.diamonds2cash.com/webservice/updatehelp/index.php';
	   var pars = 'helpsection=' + section;
	
	   var myAjax = new Ajax.Updater(
			{success: 'rhshelp'}, 
			url, 
			{
				method: 'get', 
				parameters: pars, 
				evalScripts:true
			});
	   return true;
  }
}


function validatePackingSlipAddress() {
	if ( $F('d2c_firstname') == '' || $F('d2c_lastname') == '' ) {
		alert ('Please enter your name in order to complete the packing slip.');
		return false;
	} else {
		if ( $F('d2c_address1') == '' || $F('d2c_city') == '' ) {
			alert ('Please complete your address.  This information is used to complete the packing slip on the next page and is the address where you would want your items returned should you decide not to sell.');
			return false;
		} else {
			return true; // $('PackingSlip').submit();
		}
	}
}


function validateSaleAgreement() {
	var typeValue = $('saleForm').serialize().toQueryParams()['payment_method']
	if (typeValue == 'check') {
		$('saleForm').submit();
	} else if (typeValue == 'wire')  {
		$('saleForm').submit();
	} else {
		alert ('Please select the method in which you would like to receive payment, prior to printing the sale agreement.');
	}
}


function validateSaleAgree() {
	var typeValue = $('saleForm').serialize().toQueryParams()['payment_method']
	if (typeValue == 'check' || typeValue == 'wire') {
		return true;
	} else {
		alert ('Please select the method in which you would like to receive payment, prior to printing the sale agreement document.');
		return false;
	}
}


function enablefield(fieldname) {
	var d = $(fieldname);
	if (d != null) {
		d.disabled=false;
	}
}

function disablefield(fieldname) {
	var d = $(fieldname);
	if (d != null) {
		d.disabled=true;
	}
}


// Show or hide elements of a page - this will toggle back and forth
function showhide(id){ 
  if (document.getElementById){ 
	obj = document.getElementById(id); 
    if (obj.style.display == "none"){ 
	    obj.style.display = "";
	  } else { 
		obj.style.display = "none"; 
	} 
  } 
}

// Show elements of a page
function show(id){ 
  if (document.getElementById){ 
	obj = document.getElementById(id); 
	obj.style.display = "";
  } 
}

function hide(id){ 
  if (document.getElementById){ 
	obj = document.getElementById(id); 
	obj.style.display = "none"; 
  } 
}
