﻿function sendForm()
{
    if ( !$('#MainForm').validateInputs() )
        return;

       $.post(
        'handlers/PostForm.ashx',
        getParameters($('#MainForm')),
        function(data) {
        	if (data == "OK" || data == "TEST") {
        		$('#MainForm').html("פרטיך התקבלו, נשמח לחזור אליך בהקדם");
        		if (data == "TEST")
        			return;
        			
        		try {
        			var catId = $('#catId').val();
        			var courseId = $('#courseId').val();
        			pageTracker._trackPageview('leads/' + catId + '/' + courseId);
        		} catch (err) { }
        	}
        	else
        		$('#MainForm').html("ארעה תקלה בעת שליחת הפרטים, נסה מאוחר יותר שוב.");
        }
    )
}

function getParameters(sender)
{
	var params = {};
	
	sender
		.find("input[checked], input[type='text'], input[type='hidden'], input[type='password'], input[type='submit'], option[selected], textarea")
		.each(function() {
			params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
		});
		
    return params;
}

$(function() {
	$('.InstituteCourses').hover(
		function() { $('.InstituteCoursesDisplay').show(); },
		function() { $('.InstituteCoursesDisplay').hide(); }
	);
});