// TransMenu JavaScript Document Developed by Charanjeet Singh.
// Copyright (C) 1999-2008 Vinove Software and Services (P) Ltd.

var isMozilla;

/******************************************
Function name : generateMenu
Return type : None
Date created : 14th May 2008
Date last modified : 15th May 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : Function generates onmouseover & onmouseout events for menu.
User instruction : generateMenu(selectedMenu)
******************************************/
generateMenu = function(selectedMenu) { 

	//get the menu navigation root
	navRoot = document.getElementById("nav");
	
	//find the menu navigation root, if found then enter here
	if(navRoot)
	{
		//get the childNodes of the navigation root 
		//start the loop and continue till the count of childNodes 
		for (i=0; i<navRoot.childNodes.length; i++) 
		{
			//get the current node
			node = navRoot.childNodes[i];
			
			//if the node is a <li> tag, so we process the menu
			if (node.nodeName=="LI")
			{
				//if the node id != menu, so we process the menu
				if(node.id!=selectedMenu && node.id!='')
				{
					//check the browser
					isMozilla = (document.all) ? 0 : 1;
					
					//write the onmouseover event code for current node
					node.onmouseover=function() {
						
						//change the selected menu class to unselect it
						document.getElementById(selectedMenu).className="remove_current";
						
						//hide the sub menu of this selected menu
						hideMenu('sub_'+selectedMenu);
						
						//if the browser is mozilla
						if(isMozilla)
						{
							//open menu for current node
							openMenu('sub_'+this.id);
							
							//change the class of this node.
							document.getElementById(this.id).className="general";
						}
						else
						{
							//change the class of this node.
							this.className = "general over";
						}
					}
					
					//write the onmouseout event code for current node
					node.onmouseout=function() {
						
						//change back the selected menu class to again select it
						document.getElementById(selectedMenu).className="current";
						
						if(isMozilla)
						{
							//hide menu for current node
							hideMenu('sub_'+this.id);
							
							//change the class of this node.
							document.getElementById(this.id).className="";
						}
						else
						{
							//change the class of this node.
							this.className ="";
						}
						
						//open the sub menu of this selected menu
						openMenu('sub_'+selectedMenu);
					}
				}
			}
		}
	}
	//send an alert that menu system not found
	else
	{
		alert('Menu system not found. Please check your code.');
	}
}

/******************************************
Function name : openMenu
Return type : None
Date created : 14th May 2008
Date last modified : 15th May 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : Function will open the menu as described by the selectMenu element.
User instruction : openMenu(selectMenu)
******************************************/
openMenu = function(selectMenu) {

	//get the selectMenu element on document
	displayMenu = document.getElementById(selectMenu);
	
	//if found change the style of this element
	if(displayMenu)
	{
		displayMenu.style.display="block";
	}
}

/******************************************
Function name : hideMenu
Return type : None
Date created : 14th May 2008
Date last modified : 15th May 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : Function will hide the menu as described by the selectMenu element.
User instruction : hideMenu(selectMenu)
******************************************/
hideMenu = function(selectMenu) {
	
	//get the selectMenu element on document
	displaySubMenu = document.getElementById(selectMenu);
	
	//if found change the style of this element
	if(displaySubMenu)
	{
		displayMenu.style.display="none";
	}	
}
function changeReturnURL()
{
		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];
		}
		var getHostName = location.hostname;
		var getPathName = location.pathname;
		var isStaging = /staging/i;
		if(document.forms[0])
		{
			if(pageName == "recive_newsletter" || pageName == "request_meeting")
			{
				if(getPathName.match(isStaging))
				{
					document.forms[0].retURL.value = "http://www.terradotta.com/staging/thankyou_popup.html?"+pageName;
					/* here we have to place the url to where your thank you page exists. */
				}
				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_popup.html";
				}
			}
			else
			{
				if(getPathName.match(isStaging))
				{
					document.forms[0].retURL.value = "http://www.terradotta.com/staging/thankyou.html?"+pageName;
				}
				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;
				}
			}
	
		}
}
window.onload = function()
{
	changeReturnURL();
}

function validateForm()
{
	var first_name = document.getElementById("first_name");
	var last_name = document.getElementById("last_name");
	var email = document.getElementById("email");
	var institution = document.getElementById("company");
	var describe = document.getElementById("00N40000002EcWp");
	if(!first_name.value)
	{
		alert("Please enter the Firstname");
		first_name.focus();
		return false;
	}
	if(!last_name.value)
	{
		alert("Please enter the Lastname");
		last_name.focus();
		return false;
	}
	if(!email.value.match(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/))
	{
		alert("Please enter the valid Email");
		email.focus();
		return false;
	}
	if(!institution.value)
	{
		alert("Please enter Institution or Company Name");
		institution.focus();
		return false;
	}
	if(!describe.value)
	{
		alert("Please choose which best describes you");
		return false;
	}
	return true;
}
/*
	@Developer	: Sushil.
	@Description: Will remove all special charachter from field.
	@Return Type: String
	@DateCreated: 8 March 2011
	@Team		: Web Development
*/
String.prototype.removeSpecialCharacter = function(replacementString)
{
	var reg = /[\'\{\}\'\"\[\]\@\#\\\!\<\>\$\%\^\&\*\(\)]*/ig;	// Regular expression for removing special character in string
	if(this.match(reg))
	{
		return (this.replace(reg,replacementString));
	}
}
