// Below is used to detect mouse location for Tooltips and Maps popup
<!--
	// Detect if the browser is IE or not.
	// If it is not IE, we assume that the browser is NS.
	var IE = document.all?true:false

	// If NS -- that is, !IE -- then set up for mouse capture
	if (!IE) document.captureEvents(Event.MOUSEMOVE)

	// Set-up to use getMouseXY function onMouseMove
	document.onmousemove = getMouseXY;

	// Temporary variables to hold mouse x-y pos.s
	var tempX = 0;
	var tempY = 0;
	var idmap = null;

//-->    


// Style Swapper
function BGNew(obj, new_style, message) { 
obj.className = new_style; 
window.status = message; 

//if (document.getElementById('idTootTip')){document.getElementById('idTootTip').style.display='none';}
}

// List Menus

sfHover = function() {
if (document.getElementById("nav")!=null)
{
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

// Show-Hide Layers

function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
function pageWidth() {return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;} 
function pageHeight() {return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;} function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;} function posTop() {return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;} function posRight() {return posLeft()+pageWidth();} function posBottom() {return posTop()+pageHeight();}

//Function to repeat strings in Nth times)
function repeat(t,n)
{
	var r='';
	for (l=0; l<n; l++) 
	{r=r+t;}
	
	return r;
}

//Function to format Amount with leading zeroes. 
//This is for sorting purpose
function fmtAmtZ(i)
{	
	if (!i)
	{	return '';}
	else
	{
		var l=(10-i.length);
		i=repeat('0',l)+i;
		return i;
	}
}

//Function to set Destination CheckBox Tab
function setDestTab(id)
{
    var ChangeCheck;
    var dest, l, i;
    ChangeCheck = true;
    if (id.indexOf('chk') >= 0)
    {
        //id = 'UNCHECKALL';
        id = id.substring(3, id.length);
        ChangeCheck = false;
    }
	var d=document.getElementById(id);
	
	//Need to check if it's Un-Check all
	if (id == 'UNCHECKALL')
	{
	    if (ChangeCheck)
	    {
	        if (d.checked)
	            d.checked = false;
	        else
	            d.checked = true;
	    }
	    if (d.checked)
	    {
	        //Loop all in the elements and hide the destinations
	        dest=document.getElementById('idDestTab').getElementsByTagName('input');
	        l=dest.length;
	        i=0;
	        if (l>0)
	        {
		        for (i=0;i<l;i++) 
		        {
			        if (dest[i].type=='checkbox' && dest[i].id != 'UNCHECKALL')
			        {
				        dest[i].checked = false;
				        showDestRecs(dest[i]);
			        }
		        }
	        }
	    }
	    else
	    {
	        //Loop all in the elements and show the destinations
	        dest=document.getElementById('idDestTab').getElementsByTagName('input');
	        l=dest.length;
	        i=0;
	        if (l>0)
	        {
		        for (i=0;i<l;i++) 
		        {
			        if (dest[i].type=='checkbox' && dest[i].id != 'UNCHECKALL')
			        {
				        dest[i].checked = true;
				        showDestRecs(dest[i]);
			        }
		        }
	        }
	    }
	}
	else
	{
	    if (ChangeCheck)
	    {
	        if (d.checked) 
	        {
		        d.checked=false;
	        }
	        else 
	        {
		        d.checked=true;
	        }
	    }
	    //Need to loop and hide all un-checked tabs first
        dest=document.getElementById('idDestTab').getElementsByTagName('input');
        l=dest.length;
        i=0;
        if (l>0)
        {
            for (i=0;i<l;i++) 
            {
	            if (dest[i].type=='checkbox' && dest[i].id != 'UNCHECKALL' && dest[i].checked == false)
	            {
		            showDestRecs(dest[i]);
	            }
            }
        }
        //Now loop and show all checked tabs first
        dest=document.getElementById('idDestTab').getElementsByTagName('input');
        l=dest.length;
        i=0;
        if (l>0)
        {
            for (i=0;i<l;i++) 
            {
	            if (dest[i].type=='checkbox' && dest[i].id != 'UNCHECKALL' && dest[i].checked == true)
	            {
		            showDestRecs(dest[i]);
	            }
            }
        }
	}
	return true;
}

//Function to display Map
function MapOnOff(s,t,i)
{
	if (s=='ON')
	{
		if (!document.getElementById('idPopMap'))
		{
			var idPop=document.createElement('div');
			idPop.setAttribute('id',['idPopMap']);
			document.body.appendChild(idPop);
			if (i.indexOf('NoImage')>=0){document.getElementById('idPopMap').className='imgNoPop';}
			else {document.getElementById('idPopMap').className='imgPop';}
			
			var idPopT=document.createElement('div');
			idPopT.setAttribute('id',['idPopTitle']);
			document.getElementById('idPopMap').appendChild(idPopT);
			document.getElementById('idPopTitle').className='imgTitle';
			var loc=t.indexOf('<');
			if (loc>0){t=t.substring(0,loc)}
			document.getElementById('idPopTitle').innerHTML = t.replace(/~/g,'\'');
			
			var idPopI=document.createElement('div');
			idPopI.setAttribute('id',['idPopImg']);
			document.getElementById('idPopMap').appendChild(idPopI);
			document.getElementById('idPopImg').className='imgMap';
			
			var idPopIm=document.createElement('img');
			idPopIm.setAttribute('id',['idMapImg']);
			idPopIm.setAttribute('src',[i]);
			//idPopIm.setAttribute('lowsrc',[document.getElementById('lowimg').value]);
			document.getElementById('idPopImg').appendChild(idPopIm);
			document.getElementById('idPopTitle').style.width=document.getElementById('idPopImg').style.width;
			document.getElementById('idMapImg').onerror = function(evt){document.getElementById('idPopMap').className='imgNoPop';document.getElementById('idMapImg').src=document.getElementById('lowimg').value+'NoImage.GIF';}
			document.getElementById('idMapImg').lowsrc= document.getElementById('lowimg').value+'imgLoader.gif';
		}
		else
		{
			var loc=t.indexOf('<');
			if (loc>0){t=t.substring(0,loc)}
			document.getElementById('idPopTitle').innerHTML = t.replace(/~/g,'\'');
			document.getElementById('idMapImg').lowsrc= document.getElementById('lowimg').value+'imgLoader.gif';
			document.getElementById('idMapImg').src=i;
			if (i.indexOf('NoImage')>=0){document.getElementById('idPopMap').className='imgNoPop';}
			else {document.getElementById('idPopMap').className='imgPop';}
			document.getElementById('idPopTitle').style.width=document.getElementById('idPopImg').style.width;
		}
		idmap=document.getElementById('idPopMap');
		idmap.style.display='';
		if (IE) {tempX = (tempX + 25)}
		else  {tempX = (tempX + 30)}
		idmap.style.left = tempX + 'px';
		idmap.style.top = tempY + 'px';
	}
	else
	{	
		if(document.getElementById('idPopMap')){document.getElementById('idPopMap').style.display='none'}
		if(document.getElementById('idMapShadow')){ document.getElementById('idMapShadow').style.display='none'}
		if(document.getElementById('idPopTitle')){document.getElementById('idPopTitle').innerHTML = '';}
		//if(document.getElementById('idMapImg')){document.getElementById('idMapImg').src='';}
		if (document.getElementById('idTootTip')){document.getElementById('idTootTip').style.display='none'}
		idmap=null;
	}	
}

//Function to display ToolTip
function toolTip(text)
{
	if (!document.getElementById('idTootTip'))
	{
		var idT=document.createElement('div');
		idT.setAttribute('id',['idTootTip'])
		document.body.appendChild(idT);
	}
	var idT=document.getElementById('idTootTip');
	if (text!='')
	{
		idT.className='toolTipBox';
		idT.innerHTML=text
		idmap=document.getElementById('idTootTip');
		idT.style.display='';
		if (IE) {tempX = (tempX + 25)}
		else  {tempX = (tempX + 30)}
		//idmap.style.left = tempX + 'px';
		//idmap.style.top = tempY + 'px';
	}
	else 
	{
		document.body.removeChild(idT);
		if (document.getElementById('idMapShadow')){document.getElementById('idMapShadow').style.display='none';}
		idmap=null;
	}
}

//Function to get mouse coordinate. This function is also being used in ToolTip and Map display.
function getMouseXY(e) {

  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft;
    tempY = event.clientY + document.body.scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX;
    tempY = e.pageY;
  }  
  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  if (idmap!=null)
  {
	
	if (IE) {tempX = (tempX + 15)}
	else  {tempX = (tempX + 17)}

	idmap.style.left = tempX + 'px';	
	
	if (idmap == document.getElementById('idTootTip'))
	{
		idmap.style.top = tempY + 'px';
		if (idmap.innerHTML.indexOf('Land Price')>=0||idmap.innerHTML.indexOf('Details')>=0)
			{tempX=(tempX-idmap.offsetWidth-30 );idmap.style.left = tempX + 'px';;}
		else{idmap.style.left = tempX + 'px';}
		//idmap.style.left = tempX + 'px';
		dropShadow(idmap,tempX,tempY);
	}
	else if (idmap == document.getElementById('idPopMap'))
	{
		wH = ((GetWindowHeight() / 2) + GetScrollY() - (idmap.offsetHeight / 2));		
        idmap.style.top  = wH + 'px';		
		
		dropShadow(idmap,tempX,wH);
	}
  }
  return true
}

