// Author:	Ravi Gupta
function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}	
function validateForm(obj) {

	errors = false;
	
	// Validate form Values

	// Name
	if (((obj == document.getElementById('sub_name')) || (obj == null)) && ((!document.getElementById('sub_name').value) || (document.getElementById('sub_name').value == 'name'))) {
		document.getElementById('sub_name').style.color = 'white';
		document.getElementById('sub_name').style.background = 'url(lib/images/error.gif) no-repeat right center';
		errors = true;
	} else if ((obj == document.getElementById('sub_name')) || (obj == null)) {
		document.getElementById('sub_name').style.color = '#white';
		document.getElementById('sub_name').style.background = 'url(lib/images/pass.gif) no-repeat right center';
	}
	
	// Strasse
	if (((obj == document.getElementById('sub_strasse')) || (obj == null)) && ((!document.getElementById('sub_strasse').value) || (document.getElementById('sub_strasse').value == 'Strasse'))) {
		document.getElementById('sub_strasse').style.color = 'white';
		document.getElementById('sub_strasse').style.background = 'url(lib/images/error.gif) no-repeat right center';
		errors = true;
	} else if ((obj == document.getElementById('sub_strasse')) || (obj == null)) {
		document.getElementById('sub_strasse').style.color = '#white';
		document.getElementById('sub_strasse').style.background = 'url(lib/images/pass.gif) no-repeat right center';
	}
	
	// Plz/Port
	if (((obj == document.getElementById('sub_Port')) || (obj == null)) && ((!document.getElementById('sub_Port').value) || (document.getElementById('sub_Port').value == 'Plz/Port'))) {
		document.getElementById('sub_Port').style.color = 'white';
		document.getElementById('sub_Port').style.background = 'url(lib/images/error.gif) no-repeat right center';
		errors = true;
	} else if ((obj == document.getElementById('sub_Port')) || (obj == null)) {
		document.getElementById('sub_Port').style.color = '#white';
		document.getElementById('sub_Port').style.background = 'url(lib/images/pass.gif) no-repeat right center';
	}
	
	// Anlass
	if (((obj == document.getElementById('sub_Anlass')) || (obj == null)) && ((!document.getElementById('sub_Anlass').value) || (document.getElementById('sub_Anlass').value == 'Anlass'))) {
		document.getElementById('sub_Anlass').style.color = 'white';
		document.getElementById('sub_Anlass').style.background = 'url(lib/images/error.gif) no-repeat right center';
		errors = true;
	} else if ((obj == document.getElementById('sub_Anlass')) || (obj == null)) {
		document.getElementById('sub_Anlass').style.color = '#white';
		document.getElementById('sub_Anlass').style.background = 'url(lib/images/pass.gif) no-repeat right center';
	}
	
	// Comment
	if (((obj == document.getElementById('sub_comment')) || (obj == null)) && ((!document.getElementById('sub_comment').value) || (document.getElementById('sub_comment').value == 'comment'))) {
		document.getElementById('sub_comment').style.color = 'white';
		document.getElementById('sub_comment').style.background = 'url(lib/images/message-error.gif) no-repeat right top';
		errors = true;
	} else if ((obj == document.getElementById('sub_comment')) || (obj == null)) {
		document.getElementById('sub_comment').style.color = '#white';
		document.getElementById('sub_comment').style.background = 'url(lib/images/message-pass.gif) no-repeat right top';
	}
	
	// phone
	if (((obj == document.getElementById('sub_phone')) || (obj == null)) && ((!document.getElementById('sub_phone').value) || (document.getElementById('sub_phone').value == '(area code) phone number') || (isInteger(document.getElementById('sub_phone').value)==false))) {
		document.getElementById('sub_phone').style.color = 'white';
		document.getElementById('sub_phone').style.background = 'url(lib/images/error.gif) no-repeat right center';
		errors = true;
	} else if ((obj == document.getElementById('sub_phone')) || (obj == null)) {
		document.getElementById('sub_phone').style.color = '#white';
		document.getElementById('sub_phone').style.background = 'url(lib/images/pass.gif) no-repeat right center';
	}
	// visitor interest
	if (((obj == document.getElementById('sub_interested')) || (obj == null)) && ((!document.getElementById('sub_interested').value) || (document.getElementById('sub_interested').value == 'i\'m interested in'))) {
		document.getElementById('sub_interested').style.color = 'white';
		document.getElementById('sub_interested').style.background = 'url(lib/images/error.gif) no-repeat 165px center';
		errors = true;
	} else if ((obj == document.getElementById('sub_interested')) || (obj == null)) {
		document.getElementById('sub_interested').style.color = '#white';
		document.getElementById('sub_interested').style.background = 'url(lib/images/pass.gif) no-repeat 165px center';
	}
	// Email Address
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var address = document.getElementById('sub_email').value;
	if (((obj == document.getElementById('sub_email')) || (obj == null)) && (reg.test(address) == false)) {
		document.getElementById('sub_email').style.color = 'white';
		document.getElementById('sub_email').style.background = 'url(lib/images/error.gif) no-repeat right center';
		errors = true;
	} else if ((obj == document.getElementById('sub_email')) || (obj == null)) {
		document.getElementById('sub_email').style.color = '#white';
		document.getElementById('sub_email').style.background = 'url(lib/images/pass.gif) no-repeat right center';
	}

	if ((document.getElementById('sub_address').value == 'postal address (optional)') && (obj == null)) {
		document.getElementById('sub_address').value = '';
	} else if (((obj == document.getElementById('sub_address')) || (obj == null))  && ((document.getElementById('sub_address').value != 'postal address (optional)') && (document.getElementById('sub_address').value != ''))) {
		document.getElementById('sub_address').style.color = '#white';
		document.getElementById('sub_address').style.background = 'url(lib/images/pass.gif) no-repeat right center';
	}
	
	if (errors == true) {
		return false;
	} else {
		document.contact.submit();
	}
}
