jQuery(function(){
	
	//alert ('test before');
	
	///Fixes menu bugs in IE7
	if(jQuery.browser.msie && jQuery.browser.version == '7.0' ) {
		//Check for ie7
			jQuery('#main-nav li').hover
				( 
				function() 
					{
						
						if(jQuery(this).children('ul.children').hasClass('remove')){
							jQuery(this).children('ul.children').css('top','50px');
							jQuery(this).children('ul.children li ul.children').css('top','0px');
							jQuery(this).children('ul.children').removeClass('remove');
						}
						if(jQuery(this).children('ul').hasClass('remove')){
							//jQuery(this).children('ul.children').css('top','-520px');
							//jQuery(this).children('ul.children').css('top','50px');
							jQuery(this).children('ul').removeClass('remove');
						}
					
					jQuery(this).addClass('sfhover');
					//alert('Added');	
					}, 
				function()
					{
					jQuery(this).removeClass('sfhover');
					//alert('Removed');	
					}
				);
			
		jQuery("#main-nav li").hover( function() {
			
					
		}, function() {
			jQuery(this).children('ul').addClass('remove');
			jQuery(this).children('ul').css('top','-999em');
			
		});
	} else {
		jQuery('#main-nav li').hover
				( 
				function() 
					{
					jQuery(this).addClass('sfhover');
					}, 
				function()
					{
					jQuery(this).removeClass('sfhover');	
					}
				);
	}
	///Fixes menu bugs in IE7 end
	
	
	/*jQuery("#main-nav li").hover
		( 
		function() 
			{
			jQuery(this).each
				(
				function ()
					{
					jQuery(this).addClass('sfhover');
					}
				);	
			}, 
		function()
			{
			jQuery(this).each
				(
				function ()
					{
					jQuery(this).removeClass('sfhover');
					}
				);
			}
		);*/
			
	/*for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			jQuery(this).addClass('sfhover');
		}
		sfEls[i].onmouseout=function() {
			jQuery(this).removeClass('sfhover');
		}
	}*/
			
	//alert ('test after');
	
    jQuery("div.errors").hide();

    
    //make all the uls in mid-section the same height
	
	//alert(jQuery('div.sidebar-right div.sidebar-content').height());
	//alert(jQuery('div.middle-section.home div.mid-sec-left ul').height() + 274);
	
	if(jQuery('div.sidebar-right div.sidebar-content').height() > (jQuery('div.middle-section.home div.mid-sec-left ul').height())) { //274 is the height of the slide on the home page + all paddings/margins
		jQuery('div.middle-section.home div.mid-sec-left ul').height( jQuery('div.sidebar-right div.sidebar-content').height() - 68 );
	} else {
		jQuery('div.sidebar-right div.sidebar-content').height( jQuery('div.middle-section.home div.mid-sec-left ul').height() + 324 );
	}
    
	jQuery('div.middle-section.home ul').height(jQuery('div.middle-section.home div.mid-sec-left ul').height());

 	jQuery('div.recent-nav ul li').click( function() {
		
		jQuery('div.recent-nav ul li').removeClass('active');
		
		if(jQuery(this).hasClass('active')) {
			jQuery(this).removeClass('active');
		} else {			
			jQuery(this).addClass('active');
		}
		
	});
	
    jQuery('div.recent-nav ul li.latNews').click( function() {
        jQuery('div.recon-wrap div.content-tab.latNews').show();
        jQuery('div.recon-wrap div.content-tab.whatsNew').hide();
    });

    jQuery('div.recent-nav ul li.whatsNew').click( function() {	
        jQuery('div.recon-wrap div.content-tab.latNews').hide();		
        jQuery('div.recon-wrap div.content-tab.whatsNew').show();
    });
	
	jQuery('div.login-form').css('top','-120px');
	jQuery('div.login-form').hide();
	
	jQuery('div.partner_btn').toggle( function() {
		jQuery('div.login-form').show();
		jQuery('div.partner-login').addClass('aboveAll');
		jQuery('div.login-form').animate({
			top: 0
		});
		jQuery('div.partner_btn').animate({
			top: 120
		});
	}, function() {
		jQuery('div.partner-login').removeClass('aboveAll');
		jQuery('div.login-form').animate({
			top: -120
		});
		jQuery('div.partner_btn').animate({
			top: 0
		});
	});
	
	//////JAVASCRIPT FOR MAKING THE MENU WORK IN IE7 and down
		
});


function isNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}

function IsValidEmail(email){

	var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	return filter.test(email);

}

function allowedChars(input_value){

	var aChars = '1234567890-+() ';

	for(i=0;i<input_value.length;i++)
		{
		if (aChars.indexOf(input_value.charAt(i)) != -1)
			{
				num = true;
			}
		else
			{
				num = false;
				break;
			}
		}
	return num;

}
function show_errors(text,display,error){

	if(error==1)
		{
			jQuery(display).html(text);
			jQuery(display).fadeIn(300).fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300);
		}
	else
		{
			jQuery(display).html('');
			jQuery(display).hide('');
		}
}

function validateForm (submitted) {

	var errCnt = 0;
	var errors = "";

	var name 		= jQuery(	"input[name='_name']"		);
	var cell 		= jQuery(	"input[name='_cell']"		);
	var comment 	= jQuery(	"textarea[name='_comment']"	);
	var email 		= jQuery(	"input[name='_email']"		);

/////NAME
	if (name.val() == '' || name.val() == 'Name')
		{
		show_errors('Please enter a first name','div.error._name',1);
		errors++;
		}
	else
		{
		show_errors('','div.error._name',0);
		}

/////CELL
	if (cell.val() == '' || cell.val() == 'Cell/Landline')
		{
		show_errors('Please enter a telephone number','div.error._cell',1);
		errors++;
		}
	else
		{
		if(!allowedChars(cell.val()))
			{
			show_errors('Invalid charachters found. Please enter a valid telephone number','div.error._cell',1);
			errors++;
			}
			else
			{
			show_errors('','div.error._cell',0);
			}
		}

/////EMAIL
	if (email.val() == '' || email.val() == 'Email')
		{
		show_errors('Please enter an email address.','div.error._email',1);
		errors++;
		}
	else
		{
		if(!IsValidEmail(email.val()))
			{
			show_errors('Please enter a valid email','div.error._email',1);
			errors++;
			}
		else
			{
			show_errors('','div.error._email',0);
			}
		}

/////COMMENT / QUERY
	if (comment.val() == '' || comment.val() == 'Please write your comments here.')
		{
		show_errors('Please write a comment','div.error._comment',1);
		errors ++;
		}
	else
		{
		show_errors('','div.error._comment',0);
		}


	if (errors <= 0)
		{
		document.contactForm.submit();
		}
}

function launch(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=635,height=600,left = 200,top = 100');");
}