//Function to display shadow in ToolTip and Map
function dropShadow(id,l,t)
{	
	if (!document.getElementById('idMapShadow'))
	{
		var idS=document.createElement('div');
		idS.setAttribute('id',['idMapShadow'])
		document.body.appendChild(idS);
	}
	var idSh=document.getElementById('idMapShadow');
	var s=7; //shadow thickness
	var w=id.offsetWidth;
	var h=id.offsetHeight;
	//alert('w=' + w+ ' --- ' + ' h='+h);
	
	t=t+s+'px';
	l=l+s+'px';
	//alert('t='+t+' l='+l + ' w='+w + ' h='+h);
	idSh.style.top=t;
	idSh.style.left=l;
	idSh.style.width=w+'px';
	idSh.style.height=h+'px';
	idSh.style.zIndex='8999';
	id.style.zIndex='9000';
	idSh.style.display='';
	idSh.className='imgShadow';
	
	//alert(id.style.left + ' ' + idSh.style.left);
}


//Function to show package listings
function showPkgLst(grpId,v)
{
	var d=document.getElementById('idPkgLst').getElementsByTagName('tr')
	var season=document.getElementById('idSeason').value
	var l=d.length;
	var gl=grpId.length;
	var idgr='';
	var Season='';
	var SupplierID='';
	var ProdID='';
	var ProdSupp=''
	var prodlst='|';
	
	if (l!=0)
	{
		for (i=0;i<l;i++) 
		{   
			if (d[i].id!='')
			{
				var iar=(d[i].id).split('-|-');
				ProdID=iar[1];
				Season=iar[2];
				SupplierID=iar[3];
				ProdSupp=ProdID+'-'+SupplierID;
				if (iar.length>0)
				{	idgr=d[i].id.substring(0,gl);
					//alert('grpId='+grpId+'  v='+v+'  season='+season+ '  iar(2)='+iar[2]);					
					if (v=='all')
					{
						if (season=='ALL'){d[i].style.display='';}
						else if (season==Season){d[i].style.display='';} 
						else{d[i].style.display='none';}
					}
					else //v!='all'
					{
						//alert('grpId='+grpId+ ' idgr='+idgr+'  v='+v+'  season='+season+ '  iar(2)='+iar[2]);
						if (season=='ALL' && idgr==grpId){d[i].style.display=v;}
						else if (season!=Season && idgr==grpId){d[i].style.display='none';}
						else if (idgr==grpId) {d[i].style.display=v;} 
					}
					if (d[i].style.display=='') 
					{
						if (prodlst.indexOf('|'+ProdSupp+'|')>=0)
						{
						    d[i].style.display = 'none';
						}
						else 
						{prodlst += ProdSupp+'|';}
					}					
					
				}
			}
		}
	}
}

