
window.onload = function() { 

}

function CheckstrReviewerEmail() {
 if ((document.frmReview.strReviewerEmail.value == "") || (document.frmReview.strReviewerEmail .value.length > 0 && (document.frmReview.strReviewerEmail .value.indexOf("@",0) == - 1 || document.frmReview.strReviewerEmail .value.indexOf(".",0) == - 1))) {
 	document.getElementById('strReviewerEmailStatus').innerHTML = '<font color="red">This email address appears invalid.  Please verify the information above.</font>';
 } else {
 	document.getElementById('strReviewerEmailStatus').innerHTML = ''
 }
}
function CheckstrInvoiceID() {
	 if ((document.frmReview.strInvoiceID.value == "")) {
 		document.getElementById('strInvoiceID').innerHTML = '<font color="red">Please enter information above, such as an order number, that the company can use to locate your order.</font>';
	} else {
	 	document.getElementById('strInvoiceID').innerHTML = ''
	}
}

function CheckintInvoiceCost() {
	 if ((document.frmReview.intInvoiceCost.value == "") || (IsNumber(document.frmReview.intInvoiceCost.value) == false)) {
 		document.getElementById('intInvoiceCost').innerHTML = '<font color="red">The transport cost must be a whole number.  The system will remove non-numeric values.  Please check your entry.</font>';
		document.frmReview.intInvoiceCost.value = RemoveNonNumeric(document.frmReview.intInvoiceCost.value);
	} else {
	 	document.getElementById('intInvoiceCost').innerHTML = ''
	}
}


function CheckReviewForm () { 

	var errorMsg = "";
	
	document.frmReview.intInvoiceCost.value = RemoveNonNumeric(document.frmReview.intInvoiceCost.value)
	
	if (document.frmReview.strReviewerName.value == ""){
		errorMsg += "\n\tName \t- Enter your Name";	
	}
	if ((document.frmReview.strReviewerEmail.value == "") || (document.frmReview.strReviewerEmail .value.length > 0 && (document.frmReview.strReviewerEmail .value.indexOf("@",0) == - 1 || document.frmReview.strReviewerEmail .value.indexOf(".",0) == - 1))) { 
		errorMsg += "\n\tE-mail Address \t- Enter your valid e-mail address";
	}
	if (document.frmReview.strInvoiceID.value == ""){
		errorMsg += "\n\tQuote or Order Number \t- Enter your Quote or Order Number";	
	}
	if ((document.frmReview.intInvoiceCost.value == "") || (IsNumber(document.frmReview.intInvoiceCost.value) == false)){
		errorMsg += "\n\tQuote or Order Cost \t- Enter a valid numeric value for Quote or Order Cost";	
	}
	if (document.frmReview.strOriginState.value == "0"){
		errorMsg += "\n\tOrigin State \t- Please choose a origin state";	
	}
	if ((document.frmReview.intPickupTimeDiff.value > "") && (IsNumber(document.frmReview.intPickupTimeDiff.value) == false)){
		errorMsg += "\n\tTotal time from pickup \t- Enter a valid numeric value for Total time from pickup";	
	}
	if (document.frmReview.strDestinationState .value == "0"){
		errorMsg += "\n\tDesination State \t- Please choose a desination state";	
	}
	if ((document.frmReview.intDeliveryTimeDiff.value > "") && (IsNumber(document.frmReview.intDeliveryTimeDiff.value) == false)){
		errorMsg += "\n\tTotal time to delivery \t- Enter a valid numeric value for Total time to delivery";	
	}
	/*if (document.frmReview.chkDamage.checked == true ){
		if ((document.frmReview.intClaimAmount.value > "") && (IsNumber(document.frmReview.intClaimAmount.value) == false)){
			errorMsg += "\n\tAmount of Damamge \t- Enter a valid numeric value for the Amount of Damage";	
		}
		if ((document.frmReview.intClaimPayment.value > "") && (IsNumber(document.frmReview.intClaimPayment.value) == false)){
			errorMsg += "\n\tAmount Paid \t- Enter a valid numeric value for the Amount Paid by Company/Insurance";	
		}
	}*/
	
	var blnReviewerRating = false;
	for (i = 0; i < document.frmReview.intReviewerRating.length; i++) {
		if (document.frmReview.intReviewerRating[i].checked == true){
			blnReviewerRating = true;
		}
	}
	if (blnReviewerRating == false){
		errorMsg += "\n\tOverall Rating \t- Please choose a Overall Ranking";	
	}
	if (document.frmReview.strReviewSubject .value == ""){
		errorMsg += "\n\tSubject \t- Please enter a subject";	
	}
		
	if (document.frmReview.strReview.value.length < 100) {
		errorMsg += '\n\tReview Length \t- In an attempt to create valuable content your review must be longer.  For assistance please refer to the section "Good Reviews Might Include".';
	}		
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Your enquiry has not been sent because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "______________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	//document.frmReview.submit.disabled = true;
	return true;
}

