var inputs = ["firstNameTb", "First Name...", "lastNameTb", "Last Name...", "emailTb", "Email Address...", "messageTb", "Message..."];

function _checkCookies() {
    //Create a Test cookie.
    var testcookie = 'jscookietest=valid';
    // Add this cookie in the cookie in the cookies collection of the document object.
    document.cookie = testcookie;
    return (document.cookie.indexOf(testcookie) > -1);
}

function inputWatermark(){
	if(inputs.length < 2 || (inputs.length % 2) != 0){
		alert('Wrong usage - please read the source comments!');
	}
	for (i = 0; i < inputs.length; i++) {
	    el = _findInput(inputs[i]);
	    el.attr("watermark", inputs[++i]);
	    el.focus(
	        function() {
	            if (this.value.length == 0 || this.value == $(this).attr("watermark")) {
	                this.value = '';
	            }
	        }
	    );
        el.blur(
            function() {
                if (this.value.length == 0) {
                    this.value = $(this).attr("watermark")
                }
            }
        );
	    el.blur();
	}

	if (_checkCookies()) {
	    $("#jscookie").val(true);
	}
}

function checkSubject(el) {
	$.$("subjectRow").className = (el.options[el.selectedIndex].text == "Other") ? "other" : "";
}

function validateSubject() {
	el = $.$("subjectList");
	errorMsg = $.$("validateOtherSubject");
	if (el.options[el.selectedIndex].text == "Other" && $("#subjectTb").val().length == 0) {
		errorMsg.className =  "other invalid";
		checkSubject(el);
		return false;
	} else {
		errorMsg.className =  "";
		return true;
	}
}

page.onload(inputWatermark);