// JavaScript Document
<!--
self.name = 'DisclosureSave';
// window.onUnload = 'window.name=""';

var vloginpopup;

function openloginpopup() {
 vloginpopup = window.open('http://www.DisclosureSave.com/loginpopup.asp', 'loginpopup', 'height=200,width=300');
} // end openloginpopup

//function focusloginpopup() {
//	if (vloginpopup.closed==false) {
//		//alert ("it's false");
//		vloginpopup.focus();
//	} // end if
//} // end focusloginpopup

function isblank(s) {
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    } 
    return true;
} // end isblank

function verify(f) {  // performs form verification. invoked from the onSubmit() event handler. The handler should return whatever value this function returns.
    var msg = "";
    var empty_fields = "";
    //var errors = "";
    // Loop through the elements of the form, looking for all text and textarea elements that don't have an "optional" property defined. 
	// Then, check for fields that are empty and make a list of them.
    for(var i = 0; i < f.length; i++) {
        var e = f.elements[i];
        if (((e.type == "text") || (e.type == "textarea")) && !e.optional) {
            if ((e.value == null) || (e.value == "") || isblank(e.value)) {	// first check if the field is empty
                empty_fields += "\n          " + e.name;
                continue;
            }
        }
    }

    // Now, if there were any empty fields, display the messages, and return false to prevent the form from being submitted. Otherwise return true.
    if (!empty_fields)
    	return true;
    if (empty_fields) {
    //    msg += "The following required field(s) are empty:" + empty_fields + "\n";
	      msg += "Please fill in all required fields.";
    }
    alert(msg);
    return false;
} // end verify

function verifyOrderStat (form) {
	//alert (form.orderStatus[1].checked);
	//alert ( isblank(form.dateOrdersFrom.value) || isblank(form.dateOrdersTo.value) );
	if ( (  (form.orderStatus[0].checked)  &&   ( isblank(form.dateOrdersFrom.value) || isblank(form.dateOrdersTo.value) ) )     ||
	     (  (form.orderStatus[1].checked)  &&     isblank(form.sellerOrder.value)                                          )     ||
		 (  (form.orderStatus[2].checked)  &&     isblank(form.idOrder.value)                                       )     
	   )
	{ 
		alert ("Please fill in all required fields.");
			return false;
    } // end if
} // end verifyOrderStat

function verifyOrder (form) {
	var a = form.APN;
	var sn = form.StreetNumber;
	var sa = form.StreetAddress;
	var ct = form.City;
	var zp = form.Zip;
	if ((a.value==null) || (a.value == "") || isblank(a.value)) {		// APN is empty
		if ((sn.value == null) || (sn.value == "") || isblank(sn.value) || (sa.value == null) || (sa.value == "") || isblank(sa.value) || (ct.value == null) || (ct.value == "") || isblank(ct.value) )  {
       		alert ("Please fill in all required fields.");
			return false;
        }
	else 
			return true;
    } // end if
} // end verifyOrder

function verifyRefund (form) {
	var a = form.Agent;
	var r = form.Reason;
	if (  (a.value == null) || (a.value == "") || isblank(a.value) || (r.value == null) || (r.value == "") || isblank(r.value) )  {
  	alert ("Please fill in all required fields.");
		return false;
  } // end if
} // end verifyRefund

function checkCardNumWithMod10(CreditCardNum) {
	var i;
	var cc = new Array(16);
	var checksum = 0;
	var validcc;

	// assign each digit of the card number to a space in the array	
	for (i = 0; i < CreditCardNum.length; i++) {
		cc[i] = Math.floor(CreditCardNum.substring(i, i+1));
	}

	// walk through every other digit doing our magic
	// if the card number is sixteen digits then start at the
	// first digit (position 0), otherwise start from the
	// second (position 1)
	for (i = (CreditCardNum.length % 2); i < CreditCardNum.length; i+=2) {
		var a = cc[i] * 2;
		if (a >= 10) {
			var aStr = a.toString();
			var b = aStr.substring(0,1);
			var c = aStr.substring(1,2);
			cc[i] = Math.floor(b) + Math.floor(c);
		} else {
			cc[i] = a;
		}
	}

	// add up all of the digits in the array
	for (i = 0; i < CreditCardNum.length; i++) {
		checksum += Math.floor(cc[i]);
	}

	// if the checksum is evenly divisble by 10
	// then this is a valid card number
	validcc = ((checksum % 10) == 0);

	return validcc;
}

