/*
	@Developer : Sushil.
	@DateCreated: 18-nov-2010
	@Desc:
		Common is a object which has some functions which do related task for change image and left links.
	@Usage:
		var ObjCommon = new Common();
*/
function Common()
{
}
Common.prototype.TopMenuClicked = function(reference,img,leftLink)
{

}
Common.prototype.ChangeLogoImage = function(imgSrc)
{
	$("#logoImageContainer").attr("src",imgSrc);
}
Common.prototype.ChangeLeftLinkFor = function(clickedHtml)
{
	this.LeftLinks(clickedHtml);
}
Common.prototype.LeftLinks = function(linksFor)
{
	var li = "";
	$("#leftLinkStudioAbroad").attr("class","displayNone");
	$("#leftLinkRiskInfoSys").attr("class","displayNone");
	$("#leftLinkI3s").attr("class","displayNone");
	$("#leftLinkWorldCompetencies").attr("class","displayNone");
	$("#leftLinkApplicationGateway").attr("class","displayNone");
	$("#leftLinkColloquia").attr("class","displayNone");
	$("#div_related_links").css('display','block');
	switch(linksFor)
	{
		case "StudioAbroad": 
			$("#leftLinkStudioAbroad").attr("class","displayBlock");
			break;
		case "RiskInfoSys":
			$("#leftLinkRiskInfoSys").attr("class","displayBlock");
			break;
		case "i3s": 
			$("#leftLinkI3s").attr("class","displayBlock");
			break;
		case "WorldCompetencies": 
			$("#leftLinkWorldCompetencies").attr("class","displayBlock");
			break;
		case "ApplicationGateway": 
			$("#leftLinkApplicationGateway").attr("class","displayBlock");
			break;
		case "Colloquia": 
			$("#leftLinkColloquia").attr("class","displayBlock");
			break;
		case "ClientList": 
			// $("#div_related_links").css('display','none');
			// $("#nav > *").removeClass("current");
				location.href = "about_client_list.html#topClientList";
			// $("#menuStudionAbroad").attr("class","current");
			break;
	}
}
function GetPageQueryString()
{
		var reg = /.*\.html\?(.*)/i;	// Regular expression find content after .html
		var pageName =  location.href.match(reg);	// Check whether it found matching record.
		pageName = pageName[1];
		var getURL = "";
		var pageLocation = "";
		var pageNameForDIsplay = "";
		if(pageName == "studioabroad_demo_request.html" || pageName == "studioabroad_demo_request")
		{
			getURL = "studioabroad.html";
			pageNameForDIsplay = "StudioAbroad";
		}
		if(pageName == "riskinfosys_demo_request.html" || pageName == "riskinfosys_demo_request")
		{
			getURL = "riskinfoSys.html";
			pageNameForDIsplay = "RiskInfoSys";
		}
		if(pageName == "i3s_demo_request.html" || pageName == "i3s_demo_request")
		{
			getURL = "i3s.html";
			pageNameForDIsplay = "i3s";
		}
		if(pageName == "worldcompetencies_demo_request.html" || pageName == "worldcompetencies_demo_request")
		{
			getURL = "worldcompetencies.html";
			pageNameForDIsplay = "WorldCompetencies";
		}
		if(pageName == "applicationgateway_demo_request.html" || pageName == "applicationgateway_demo_request")
		{
			getURL = "applicationgateway.html";
			pageNameForDIsplay = "ApplicationGateway";
		}
		if(pageName == "colloquia_demo_request.html" || pageName == "colloquia_demo_request")
		{
			getURL = "colloquia.html";
			pageNameForDIsplay = "Colloquia";
		}
		var html = "";
		var htmlCarreer = "";
		if(pageName == "career_at_terra_dotta.html" || pageName == "career_at_terra_dotta")
		{
			getURL = "index.html";
			pageLocation = "Return to Home Page";
			$("#pageLocation").html(pageLocation);
			htmlCarreer = "<h1>Thank you<br /><span>for your interest in <span id='pageName'>Terra Dotta</span></span></h1><p> We have received the information you <br/> submitted and will keep it on file for review <br/> as positions become available.<br />";
		}
		if(pageName && getURL)
		{
			html = "<h1>Thank you<br /><span>for your interest in <span id='pageName'>Terra Dotta</span></span></h1><p> We have received the information you submitted and will <br/> contact you as soon as possible.<br />";
			if(document.getElementById("pageLocation"))
			{
				if(pageName != "career_at_terra_dotta")
				{
					$(html).insertBefore("#pageLocation");
				}
				else
				{
					$(htmlCarreer).insertBefore("#pageLocation");
				}
				$("#pageLocation").attr("href",getURL);
			}
		}
		else
		{
			html = "<h1>Thank you<br /><span>for your interest in <span id='pageName'>Terra Dotta</span></span></h1><p> We have received the information you submitted and will <br/> contact you as soon as possible.<br />";
			$(html).insertBefore("#pageLocation");
			$("#pageLocation").attr("href","javascript:void(0)");
			$("#pageLocation").bind("click",function()
				{
					history.go(-1)
				}
			);
		}
		if(pageNameForDIsplay)
		{
			$("#pageName").html(pageNameForDIsplay);
		}
}
var currentPage_Name="";
$(document).ready
(
	function()
	{
		var getPageLocation = location;
		getPageLocation = String(getPageLocation);
		var regFindFile = /[a-z0-9_-]+(.+)\.html$/i;
		var pageNameArr = "";
		var pageName = "";
		if(getPageLocation.match(regFindFile))
		{
			pageNameArr = getPageLocation.split("/");
			var getFileName = pageNameArr[pageNameArr.length-1].match(/(.*)\.html$/i);
			pageName = getFileName[1];
			currentPage_Name = pageName;
		}
		var getHostName = location.hostname;
		var getPathName = location.pathname;
		var isStaging = /staging/i;
		if(document.forms[0])
		{
			if(getPathName.match(isStaging))
			{
				document.forms[0].retURL.value = "http://www.terradotta.com/staging/thankyou.html";
			}
			else
			{
				/* here we have to place the url to where your thank you page exists. */
				document.forms[0].retURL.value = "http://www.terradotta.com/thankyou.html?"+pageName;
			}
		}
		else
		{
			
		}
		if(!document.referrer || document.referrer == "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8")
		{
			//$("#previousPage").css("display","block");
		}
	}
);
/*
	Common form validation for all pages. ;)
*/
var isAppend = 0;
function limitChars(textid, limit, infodiv)
{
	var text = $('#'+textid).val();	
	var textlength = text.length;
	if(textlength > limit)
	{
		$('#' + infodiv).html('You cannot write more then '+limit+' characters!');
		$('#'+textid).val(text.substr(0,limit));
		return false;
	}
	else
	{
		$('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');
		return true;
	}
}

