function getCookie(Name) {
   var search = Name + "="
   if (document.cookie.length > 0) { // if there are any cookies
      offset = document.cookie.indexOf(search)
      if (offset != -1) { // if cookie exists
         offset += search.length
         // set index of beginning of value
         end = document.cookie.indexOf(";", offset)
         // set index of end of cookie value
         if (end == -1)
            end = document.cookie.length
         return unescape(document.cookie.substring(offset, end))
      } else {
	  	return "NA";
	  }
   }
}

function Validation(hTarget, hErrorMsg, hType){
var hResult;
var hMsg = "";

	hResult = 1;
	switch (hType) {
	//Cannot Be Null.
	case "0":
		if (document.Veno [hTarget].value.length == 0) {
			hMsg += "Missing Information:\n";
			hMsg += "====================\n\n";
			hMsg += hErrorMsg;
			hMsg += " is missing!";
			hResult = 0;
			alert(hMsg);
		}
		break;
	//Must Be Number And Cannot Be Null.
	case "1":
		if ((document.Veno [hTarget].value.length == 0) || (isNaN(document.Veno [hTarget].value))) {
			hMsg += "Typo Detected:\n";
			hMsg += "====================\n\n";
			hMsg += hErrorMsg;
			hMsg += " was mistyped. It accept number *ONLY* and cannot be blank!";
			hResult = 0;
			alert(hMsg);
		}
		break;
	//Must Be Number But Can Be Null.
	case "1a":
		if (isNaN(document.Veno [hTarget].value)) {
			hMsg += "Typo Detected:\n";
			hMsg += "====================\n\n";
			hMsg += hErrorMsg;
			hMsg += " was mistyped. It accept number *ONLY* or just leave it blank!";
			hResult = 0;
			alert(hMsg);
		}
		break;
	//In Date Format MM/DD/YYYY.
	case "2":
		if ((document.Veno [hTarget].value.length != 10)) {
			hResult = 0;
		} else {
			if ((document.Veno [hTarget].value.charAt(2) != '/')) {
				hResult = 0;
			} else {
				if ((document.Veno [hTarget].value.charAt(5) != '/')) {
					hResult = 0;
				} else {
					if (isNaN(document.Veno [hTarget].value.replace(/\//gi, ''))) {
						hResult = 0;
					} else {
						if ((parseInt(document.Veno [hTarget].value.substring(0, 2), 10) == 0) || (parseInt(document.Veno [hTarget].value.substring(0, 2), 10) > 12)) {
							hResult = 0;
						} else {
							if ((parseInt(document.Veno [hTarget].value.substring(3, 5), 10) == 0) || (parseInt(document.Veno [hTarget].value.substring(3, 5), 10) > 31)) {
								hResult = 0;
							}
						}
					}
				}
			}
		}
		
		if (hResult == 0) {
			hMsg += "Typo Detected:\n";
			hMsg += "====================\n\n";
			hMsg += hErrorMsg;
			hMsg += " was mistyped. Please enter date in (MM/DD/YYYY) format and it cannot be blank!";
			alert(hMsg);
		}

		break;
	//Card Card String Check. If applied, value cannot be NULL.
	case "3a0":
		if ((document.Veno.Payment_Type.value == 'Visa') || (document.Veno.Payment_Type.value == 'MasterCard') || (document.Veno.Payment_Type.value == 'AMEX')) {
			if (document.Veno [hTarget].value.length == 0) {
				hMsg += "Missing Information:\n";
				hMsg += "====================\n\n";
				hMsg += hErrorMsg;
				hMsg += " is missing!";
				hResult = 0;
				alert(hMsg);
			}
		}
		break;
	//Card Card Number Check. If applied, value cannot be NULL and Must be Number only.
	case "3a1":
		if ((document.Veno.Payment_Type.value == 'Visa') || (document.Veno.Payment_Type.value == 'MasterCard') || (document.Veno.Payment_Type.value == 'AMEX')) {
			if (isNaN(document.Veno [hTarget].value)) {
				hMsg += "Typo Detected:\n";
				hMsg += "====================\n\n";
				hMsg += hErrorMsg;
				hMsg += " was mistyped. It accept number *ONLY* and cannot be blank!";
				hResult = 0;
				alert(hMsg);
			}
		}
		break;
	//Card Card Expiry Date Check. If applied, value cannot be NULL and Must be Number only.
	case "3a2":
		if ((document.Veno.Payment_Type.value == 'Visa') || (document.Veno.Payment_Type.value == 'MasterCard') || (document.Veno.Payment_Type.value == 'AMEX')) {
			if ((document.Veno [hTarget].value.length < 4) || (isNaN(document.Veno [hTarget].value))) {
				hMsg += "Typo Detected:\n";
				hMsg += "====================\n\n";
				hMsg += hErrorMsg;
				hMsg += " was mistyped. It accept (MMYY) format *ONLY* and cannot be blank!";
				hResult = 0;
				alert(hMsg);
			}
		}
		break;
	//Debit String Check. If applied, value cannot be NULL.
	case "3b0":
		if (document.Veno.Payment_Type.value == 'Debit') {
			if (document.Veno [hTarget].value.length == 0) {
				hMsg += "Missing Information:\n";
				hMsg += "====================\n\n";
				hMsg += hErrorMsg;
				hMsg += " is missing!";
				hResult = 0;
				alert(hMsg);
			}
		}
		break;
	//Cheque String Check, If applied, value cannot be NULL.
	case "3c0":
		if (document.Veno.Payment_Type.value == 'Cheque') {
			if (document.Veno [hTarget].value.length == 0) {
				hMsg += "Missing Information:\n";
				hMsg += "====================\n\n";
				hMsg += hErrorMsg;
				hMsg += " is missing!";
				hResult = 0;
				alert(hMsg);
			}
		}
		break;
	}
	return hResult;
}
