/**
 * @author GeekTantra
 * @date 24 September 2009
 */
/*
 * This functions checks where an entered date is valid or not.
 * It also works for leap year feb 29ths.
 * @year: The Year entered in a date
 * @month: The Month entered in a date
 * @day: The Day entered in a date
 */
function isValidDate(year, month, day){
    var date = new Date(year, (month - 1), day);
    var DateYear = date.getFullYear();
    var DateMonth = date.getMonth();
    var DateDay = date.getDate();
    if (DateYear == year && DateMonth == (month - 1) && DateDay == day) 
        return true;
    else 
        return false;
}
/*
 * This function checks if there is at-least one element checked in a group of check-boxes or radio buttons.
 * @id: The ID of the check-box or radio-button group
 */
function isChecked(id){
    var ReturnVal = false;
    $("#" + id).find('input[type="radio"]').each(function(){
        if ($(this).is(":checked")) 
            ReturnVal = true;
    });
    $("#" + id).find('input[type="checkbox"]').each(function(){
        if ($(this).is(":checked")) 
            ReturnVal = true;
    });
    return ReturnVal;
}

/* <![CDATA[ */
jQuery(function(){
	jQuery("#name,#company_name").validate({
		expression: "if (VAL) return true; else return false;",
		message: "Required field"
	});
	jQuery("#email").validate({
		expression: "if (VAL.match(/^[^\\W][a-zA-Z0-9\\_\\-\\.]+([a-zA-Z0-9\\_\\-\\.]+)*\\@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*\\.[a-zA-Z]{2,4}$/)) return true; else return false;",
		message: "Email not valid"
	});
	jQuery("#phone").validate({
    	expression: "if (VAL.match(/^[0-9\\.\\-][0-9\\.\\-]{9,11}.{0,6}$/)) return true; else return false;",
    	message: "Not a valid phone #"
    });
	jQuery("#interested").validate({
		expression: "if (VAL != '0') return true; else return false;",
		message: "Please make a selection"
	});

	
/*		
	jQuery("#ValidNumber").validate({
		expression: "if (!isNaN(VAL) && VAL) return true; else return false;",
		message: "Please enter a valid number"
	});
	jQuery("#ValidInteger").validate({
		expression: "if (VAL.match(/^[0-9]*$/) && VAL) return true; else return false;",
		message: "Please enter a valid integer"
	});
	jQuery("#ValidDate").validate({
		expression: "if (!isValidDate(parseInt(VAL.split('-')[2]), parseInt(VAL.split('-')[0]), parseInt(VAL.split('-')[1]))) return false; else return true;",
		message: "Please enter a valid Date"
	});
	jQuery("#ValidPassword").validate({
		expression: "if (VAL.length > 5 && VAL) return true; else return false;",
		message: "Please enter a valid Password"
	});
	jQuery("#ValidConfirmPassword").validate({
		expression: "if ((VAL == jQuery('#ValidPassword').val()) && VAL) return true; else return false;",
		message: "Confirm password field doesn't match the password field"
	});
	jQuery("#ValidSelection").validate({
		expression: "if (VAL != '0') return true; else return false;",
		message: "Please make a selection"
	});
	jQuery("#ValidMultiSelection").validate({
		expression: "if (VAL) return true; else return false;",
		message: "Please make a selection"
	});
	jQuery("#ValidRadio").validate({
		expression: "if (isChecked(SelfID)) return true; else return false;",
		message: "Please select a radio button"
	});
	jQuery("#ValidCheckbox").validate({
		expression: "if (isChecked(SelfID)) return true; else return false;",
		message: "Please check atleast one checkbox"
	});
	jQuery('.AdvancedForm').validated(function(){
		alert("Use this call to make AJAX submissions.");
	});
	*/
});
/* ]]> */
