// <script>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//3 Functions used for the destination vegas homepage. 
//Restore the images generated from the Randomize function

//Global variables to save url generated
var original_zumanity;
var original_mystere;
var original_o;
var original_ka;
				
function post_MM_swapImgRestore(){
	document.getElementById('OPhoto').src = original_o;
	document.getElementById('MysterePhoto').src = original_mystere; 
	document.getElementById('KAPhoto').src = original_ka;
	document.getElementById('ZUMANITYPhoto').src = original_zumanity;
}
//Turn all images off
function pre_MM_SwapImage(){
	document.getElementById('OPhoto').src = '/Cirquedusoleil/asp/DestinationVegas/images/btn_Ooff.gif';
	document.getElementById('MysterePhoto').src = '/Cirquedusoleil/asp/DestinationVegas/images/btn_mystereoff.gif';
	document.getElementById('KAPhoto').src = '/Cirquedusoleil/asp/DestinationVegas/images/btn_KAoff.gif';
	document.getElementById('ZUMANITYPhoto').src = '/Cirquedusoleil/asp/DestinationVegas/images/btn_zumanityoff.gif';
}
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
function MM_swapImgRestore(){ //v3.0
  var i,x,a=document.MM_sr;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; 
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){
    document.MM_sr[j++]=x;
	if(!x.oSrc) x.oSrc=x.src;
	x.src=a[i+2];
  }
}
function MM_preloadImages() { //v3.0
  var d=document;
  if (d.images) {
    if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
	for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0) {
	  d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
	}
  }
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;
  if (!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if (!(x=d[n])&&d.all) x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for (i=0;!x&&d.layers&&i<d.layers.length;i++) x = MM_findObj(n,d.layers[i].document);
  if (!x && d.getElementById) x=d.getElementById(n);
  return x;
}
function MM_showHideLayers() { //v6.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
		if (obj.style) {
			obj=obj.style;
			v=(v=='show')?'visible':(v=='hide')?'hidden':v;
		}
	obj.visibility=v;
	}
}
function openWindow(){
	var winWidth		= 501;  // set required width of window here
	var winHeight		= 351; // set required height of window here
	if (winWidth>screen.width) winWidth = screen.width;
	if (winHeight>screen.height) winHeight = screen.height;
	if (winWidth <= 0) winWidth = screen.width;
	if (winHeight <= 0) winHeight = screen.height;
	var leftPos = 0; leftPos = screen.width/2 - winWidth/2; // centres window
	var topPos	= 0; topPos = screen.height/2 - winHeight/2;  // centres window			
	newWindow = window.open('O-manyFriends.htm','newWin','toolbar=no,location=no,scrollbars=no,resizable=no,width='+winWidth+',height='+winHeight+',left='+leftPos+',top='+topPos+'');
}	
function SubmitSearch(sErrorMsg,sErrorMsg2){
	
	if ((document.getElementById('start_date').value == '') || (document.getElementById('start_date').value == 'dd/mm/yyyy') || (document.getElementById('start_date').value == 'jj/mm/aaaa') || (document.getElementById('start_date').value == 'mm/dd/yyyy') || (document.getElementById('start_date').value == 'mm/jj/aaaa'))
	{
		document.getElementById('error_message').innerHTML = sErrorMsg;
		return false;
	} else if ((document.getElementById('end_date').value == '') || (document.getElementById('end_date').value == 'dd/mm/yyyy') || (document.getElementById('end_date').value == 'jj/mm/aaaa') || (document.getElementById('end_date').value == 'mm/dd/yyyy') || (document.getElementById('end_date').value == 'mm/jj/aaaa'))
	{
		document.getElementById('error_message').innerHTML = sErrorMsg2;
		return false;
	} else {
		//Uncomment to post in search result instead of opening in greybox
		//document.forms[0].submit();
		
		var foundC1;
		var startdate;
		var enddate;
		
		foundC1 = false;
		startdate = document.getElementById('start_date').value;
		enddate = document.getElementById('end_date').value;
		
		//Use regex to replace slashes with "-" because of querystring issue with slashes
		startdate = startdate.replace(/\//g,"-");
		enddate = enddate.replace(/\//g,"-");
		
		//Clean error message
		document.getElementById('error_message').innerHTML = '';
		
		for(i=0; i<document.forms[0].elements.length; i++)
		{
		   if(document.forms[0].elements[i].name == "c1" )
		   {
				foundC1 = true;
		   }
		}

		//Get the siteLang
		var siteLang;
		var url_ref;
		
		url_ref = document.location.href;
		
		url_ref = url_ref.toLowerCase();
		
		if (url_ref.indexOf("/fr/", 0)!=-1)
		{
			siteLang = "fr";
		}	
		else
		{
			siteLang = "en";
		}
		
		var strUrlEnv = "";
		if (url_ref.indexOf("dev.zumanity.com") != -1) {
			strUrlEnv = "http://www.dev.cirquedusoleil.com";
		} else if (url_ref.indexOf("preprod.zumanity.com") != -1) {
			strUrlEnv = "http://www.preprod.cirquedusoleil.com";
		} else if (url_ref.indexOf("zumanity.com") != -1) {
			strUrlEnv = "http://www.cirquedusoleil.com";
		}
				
		if(foundC1)
		{
			// element of name "c1" exists
			var strUrl = strUrlEnv + "/CirqueDuSoleil/" + siteLang + "/LasVegas/popup.html?start_date=" + startdate + "&end_date=" + enddate + "&c1=" + document.getElementById('c1').value;
		}
		else
		{
			var strUrl = strUrlEnv + "/CirqueDuSoleil/" + siteLang + "/LasVegas/popup.html?start_date=" + startdate + "&end_date=" + enddate;
		}

		//return GB_showCenter('', strUrl,'500','790');
		
		var init={caption:"",center_win:true,height:500,width:790,fullscreen:false,callback_fn:enableScroll};
		var win=new GB_Window(init);
		disableScroll(); 
		return win.show(strUrl); 
		
		//return GB_showFullScreen('', strUrl,'500','768');

	}
	//return true; 
}
var bh,bw,bo,hh,hw,ho;
function cancel(e){
	return false;
}
function enableScroll(){
	if (window.removeEventListener)
		window.removeEventListener('DOMMouseScroll', cancel, false);
	window.onmousewheel = document.onmousewheel = null;
	if (!window.opera) {
		document.body.style.height = bh; //"auto";
		document.body.style.width = bw; //"auto";
		document.body.style.overflow = bo; //"";
		document.getElementsByTagName("html")[0].style.height = hh; //"auto";
		document.getElementsByTagName("html")[0].style.width = hw; //"auto";
		document.getElementsByTagName("html")[0].style.overflow = ho; //"";
	}	
}
function disableScroll(){
	if (window.addEventListener)
		window.addEventListener('DOMMouseScroll', cancel, false);
	window.onmousewheel = document.onmousewheel = cancel;
	if (!window.opera) {
		bh = document.body.style.height;
		bw = document.body.style.width;
		bo = document.body.style.overflow;
		hh = document.getElementsByTagName("html")[0].style.height;
		hw = document.getElementsByTagName("html")[0].style.width;
		ho = document.getElementsByTagName("html")[0].style.overflow;
		document.body.style.height = "100%";
		document.body.style.width = "100%";
		document.body.style.overflow = "hidden";
		document.getElementsByTagName("html")[0].style.height = "100%";
		document.getElementsByTagName("html")[0].style.width = "100%";
		document.getElementsByTagName("html")[0].style.overflow = "hidden";
	}
}