//Function to display destination package list when Checkbox Tab is clicked
function showDestRecs(id)
{	
	var iVal=id.value //+'-';
	//alert(iVal);
	if (id.checked){showPkgLst(iVal,'');}
	else {showPkgLst(iVal,'none');}
	
}

//Function to add <li> tag
function addLITag(idS,idT){
	 var mainDIV = document.getElementById('idDestTab');
	 var ulMain = mainDIV.getElementsByTagName('ul').item(0);
	 var sT ="\setDestTab('"+idS+"');";
	 var sD ="\showDestRecs(this);"
	 var newLI = document.createElement('li');
	 var newLabel = document.createElement('label');
	 newLabel.setAttribute('for',''+idS+'');
	 newLabel.setAttribute('onclick',''+sT+'');
	 newLabel.innerHTML=idT;
	 
	 newLI.appendChild(newLabel);
	 var newChkBox = document.createElement('input');
	 //newChkBox.setAttribute('type',['checkbox']);
	 //newChkBox.setAttribute('value',[idS]);
	 //newChkBox.setAttribute('title',[idT]);
	 //newChkBox.setAttribute('id',[idS]);
	 //newChkBox.setAttribute('onclick',[sD]);
	 newChkBox.type='checkbox';
	 newChkBox.value=idS
	 newChkBox.title=idT;
	 newChkBox.id=idS;
	 newChkBox.onclick=''+sT+'';
	 
	 
	 //newChkBox.onclick=sD;
	 newLI.appendChild(newChkBox);
	 ulMain.appendChild(newLI);
}
function QryStr(strKey){try{var qs=window.location.search.substring(1).split("&");for(var i=0;i<qs.length;i++)if(qs[i].split("=")[0].toUpperCase()==strKey.toUpperCase())return qs[i].split("=")[1];return''}catch(ex){return''}}
//Function to populate destination checkbox tabs
function popDestTab()
{
	var d=document.getElementById('idSubLnk').getElementsByTagName('li')
	var a=null;
	var l=d.length;
	var li='<li><label  style="display:inline;" onclick="setDestTab(\'id_subgroup\');" >id_subgrptitle</label><input type="checkbox" checked value="id_subgroup" id="id_subgroup" title="id_subgrptitle" onclick="setDestTab(\'chkid_subgroup\')" /></li>'
	var liUncheck = '<li><label  style="display:inline;" onclick="setDestTab(\'id_subgroup\');" >id_subgrptitle</label><input type="checkbox" value="id_subgroup" id="id_subgroup" title="id_subgrptitle" onclick="setDestTab(\'chkid_subgroup\')" /></li>'
	var idgrp='';
	var idtitle='';
	var ul='';
	var ulTag='';
	
	if (l==0){document.getElementById('idDestTab').style.display='none';}
	else
	{
		for (i=0;i<l;i++) 
		{	a=d[i].getElementsByTagName('a');
			idgrp = a[0].id;
//			if (document.getElementById('id'+idgrp))
//			{
//				if (document.getElementById('id'+idgrp).value>0)
//				{
					idtitle = a[0].innerHTML;
					if (idgrp == 'UNCHECKALL')
					    ul = liUncheck;
					else
					    ul=li;
					ul=ul.replace(/id_subgroup/g,idgrp);
					ul=ul.replace(/id_subgrptitle/g,idtitle);
					ulTag=ulTag+ul;
//				}
//			}
		}
		ulTag = '<ul>'+ulTag+'</ul>';
		document.getElementById('idDestTab').innerHTML = ulTag;
	}
}
	