function cleanCardNum(CreditCardNum) {
	var i;
	var ch;
	var newCard = "";

	// walk through the string character by character to build
	// a new string with numbers only
	i = 0;
	while (i < CreditCardNum.length) {
		// get current character
		ch = CreditCardNum.substring(i, i+1);
		if ((ch >= "0") && (ch <= "9")) {
			// if the current character is a digit then add it
			// to the numbers-only string
			newCard += ch;
		} else {
			// is not a digit so check if it is a dash or a space
			if ((ch != " ") && (ch != "-")) {
				// not a dash or a space so die
				alert("The card number contains invalid characters.");
				return false;
			}
		}
		i++;
	}

	// we got here if we didn't fail, so return what we built
	return newCard;
}

function checkCard(CreditCard, CreditCardNum, CreditCardName, CreditCardExp) {
	var validExp;
	var validCard;
	var cardLength;
	var cardLengthOK;
	var cardStart;
	var cardStartOK;
	var CrName = document.credit.CreditCardName;
	var CrExp = document.credit.CreditCardExp;
	var CrNum = document.credit.CreditCardNum;
	var ExpDate;
	
	// make sure Name field is populated
	if ((CrName.value == null) || (CrName.value == "") || isblank(CrName.value)) {
		alert("Please enter the name as it appears on Credit Card.");
		return false;
	}
	
	
	// make sure Number field is populated
	if ((CrNum.value == null) || (CrNum.value == "") || isblank(CrNum.value)) {
		alert("Please enter the Number as it appears on Credit Card.");
		return false;
	}

	// make sure Exp field is populated
	if ((CrExp.value == null) || (CrExp.value == "") || isblank(CrExp.value)) {
		alert("Please enter the Expiration Date as it appears on the Credit Card.  Example:  01/00 for Jan 2000.");
		return false;
	}
	
	if (CreditCardExp.length != 5)  {
	alert ("Please enter the Expiration Date with 5 characters.  Example:  01/00 for Jan 2000.");
	return false;
	}
	
	if (!((CreditCardExp.substring(0,1) >= "0") && (CreditCardExp.substring(0,1) <= "9"))) {
	alert ("The Expiration Date contains invalid characters.");	
	return false;
	}
	
	if (!((CreditCardExp.substring(1,2) >= "0") && (CreditCardExp.substring(1,2) <= "9"))) {
	alert ("The Expiration Date contains invalid characters.");	
	return false;
	}
		
	if ((CreditCardExp.substring(2,3) != "/"))  {
	alert ("Please enter the Expiration Date with a '/' separating Month and Year.  Example:  01/00 for Jan 2000.");
	return false;
	}
	
	if (!((CreditCardExp.substring(3,4) >= "0") && (CreditCardExp.substring(3,4) <= "9"))) {
	alert ("The Expiration Date contains invalid characters.");	
	return false;
	}
	
	if (!((CreditCardExp.substring(4,5) >= "0") && (CreditCardExp.substring(4,5) <= "9"))) {
	alert ("The Expiration Date contains invalid characters.");	
	return false;
	}
	
	// check if the card type is valid
	if ((CreditCard != "1") && (CreditCard != "2") && (CreditCard != "3") && (CreditCard != "4")) {
		alert("Please select a card type.");
		return false;
	}

	// clean up any spaces or dashes
	validCard = cleanCardNum(CreditCardNum);
	if (validCard != "") {
		// check the first digit does it matches the card type?
		cardStart = validCard.substring(0,1);
		cardStartOK = ( ((CreditCard == "2") && (cardStart == "4")) ||
				((CreditCard == "3") && (cardStart == "5")) ||
				((CreditCard == "1") && (cardStart == "3")) ||
				((CreditCard == "4") && (cardStart == "6")) );
		if (!(cardStartOK)) {
			// card number's first digit doesn't match card type
			alert("Please make sure the card number you've entered matched the card type you selected.");
			return false;
		}

		// the card number good so check to make sure right length
		
		cardLength = validCard.length;		
		cardLengthOK = ( ((CreditCard == "2") && ((cardLength == 13) || (cardLength == 16))) ||
				 ((CreditCard == "3") && (cardLength == 16)) ||
				 ((CreditCard == "1") && (cardLength == 15)) ||
				 ((CreditCard == "4") && (cardLength == 16)) );
		if (!(cardLengthOK)) {
			// not the right length
			alert("Please make sure you've entered all of the digits on your card.");
			return false;
		}

		// card number passes so we do the Mod10
		if (checkCardNumWithMod10(validCard)) {
			return true;
		} else {
			alert("Please make sure you've entered your card number correctly.");
			return false;
		}
	} else {
		return false;
	}
}



//-->