//Drop Down Menu

var menuids=["tabmenu"] 

function buildsubmenus_horizontal(){
for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
		if (ultags[t].parentNode.parentNode.id==menuids[i]){ //if this is a first level submenu
			ultags[t].style.top=ultags[t].parentNode.offsetHeight+"px" //dynamically position first level submenus to be height of main menu item
			ultags[t].parentNode.getElementsByTagName("a")[0].className="mainfoldericon"
		}
		else{ //else if this is a sub level menu (ul)
		  ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    	ultags[t].parentNode.getElementsByTagName("a")[0].className="subfoldericon"
		}
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.visibility="visible"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.visibility="hidden"
    }
    }
  }
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus_horizontal, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus_horizontal)


//Image Rollover
function SimpleSwap(el,which){
        el.src=el.getAttribute(which||"origsrc");
}

function SimpleSwapSetup(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
    // preload image
    // comment the next two lines to disable image pre-loading
    //x[i].oversrc_img = new Image();
    //x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
  }
}

function ChildMouseOver(childObj) {
	childname = childObj.id;
	ndx = childname.indexOf('_');
	if (ndx != -1) {
		parentname = childname.substr(0, ndx);
		parentObj = document.getElementById(parentname);
		if (parentObj != null) {
			parentObj.src=parentObj.getAttribute('oversrc');
		} else {
			parentObj = document.getElementByName(parentname);
			if (parentObj != null) {
				parentObj.src=parentObj.getAttribute('oversrc');
			}
		}
	}
}

function ChildMouseOff(childObj) {
	childname = childObj.id;
	ndx = childname.indexOf('_');
	if (ndx != -1) {
		parentname = childname.substr(0, ndx);
		parentObj = document.getElementById(parentname);
		if (parentObj != null) {
			parentObj.src=parentObj.getAttribute('origsrc');
		} else {
			parentObj = document.getElementByName(parentname);
			if (parentObj != null) {
				parentObj.src=parentObj.getAttribute('origsrc');
			}
		}
	}
}
 
var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};
window.onload = function(){PreSimpleSwapOnload(); SimpleSwapSetup();} 


//Form Validator
function validateForm(theForm) {
     	if (theForm.first_name.value == ""){
     		alert("Please enter your first name.");
     		theForm.first_name.focus();
     		return (false);
     	}
     	if (theForm.last_name.value ==""){
     		alert("Please enter your last name.");
     		theForm.last_name.focus();
     		return (false);
     	}
		if (theForm.title.value == ""){
     		alert("Please enter your Title.");
     		theForm.title.focus();
     		return (false);
		}
     	if (theForm.organization.value ==""){
     		alert("Please enter your Organization.");
     		theForm.organization.focus();
     		return (false);
     	}
		if (theForm.phone.value ==""){
     		alert("Please enter your phone number.");
     		theForm.phone.focus();
     		return (false);
     	}
		if (theForm.contactCountryCode.value == ""){
     		alert("Please enter your country.");
     		theForm.contactCountryCode.focus();
     		return (false);
     	}
     	if (theForm.email.value ==""){
     		alert("Please enter your e-mail address.");
     		theForm.email.focus();
     		return (false);
     	}
     	if(validEmail(theForm.email.value) == false){
     		alert("Please enter a valid e-mail address.");
     		theForm.email.focus();
     		return (false);
     	}     	
		if (theForm.comp_url.value == ""){
     		alert("Please enter your Company URL.");
     		theForm.comp_url.focus();
     		return (false);
		}		
}
                 
     function validEmail(email) {
     	invalidChars = " /:,;";
     	for (i=0; i < invalidChars.length; i++) {
     		badChar = invalidChars.charAt(i);
     		if (email.indexOf(badChar,0) > -1) {
     			return false;
     		}
     	}
     	atPos = email.indexOf("@",1)
     	if (atPos == -1) {
     		return false;
     	  }
     	if (email.indexOf("@",atPos+1) > -1) {
     		return false;
     	}
     	periodPos = email.indexOf(".",atPos)
     	if (periodPos == -1) {
     		return false;
     	}
     	if (periodPos+3 > email.length) {
     		return false;
     	}
     	return true;
      }

     	var dynamicSendTo = false;
     	var dynamicSubject = false;
     	var dynamicOverview = false;
     	var dynamicTimes = false;
     	var dynamicMoreInfo = false;
     
      if( location.search.indexOf('Orlando') > -1 ) {
dynamicSendTo 	= "exhibit@gartner.com";
dynamicSubject 	= "Orlando_Sponsor_Info_Request";
} else if( location.search.indexOf('Cannes') > -1 ) {
dynamicSendTo 	= "exhibit@gartner.com";
dynamicSubject 	= "Cannes_Sponsor_Info_Request";
} else if( location.search.indexOf('Sydney') > -1 ) {
dynamicSendTo 	= "patricia.calleja@gartner.com";
dynamicSubject 	= "Sydney_Sponsor_Info_Request";
} else if( location.search.indexOf('Tokyo') > -1 ) {
dynamicSendTo 	= "ggevents@gartner.co.jp.";
dynamicSubject 	= "Tokyo_Sponsor_Info_Request";
} else if( location.search.indexOf('Sandiego') > -1 ) {
dynamicSendTo 	= "exhibit@gartner.com";
dynamicSubject 	= "San_Diego_Sponsor_Info_Request";
} else if( location.search.indexOf('SanFrancisco') > -1 ) {
dynamicSendTo 	= "exhibit@gartner.com";
dynamicSubject 	= "San_Franciso_Sponsor_Info_Request";
} else if( location.search.indexOf('Barcelona') > -1 ) {
dynamicSendTo 	= "exhibit@gartner.com";
dynamicSubject 	= "Barcelona_Sponsor_Info_Request";
}


// POPUP FUNCTIONS (original code from gartner.com utility.js)
// added here as needed by each page for terms of use in footer include.
function rawPopUp(url, width, height, features, target) {

   // main raw popup
   // written by Peter Mahnke 20 May 2004
   //
   // attempt to clean up all random js popups

   var u = url;
   var t = target;
   var w = width;
   var h = height;
   var f = features;

  // return if there is no URL
  if (u == null) {
      return false;
  }

   // set up default values if none passed
   t = t ? t : "_blank";
   w = w ? w : 750;
   h = h ? h : 550;
   f = f ? f : "resizable=yes,scrollbars=yes,toolbar=no";

   // find middle x and y position of the screen
   var left = (window.screen.width - w)/2;
   var top  = (window.screen.height - h)/2;

   var newWin=null;
   var settings = 'width=' + w + ',height=' + h + ',top=' + top + ',left=' + left + ', ' + f;

   newWin = window.open(u, t, settings);
   newWin.focus();
   return(newWin);

}