function btnLogin(s)
{
	switch (s)
	{
		case 'in': {document.getElementById('idBtnLogIn').style.display='none';document.getElementById('idBtnLogOut').style.display='';break;}
		default: {document.getElementById('idBtnLogIn').style.display='';document.getElementById('idBtnLogOut').style.display='none';break;}
	}
}
      
function tt(l)
{	var txt='';
	switch (l)
	{
		case 1:
		{ 
			txt='Click on your correct location<br>here to ensure you are viewing<br>the right product, pricing and<br>offer details.'
			break;
		}
		case 2:
		{ 
			txt='Check this box for your computer to <br>remember your geographic region so <br>next time you visit cietours.com you <br>will be directed to the appropriate <br>page.'
			break;
		}
		default:{ break;}
	}
	toolTip(txt);
	if (txt!=''){document.getElementById('idTootTip').style.background='#5168A7';document.getElementById('idTootTip').style.textAlign='left';}
}

function GetElementWidth(e)
{	
    if (typeof(e.innerWidth) == 'number')
    {
        //Non-IE
        return e.innerWidth;
    }
    else if(e.documentElement && (e.documentElement.clientWidth || e.documentElement.clientHeight))
    {
        //IE 6+ in 'standards compliant mode'
        return e.documentElement.clientWidth;
    }
    else if (e && (e.clientWidth || e.clientHeight))
    {
        //IE 4 compatible
        return e.clientWidth;
    }
}

function GetElementHeight(e)
{	
    if (typeof(e.innerWidth) == 'number')
    {
        //Non-IE
        return e.innerHeight;
    }
    else if(e.documentElement && (e.documentElement.clientWidth || e.documentElement.clientHeight))
    {
        //IE 6+ in 'standards compliant mode'
        return e.documentElement.clientHeight;
    }
    else if (e && (e.clientWidth || e.clientHeight))
    {
        //IE 4 compatible
        return e.clientHeight;
    }
}