// JavaScript Document
$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		//if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		$(this).children().css({'min-height': currentTallest}); 
	});
	return this;
};
$(function(){ $('.indexRow1').equalHeights(); });


function setActiveMenu(arr, crtPage)
{
	for (var i=0; i < arr.length; i++)
	{
	
	

		if(extractPageName(arr[i].href) == crtPage)
		{
			$("ul#sideNav li").each(function(){
			    var thisID = $(this).attr("id");
			    if(crtPage == thisID){
			    
			   $(this).parents("li.mainLI").find("a.sidenavH").addClass("clicked");
			   $("#sideNav li a.clicked").parent().find("ul.sideNavSub").slideDown();
			   
			   
			   }
		    });
		}
	}
}
 
function setPage()
{
	hrefString = document.location.href ? document.location.href : document.location;
    setActiveMenu(document.getElementById(extractPageName(hrefString)).getElementsByTagName("a"), extractPageName(hrefString));
}
$(document).ready(function(){
	$('<style type="text/css">.clearfix:after {visibility: hidden;display: block;font-size: 0;content: " ";clear: both;height: 0;}* html .clearfix { zoom: 1; }*:first-child+html .clearfix { zoom: 1; }textarea{resize:none;}</style>').appendTo("head");
// Thought Row
	$("div.newsRow:last,div.indexRow:last,div.meetRow:last").css('border-bottom','none');
	$("div.learnWithmeCol:last,div.index3Blk:last").css('border-right','none');
	$('ul li:empty').remove();
	SetEventTrigger();
	$("span.cursorPointer").hover(function(){
        $(this).next("span.event").show();
	    $(this).parent().hover(function() {
        }, function() { 
            $("span.event").hide();
        });
    });

	
	$('#sideNav li a.sidenavH').click(function(){
		if(!$(this).hasClass("clicked")){
			$('ul.sideNavSub').slideUp();
			$("#sideNav li a.sidenavH").removeClass("clicked");
			$(this).parent().find("ul.sideNavSub").slideDown();
			$(this).addClass("clicked");
		}
		return false;
	});
});
function SetEventTrigger(){
    $("td.day-with-date").each(function(){
        if(!$(this).hasClass("no-events")){
	        $(this).children("span:first").addClass('cursorPointer');
	        $(this).children("span:first").addClass('yesEventsColor');
	    }
	    $(this).children("span:first").addClass('eventTrigger');
    });
}
function validate_contactus()
{
		var name=document.getElementById('txtname');
		var phone=document.getElementById('txttelephone');
		var email=document.getElementById('txtemail');
		var message=document.getElementById('txtmessage');
		
		if(name.value=="" || name.value=="Full name")
		{
			alert('Please enter your name');
			name.focus();
			return false;
		}
		else if(phone.value=="" || phone.value=="Telephone")
		{
				alert('Please enter your telephone number');
				phone.focus();
				return false;
		}
		else if(checkInternationalPhone(phone.value)==false)
			{
				alert('Please enter a Valid telephone number');
				phone.focus();
				phone.value='';
				return false;
			}
		else if(email.value=="" || email.value=="Email")
		{
			alert('Please enter your email');
			email.focus();
			return false;
		}
		else if(!emailValidate(email.value))
		{
			alert('Please enter a Valid email address');
			email.value='';
			email.focus();
			return false;
		}
		else if(message.value=="" || message.value=="Message")
		{
			alert('Please enter your message');
			message.focus();
			return false;
		}
		else
		{
			return true;
		}
	
}


function emailValidate(email) 
{
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,3})$/;
   return reg.test(trim(email));
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}

/**
 * DHTML phone number validation script. 
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 4;

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 trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function extractPageName(hrefString)
{
	var arr = hrefString.split('/');
	//alert((arr.length < 3) ? hrefString : arr[arr.length-2].toLowerCase() + arr[arr.length-1].toLowerCase());
	
	return  (arr.length < 3) ? hrefString : arr[arr.length-2].toLowerCase() + arr[arr.length-1].toLowerCase();
}
 
function validate_newsletter()
{
	var name=document.getElementById('first_name');
	//var name=document.getElementById('first_name');	
	var email=document.getElementById('email');
	if(name.value=="" || name.value=="Name")
	{
		alert('Please enter your Name');
		name.focus();
		return false;
	}
	else if(email.value=="" || email.value=="Email")
	{
		alert('Please enter your Email');
		email.focus();
		return false;
	}
	else if(!emailValidate(email.value))
	{
		alert('Please enter a Valid Email');
		email.value='';
		email.focus();
		return false;
	}
	else
	{
		document.forms["newsletter_signup"].submit();	
	}
}

function validate_unsubnewsletter()
{
    var email=document.getElementById('delemail');
	if(email.value=="" || email.value=="Email")
	{
		alert('Please enter your Email');
		email.focus();
		return false;
	}
	else if(!emailValidate(email.value))
	{
		alert('Please enter a Valid Email');
		email.value='';
		email.focus();
		return false;
	}
	else
	{
		document.forms["newsletter_unsubscribe"].submit();	
	}
}