$(document).ready
(
	function()
	{
		$('#00N40000001m4Cc').after("<br/><span id='charlimit'></span>");
		$('#00N40000001m4Cc').keyup
		(
			function()
			{
				limitChars('00N40000001m4Cc', 1000, 'charlimit');
			}
		);

		if(document.forms[0])
		{
			$(document.forms[0].submit).bind("click",function ValidateForm(e)
												  {
														$("#first_name").val($("#first_name").val().removeSpecialCharacter(""));
														$("#00N40000001m4Cc").val($("#00N40000001m4Cc").val().removeSpecialCharacter(""));
														$("#last_name").val($("#last_name").val().removeSpecialCharacter(""));
														var first_name = $("#first_name").val();
														var last_name = $("#last_name").val();
														var email = $("#email").val();
														var comment = $("#00N40000001m4Cc").val();
														var phone = "";
														if(currentPage_Name && currentPage_Name!="career_at_terra_dotta")
														{
															phone = $("#phone").val();
															var institutionName = $("#company").val();
														}
														var regPhone = /^0?[0-9]{10}$/i;
														var regHyphenPhone = /^[0-9]{3}\-[0-9]{3}\-[0-9]{4}$/;
														var regEmail = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
														var isError = 0;
														if((!first_name || first_name=="First"))
														{
															alert("Please enter firstname");
															$("#first_name").focus();
															isError = 1;
														}
														if((!last_name || last_name=="Last") && !isError)
														{
															alert("Please enter lastname");
															$("#last_name").focus();
															isError = 1;
														}
														if(!email.match(regEmail) && !isError)
														{
															alert("Please enter valid email");
															$("#email").focus();
															isError = 1;
														}
														if(currentPage_Name && currentPage_Name!="career_at_terra_dotta")
														{
															if(!(phone.match(regPhone) || phone.match(regHyphenPhone)) && !isError)
															{
																/* [ PLEASE UNCOMMENT BELOW STATEMENT FOR TO MAKE PHONE FIELD REQUIRED ] */
																//alert("Please enter valid phone");
																//$("#phone").focus();
																//isError = 1;
															}
														}
														if(document.getElementById("company")!=null && !institutionName && !isError)
														{
															alert("Please Institution or Company Name");
															$("#company").focus();
															isError = 1;
														}
														if(!comment && !isError)
														{
															alert("Please enter comment");
															$("#00N40000001m4Cc").focus();
															isError = 1;
														}
														if(isError==1)
														{
															if(e.returnValue)
															{
																e.returnValue = false;
															}
															else
															{
																e.preventDefault();
															}
														}
												  }
			);
		}
	}
);
function changeLocation()
{
	if(arguments.length)
	{
		var reg = /.*studioabroad_support\.html(.*)/i;	// Regular expression find content after .html
		var match =  location.href.match(reg);	// Check whether it found matching record.
		if(match)
		{
			$("#leftLinkStudioAbroad").css("display","none");	// Display none for left links.
			$("#logoImageContainer").attr("src","common/images/terra_dotta_logo.jpg");	// Change logo image
			$("#div_related_links").css("display","none");	// Display:none of div_related_links
			$("#nav > *").each	// Iterate n times content available in #nav
			(
				function()
				{
					if($(this).hasClass("current"))	// [ If top contact link clicked it checks for not any link highlighted is so then it will remove class ]
					{
						$(this).removeClass("current");	// Remove Class current.
					}
				}
			);
		}
		var arg = arguments[0];
		if(arg == "topSupport" && !match)
		{
			location.href = "studioabroad_support.html#topSupport";
		}
	}
	else
	{
		location.href = "about_client_list.html";
	}
}
var ObjCommon = new Common();