function changeDamage () { 
	var testMsg = ""
	if (document.frmReview.chkDamage.checked == true ){
		for (i = 0; i < document.frmReview.intClaimPrompt.length; i++) {
			document.frmReview.intClaimPrompt[i].disabled = false;
		}
		for (i = 0; i < document.frmReview.intClaimEase.length; i++) {
			document.frmReview.intClaimEase[i].disabled = false;
		}
		document.frmReview.intClaimEase.disabled = false;
		document.frmReview.intClaimAmount.disabled = false;
		document.frmReview.intClaimPayment.disabled = false;
		document.frmReview.intClaimPayment.hidden = false;
	}
	else {
		for (i = 0; i < document.frmReview.intClaimPrompt.length; i++) {
			document.frmReview.intClaimPrompt[i].disabled = true;
		}
		for (i = 0; i < document.frmReview.intClaimEase.length; i++) {
			document.frmReview.intClaimEase[i].disabled = true;
		}
		document.frmReview.intClaimPrompt[0].checked = true;
		document.frmReview.intClaimEase[0].checked = true;
		document.frmReview.intClaimAmount.disabled = true;
		document.frmReview.intClaimPayment.disabled = true;
		document.frmReview.intClaimAmount.value = "";
		document.frmReview.intClaimPayment.value = "";
				
	}
}
function changePickup () { 
	var checkedPickup = ""
	for (var i = 0; i < document.frmReview.intPickup.length; i++) {
		if (document.frmReview.intPickup[i].checked) {
			checkedPickup = document.frmReview.intPickup[i].value
		}
	}
	
	switch (checkedPickup) {
		case '1': { 
			document.frmReview.intPickupTimeDiff.disabled = false;
			break
		}
		case '2': { 
			document.frmReview.intPickupTimeDiff.value = "";
			document.frmReview.intPickupTimeDiff.disabled = true;
			break
		}
		case '3': { 
			document.frmReview.intPickupTimeDiff.disabled = false;
			break
		}
		case '4': { 
			document.frmReview.intPickupTimeDiff.value = "";
			document.frmReview.intPickupTimeDiff.disabled = true;
			break
		}
		// And so on.. and so on..

		// whatever is passed to switch that is not caught
		// by the above fall under this category.
		default: { alert('<font>Error: ' + checkedPickup + '</font><br>'); break }
	}
}

function IsNumber(sText) {
   var ValidChars = "0123456789.";
   var Char;
   for (i = 0; i < sText.length; i++) {
       Char = sText.charAt(i);
       if (ValidChars.indexOf(Char) == -1) {
          return false;
       }
    }
   return true;
}

function RemoveNonNumeric( strString )
{
	// Variables
	var strValidCharacters = "1234567890.";
	var strReturn = "";
	var strBuffer = "";
	var intIndex = 0;
	
	
	// Loop through the string 
	for( intIndex = 0; intIndex < strString.length; intIndex++ )
	{
	     // Get this character
	     strBuffer = strString.substr( intIndex, 1 );
	
	     // Is this a number
	     if( strValidCharacters.indexOf( strBuffer ) > -1 )
	     {
	          // Yes
	          strReturn += strBuffer;
	     }
	}
	strReturn = parseInt(strReturn)
	
	if (isNaN(strReturn)) {
		return "";
	}

	// Return the value
	return strReturn;
}
