//requires jquery and windows_js loaded
// string utility functions
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}



function validate_index_form() {
    var ret = true;
    var requiredFields = jQuery('#form1 .form_required')
    //jQuery('.required_field_arrow').css('display','inline');
    
    if (jQuery('#FirstConTitle')[0].selectedIndex == 0) {
        ret = false;
        jQuery('#FirstConTitle').parent().prev().css('color','#FF0000');
    }
    else {
        jQuery('#FirstConTitle').parent().prev().css('color','#000000');
    }
    if (jQuery('#ContactFirst').val().trim() == '') {
        ret = false;
        jQuery('#ContactFirst').parent().prev().css('color','#FF0000');
    }
    else {
        jQuery('#ContactFirst').parent().prev().css('color','#000000');
    }
    if (jQuery('#ContactLast').val().trim() == '') {
        ret = false;
        jQuery('#ContactLast').parent().prev().css('color','#FF0000');
    }
    else {
        jQuery('#ContactLast').parent().prev().css('color','#000000');
    }
    if (jQuery('#PrimAdd').val().trim() == '') {
        ret = false;
        jQuery('#PrimAdd').parent().prev().css('color','#FF0000');
    }
    else {
        jQuery('#PrimAdd').parent().prev().css('color','#000000');
    }
    if (jQuery('#PrimCity').val().trim() == '') {
        ret = false;
        jQuery('#PrimCity').parent().prev().css('color','#FF0000');
    }
    else {
        jQuery('#PrimCity').parent().prev().css('color','#000000');
    }
    if (jQuery('#State')[0].selectedIndex == 0) {
        ret = false;
        jQuery('#State').parent().prev().css('color','#FF0000');
    }
    else {
        jQuery('#State').parent().prev().css('color','#000000');
    }
    if (jQuery('#ZipCode').val().trim() == '') {
        ret = false;
        jQuery('#ZipCode').parent().prev().css('color','#FF0000');
    }
    else {
        jQuery('#ZipCode').parent().prev().css('color','#000000');
    }
    //country cannot be left blank.  selectedIndex 0 is the USA
    //jQuery('#Country').addClass('form_required');
    //ret = true;
    if (!ret) {
        //display the error message
//        var DialogString = '<h2 class="sepImage epBlue">While our website provides a wealth of information our <span class="epRed">FREE DVD</span> is still the best way to see how our swimming machines perform.</h2>';
//        DialogString += '<table width="90%" align="center" border="0" cellpadding="5"><tr valign="middle"><td align="center" width="50%">';
//        DialogString += '<img src="indexcimages/requestandproceed.gif" width="135" height="64" onclick="Dialog.closeInfo();" />'
//       //DialogString += '<button style="height: 60px;" onclick="Dialog.closeInfo();">Request FREE DVD,<br />then proceed to the main website.</button>';
//        DialogString += '</td><td align="center" width="50%">';
//        DialogString += '<img src="indexcimages/proceed.gif" width="135" height="64" onclick="location.href = \'main.html\';" />'
//        //DialogString += '<button style="height: 60px;" onclick="location.href = \'main.html\';">Proceed to the main website.</button>';
//        DialogString += '</td></tr></table>';


		var DialogString = '<h2 class="sepImage epBlue">Oops!  In order to send you our <span class="epRed">FREE DVD</span> we require a few important pieces of information.  We\'ve hightlighted the missing pieces in <span class="epRed">red</span>.</h2>';
        DialogString += '<table width="90%" align="center" border="0" cellpadding="5"><tr valign="middle"><td align="center">';
        DialogString += '<img src="indexcimages/requestandproceed.gif" width="135" height="64" onclick="Dialog.closeInfo();" />';
  		DialogString += '</td></tr></table>';
  		//DialogString += '<button style="height: 60px;" onclick="Dialog.closeInfo();">Request FREE DVD,<br />then proceed to the main website.</button>';
        //DialogString += '</td><td align="center" width="50%">';
        //DialogString += '<img src="indexcimages/proceed.gif" width="135" height="64" onclick="location.href = \'main.html\';" />'
        //DialogString += '<button style="height: 60px;" onclick="location.href = \'main.html\';">Proceed to the main website.</button>';
        //DialogString += '</td></tr></table>';
        //Dialog.info(DialogString, { windowParameters: {resizable: false,  effectOptions: {duration:0.25}, showEffect: Effect.Grow, hideEffect: Effect.Puff, width: 375, height:200, className:"alphacube"}});
	Dialog.info(DialogString, { windowParameters: {resizable: false, width: 375, height:200, className:"alphacube"}});
    }
    else {
        jQuery('#form1').submit();
    }
    
    return ret;
}