<!--
/* check for required fields */
function formCheck(formobj){
	// name of mandatory fields
	var fieldRequired = Array("authorname", "subcatname", "complaint", "cfname", "clname", "cphone", "cemail", "caddress", "ccity", "cprovince", "ccountry", "czip");
	// field description to appear in the dialog box
	var fieldDescription = Array("Author Name", "Subcategory Name", "Komplain", "Nama depan", "Nama Keluarga", "Nomor Telepon", "Alamat E-mail", "Alamat", "Kota", "Propinsi", "Negara", "Kode Pos");
	// dialog message
	var alertMsg = "Please complete the following data :\n";
	var l_Msg = alertMsg.length;

	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
				case "select-one":
					if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
					break;
				case "select-multiple":
					if (obj.selectedIndex == -1){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
					break;
				case "text":
				case "textarea":
					if (obj.value == "" || obj.value == null){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
					break;
				default:
					if (obj.value == "" || obj.value == null){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
			}
		}
	}
	if (alertMsg.length == l_Msg){
		return true;
	} else {
		alert(alertMsg);
		return false;
	}
}

/* check for required fields & invalid characters */
function formCheck2(formobj){
	// name of mandatory fields
	var fieldRequired = Array("productQty");
	// field description to appear in the dialog box
	var fieldDescription = Array("Jumlah");
	// dialog message
	var alertMsg = "Please complete the following :\n";
	var l_Msg = alertMsg.length;

	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
				case "select-one":
					if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
					break;
				case "select-multiple":
					if (obj.selectedIndex == -1){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
					break;
				case "text":
				case "textarea":
					if (obj.value == "" || obj.value == null || ((obj.value >= "a" && obj.value <= "z") || (obj.value >= "A" && obj.value <= "Z" ))){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
					break;
				default:
					if (obj.value == "" || obj.value == null || ((obj.value >= "a" && obj.value <= "z") || (obj.value >= "A" && obj.value <= "Z" ))){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
			}
		}
	}
	if (alertMsg.length == l_Msg){
		return true;
	} else {
		alert(alertMsg);
		return false;
	}
}

/* check if e-mail address inputted is correct */
function checkEmail(checkString)
{
    var newstr = "";
    var at = false;
    var dot = false;

    // IF EMAIL ADDRESS HAS A '@' CHARACTER
    if (checkString.indexOf("@") != -1) {
      at = true;

    // IF EMAIL ADDRESS HAS A '.' CHARACTER
    } else if (checkString.indexOf(".") != -1) {
      dot = true;
    }
    // PARSE REMAINDER OF STRING
    for (var i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i + 1)
        if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
                || (ch == "@") || (ch == ".") || (ch == "_")
                || (ch == "-") || (ch >= "0" && ch <= "9")) {
                newstr += ch;
                if (ch == "@") {
                    at=true;
                }
                if (ch == ".") {
                    dot=true;
                }
        }
    }
    if ((at == true) && (dot == true)) {
        return newstr;
    } else {
      // DISPLAY ERROR MESSAGE
      alert ("The e-mail address you input is not in the correct format.");
      return checkString;
    }
}

/* check if field contains alphabet */
function toAlpha(checkString)
{
    newString = "";    // REVISED/CORRECTED STRING
    count = 0;         // COUNTER FOR LOOPING THROUGH STRING

    // LOOP THROUGH STRING CHARACTER BY CHARACTER
    for (i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i+1);

        // ENSURE CHARACTER IS AN ALPHA CHARACTER
        if ((ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z") || (ch == " ") || (ch == ".") || (ch == ",") || (ch == "-") || (ch == "'") || (ch == "&")) {
            newString += ch;
        }
    }
    if (checkString != newString) {
		alert ("The data you input is not in the correct format.")
		return newString;
	} else {
        return checkString;
	}
}

/* check if the value contains digit */
function toInteger(checkString)
{
    newString = "";    // REVISED/CORRECTED STRING
    count = 0;         // COUNTER FOR LOOPING THROUGH STRING

    // LOOP THROUGH STRING CHARACTER BY CHARACTER
    for (i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i+1);

        // ENSURE CHARACTER IS A DIGIT
        if (ch >= "0" && ch <= "9") {
            newString += ch;
        }
    }
    if (checkString != newString) {
		alert ("The data you input is not in the correct format.")
		return newString;
	} else {
        return checkString;
	}
}

/* display numbers in comma-separated form */
function Comma(number) {
	number = '' + number;
	if (number.length > 3) {
		var mod = number.length % 3;
		var output = (mod > 0 ? (number.substring(0,mod)) : '');
		for (i=0 ; i < Math.floor(number.length / 3); i++) {
			if ((mod == 0) && (i == 0))
				output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
			else
				output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
		}
		return (output);
	} else return number;
}

/* display numbers in comma-separated form */
function redirect(URLStr) { location = URLStr; }

/* preload images */
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
