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_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 stateCart(theLink)
{ 
    var item=theLink.parentNode.parentNode.getElementsByTagName('input');
    returnValue=false;
	var button;
	for (var j=0; j<item.length; j++)
	{
		button=theLink.parentNode.parentNode.getElementsByTagName('input')[j];
		if(button.value=="Request FREE Travel Guide") returnValue=button.onclick();
	}
	return returnValue;
}



function cart(link,id)
{ 
	var ans;
	if(link.title=="Request FREE Travel Guide")
		ans=makeHttpRequest("/changeCart.php?add="+id, 'changeButton', link, false);
	else
		ans=makeHttpRequest("/changeCart.php?remove="+id, 'changeButton', link, false);
	if(!ans)
		return true;
	return false;	
}

function changeButton(link, returnVal)
{
	if(link.title == "Request FREE Travel Guide" && returnVal=="Added"){
		link.title ="Remove FREE Travel Guide";
		link.innerHTML='<img src="/images/brochure_added.jpg">';
		//link.className="checked";
		numCart++;
	}

	if(link.title=="Remove FREE Travel Guide" && returnVal=="Removed"){
		link.title="Request FREE Travel Guide";
	//	link.innerHTML="Add Brochure to Cart";
	//	link.className="unchecked";	
		link.innerHTML='<img src="/images/add_brochure.jpg">';
		numCart--;
	}

	if(document.all){//thisbrowser="ie" 
		numInCartObj=document.all["numInCart"];
		checkOutFormObj=document.all["checkOutForm"];
	}

	if(!document.all && document.getElementById){//thisbrowser="NN6";
		numInCartObj=document.getElementById("numInCart");
		checkOutFormObj=document.getElementById("checkOutForm");
	}

	if(numCart==0)
		checkOutFormObj.disabled=true;
	else
		checkOutFormObj.disabled=false;

		numInCartObj.style.fontSize = '16pt';
	numInCartObj.innerHTML="<b>"+numCart+"</b>";
	setTimeout("makeCartSmaller();",1000);
}

function makeCartSmaller()
{
	if(document.all)//thisbrowser="ie"
		numInCartObj=document.all["numInCart"];
	if(!document.all && document.getElementById)//thisbrowser="NN6";
		numInCartObj=document.getElementById("numInCart");
	numInCartObj.style.fontSize = '12pt';
}

function makeHttpRequest(url, callback_function, addReturnVal ,return_xml)
{
	var http_request = false;
	http_request=getAjax();

	if (!http_request) {
		//alert('Unfortunatelly you browser doesn\'t support this feature.');
		return false;
	}
	http_request.onreadystatechange = function() {
		if (http_request.readyState == 4) { 
			if (http_request.status == 200) {
				if(callback_function) {
					if(addReturnVal)
						returns='(addReturnVal,';
					else
						returns='(';

					if (return_xml)  
						eval(callback_function + returns+'http_request.responseXML)');
					else 
						eval(callback_function + returns+'http_request.responseText)');
				}
			}
			else 
			{
				//alert('There was a problem with the request.(Code: ' + http_request.status + ')');
				// return false;
			}
		}
	}
	http_request.open('GET', url, true);
	http_request.send(null);
	return true;
}

function getAjax()
{
 var xmlhttp;
 if (window.XMLHttpRequest) // Mozilla, Safari,...
 { 
  xmlhttp = new XMLHttpRequest();
  if (xmlhttp.overrideMimeType) 
   xmlhttp.overrideMimeType('text/html');
//   xmlhttp.overrideMimeType('text/xml');
 } 
 else if (window.ActiveXObject) // IE
 { 
  try 
  {
   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch (e) 
  {
   try 
   {
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   }catch (e) {}
  }
 }            
 return xmlhttp;
}

   function init()
   {
    if(document.all)//thisbrowser="ie"
     checkOutForm=document.all["checkOutForm"];
    if(!document.all && document.getElementById)//thisbrowser="NN6";
     checkOutForm=document.getElementById("checkOutForm");
	if(numCart==0)
     checkOutForm.disabled=true;
    else
     checkOutForm.disabled=false;	
   }
   
  function startMove()
  {
   if(document.all)//thisbrowser="ie"
    nav=document.all["side_container"];
   if(!document.all && document.getElementById)//thisbrowser="NN6";
    nav=document.getElementById("side_container");
   if(document.all)//thisbrowser="ie"
    main1=document.all["main"];
   if(!document.all && document.getElementById)//thisbrowser="NN6";
    main1=document.getElementById("main");
   if(document.all)//thisbrowser="ie"
    spacer=document.all["copterPlacement"];
   if(!document.all && document.getElementById)//thisbrowser="NN6";
    spacer=document.getElementById("copterPlacement");
   //theleft=document.body.clientWidth-parseInt(nav.style.width); 
   theleft=parseInt(spacer.style.left)-2;
   thetop=main1.offsetTop;
   nav.style.cssText="position:absolute;";
   nav.style.cssText="position:absolute; left:"+(parseInt(spacer.offsetLeft)-2)+"px; top:"+thetop+"px; width:175px;";
   windows = Array(makeWindow(nav,thetop, theleft));
   stayOnScreen();

  }
  var windows = Array();
  	function makeWindow(id,startY,startX)
	{ 
	//alert(id.style.cssstyle);
		var el=id;
		if(document.layers)
		el.style=el;
		el.x = startX;
	    el.y = startY;
	    el.startY=startY;
		el.startX=startX
		return el;
	}
	window.stayOnScreen=function ()
	{
	 if (document.documentElement && !document.documentElement.scrollTop)
	  pY=0;
	 if (document.documentElement && document.documentElement.scrollTop)
      pY=document.documentElement.scrollTop;
     else if (document.body && document.body.scrollTop)
	  pY = document.body.scrollTop;
	  var ieType=(typeof window.innerWidth != 'number');
      var docComp=(document.compatMode);
	  var docMod=(docComp && docComp.indexOf("CSS") != -1);
	  var ieRef=(ieType && docMod);
	  if (self.innerWidth)
		winH = self.innerHeight;
	  else if (document.documentElement && document.documentElement.clientWidth)
		winH = document.documentElement.clientHeight;
	  else if (document.body)
		winH = document.body.clientHeight;
	  //winH=(ieRef)?ieRef.clientHeight:window.innerHeight;

	  for(i=0;i<windows.length;i++)
	  { //alert(winH);
	   tempY=winH-windows[i].offsetHeight-10
	   if(tempY>0)
	   {
		if(document.all)//thisbrowser="ie"
         main1=document.all["main"];
        if(!document.all && document.getElementById)//thisbrowser="NN6";
         main1=document.getElementById("main");
	    if(document.all)//thisbrowser="ie"
	     spacer=document.all["copterPlacement"];
     	if(!document.all && document.getElementById)//thisbrowser="NN6";
         spacer=document.getElementById("copterPlacement");

        thetop=main1.offsetTop+6;
		   if(tempY>thetop)
		   	windows[i].startY=thetop;
		   else
		   	windows[i].startY=tempY;
	   }
	  else if(windows[i].startY+windows[i].offsetHeight>winH-10) 
	  	windows[i].startY=winH-windows[i].offsetHeight-10;
	   windows[i].x =parseInt(spacer.offsetLeft)-2;//document.body.clientWidth-parseInt(windows[i].style.width);//-3;
	   windows[i].y += (pY + windows[i].startY - windows[i].y)/15;
	   windows[i].style.left=windows[i].x+"px";
	   windows[i].style.top=windows[i].y+"px";
	  }
	  setTimeout("stayOnScreen()", 10);
	}
  
  	function selectAll(type)
	{
	    var cart=new getObj('cart').obj.rows;
		for (var i=0; i<cart.length; i++)
		{  
		    var item=cart[i].getElementsByTagName('input');
		    for (var j=0; j<item.length; j++)
    		{  
     			if (item[j].value==type)
       			 	item[j].checked=true;
    		}	
		}
	}
	
	function selectAllDownload()
	{ 
		selectAll('download');
	}
	
	function selectAllMail()
	{
		selectAll('mail');
	}
	
	function getObj(name)
	{
	  if (document.getElementById)
	  {
		this.obj=document.getElementById(name);
		this.style=document.getElementById(name).style;
	  }
	  else if (document.all)
	  {
		this.obj=document.all[name];
		this.style=document.all[name].style;
	  }
	  else if (document.layers)
	  {
		this.obj=document.layers[name];
		this.style=document.layers[name];
	  }
	}
	
 function gotoPage(value)
 {
  if(value!=-1)
  {
   z=parseInt(value)+1;
   j=states[z];
   location.href="/FreeTravelBrochures/"+regions[j]+"/#"+states[value];
  }
 }
 
 function checkPasswordMatch(confirmPassword)
 {
		if(document.all)//thisbrowser="ie"
         newPass=document.all["newPassword"];
        if(!document.all && document.getElementById)//thisbrowser="NN6";
         newPass=document.getElementById("newPassword");
		if(document.all)//thisbrowser="ie"
         matchDis=document.all["matchDisplay"];
        if(!document.all && document.getElementById)//thisbrowser="NN6";
         matchDis=document.getElementById("matchDisplay");
		if(newPass.value==confirmPassword) matchDis.innerHTML="<font color=\"#00FF00\">Match!</font>";
		else matchDis.innerHTML="<font color=\"#FF0000\">Don't Match</font>";
 }

function open_window(page,name,width,height) 
{ 
	if(isNaN(width)) width=550;
	if(isNaN(height)) height=500;
	child=window.open(page, name, "width="+width+", height="+height+", scrollbars=yes, menubar=no");
    if (child.opener == null) 
		child.opener = self;
}

function openHelp(page)
{
	open_window('/members/help.php?on='+page,'Help'); 
	return false;
}

function hideMenu(menu,region) 
{ 

 var id,className;
 className=menu.parentNode.className;
 if(className.substr(className.length-3,3)=='sub')
 id=className.substr(className.indexOf(' ')+1);
 else
 id=className+'sub';
 hideTimer[region] = setTimeout('collapse(\"'+id+'\", '+region+');',100);
}

function collapse(id,region)
{ 
  if(document.all)//thisbrowser="ie"
  toRemove=document.all[id];
 if(!document.all && document.getElementById)//thisbrowser="NN6";
  toRemove=document.getElementById(id);
 toRemove.parentNode.removeChild(toRemove);
 isOpened[region]=null;
}

//menus
var hideTimer=Array(null,null,null,null,null);
var isOpened=Array(null,null,null,null,null);;
function showMenu(menu,region,whichWayToOpen)
{ 
 if(isOpened[region]==null)
 {
 	var top,left,cssClass;
 	isOpened[region]=true;
    top=menu.parentNode.parentNode.parentNode.parentNode.parentNode.offsetTop+menu.parentNode.offsetTop;
	if(window.ActiveXObject && whichWayToOpen==0) top+=90; //ie
	if(whichWayToOpen==1) top=top+18;
	left=menu.parentNode.offsetLeft;
	 cssClass=menu.parentNode.className+'sub';	

    var main=document.createElement('div');
    menu.parentNode.parentNode.parentNode.appendChild(main);
	main.style.position='absolute';
	main.style.left=left+"px";
	main.style.width="20%";
	main.style.margin="0px";
	main.style.padding="0px";
	main.setAttribute("id", cssClass)

	 for(var i=0;i<states.length;i+=2)
	 {
		if(states[i+1]==region)
		{
		 stateDisplay=states[i].replace("_"," ");
		 var menuItem=document.createElement('div');
		 main.appendChild(menuItem);
		 menuItem.className=(navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) <= 6?'ieSub':'ffSub')+' '+cssClass;
		 var menuLink=document.createElement('a');
		 menuLink.appendChild(document.createTextNode(stateDisplay));
		 menuItem.appendChild(menuLink);
		 menuLink.setAttribute('href','/FreeTravelBrochures/'+regions[region]+'/#'+states[i]);
		 if(menuLink.addEventListener)
		 {
		  menuLink.addEventListener( 'mouseover', function () {showMenu(this,region,whichWayToOpen) },true );
		  menuLink.addEventListener( 'mouseout', function () {hideMenu(this,region); },true );
		 }
		 else
		 {
		  menuLink.onmouseover=function () {showMenu(this,region,whichWayToOpen) };
		  menuLink.onmouseout=function () {hideMenu(this,region); };
		 }
		 menuLink.style.display="block";
		 if(whichWayToOpen==0)	top-=18;
		}
	 }
	 main.style.top=top+"px";
 }
 if(hideTimer && hideTimer[region]) clearTimeout(hideTimer[region]);
}

function  selectDetailPic(pidid,contract)
{
	if(defaultVal!=pidid)
	{
		if(document.all)//thisbrowser="ie"
		  picture=document.all["pictureDetail"+contract];
		 if(!document.all && document.getElementById)//thisbrowser="NN6";
		  picture=document.getElementById("pictureDetail"+contract);
		 picture.innerHTML='<img src="http://www.travelguidesfree.com/images/brochurePics/'+contract+'/'+pidid+'.jpg" height="190" width="150">';
		 
		if(document.all)//thisbrowser="ie"
		  thumb=document.all["thumb"+pidid];
		 if(!document.all && document.getElementById)//thisbrowser="NN6";
		  thumb=document.getElementById("thumb"+pidid);
		 thumb.className="pictureSelect";
		 
		if(document.all)//thisbrowser="ie"
		  thumb=document.all["thumb"+defaultVal];
		 if(!document.all && document.getElementById)//thisbrowser="NN6";
		  thumb=document.getElementById("thumb"+defaultVal);
		 thumb.className="pictureUnselect";
		 defaultVal=pidid;
	}
}

function thumbBack(contract,oldPicId)
{
	doThumbPic(contract,oldPicId,-1);
}

function thumbForward(contract,oldPicId)
{
	doThumbPic(contract,oldPicId,1);
}

function doThumbPic(contract,oldPicId,direction)
{
	z=0;
	newPicId=null;
	while(!newPicId && picData.length>=z)
	{
		if(picData[z]==contract)
		{ 
			curPos=z+2;
			for(j=0;j<picData[z+1];j++)
			{  
				if(picData[curPos+j]==oldPicId && j+direction<picData[z+1] && j+direction>=0)
				{ 
					newPicId=picData[curPos+j+direction];	
					picPos=j+direction+1;
					totalPics=picData[z+1];
				    j=picData[z+1];
				}
			}			
			z+=picData[z+1]+2;
		}
		else
		 z+=picData[z+1]+2;
	} 
		if(document.all)//thisbrowser="ie"
		  picture=document.all["picture"+contract];
		 if(!document.all && document.getElementById)//thisbrowser="NN6";
		  picture=document.getElementById("picture"+contract);
		 tempId=newPicId+"";
		 if(tempId.substr(0,1)=="t")
			 temp='<img src="http://www.travelguidesfree.com/members/images/tempBanners/'+contract+'/'+tempId.substr(1,tempId.length-1)+'.jpg" height="190" width="150" class="adPic">';
		 else
			 temp='<img src="http://www.travelguidesfree.com/images/brochurePics/'+contract+'/'+newPicId+'.jpg" height="190" width="150" class="adPic">';
		 temp+='<table width="150" cellpadding="0" cellspacing="0" class="thumbPics"><tr><td width="30">';
		 if(picPos!=1)
		  temp+='<a href="javascript:thumbBack('+contract+',\''+newPicId+'\')"><img src="/images/thumb-back-Arrow.gif" alt="Go to the next picture" width="20" height="20" class="thumbPic"></a>';
		 else
		  temp+='&nbsp;';
		 temp+='</td><td align="center">'+picPos+'/'+totalPics+'</td><td width="30">';
		 if(picPos!=totalPics)
		 	temp+='<a href="javascript:thumbForward('+contract+',\''+newPicId+'\')"><img src="/images/thumb-Forward-Arrow.gif" alt="Go to the next picture" width="20" height="20" class="thumbPic"></a>';
		else
		 	temp+='&nbsp;';
		temp+='</td></tr></table>';
		picture.innerHTML=temp;
}

function showPollAns(id)
{
 poll_id=pollInfo[0];
 ans=makeHttpRequest("/changeCart.php?poll="+poll_id+"&choice="+id, 'pollReturns',id, false);
 if(document.all)//thisbrowser="ie"
  pollQ=document.all["pollQuestion"];
 if(!document.all && document.getElementById)//thisbrowser="NN6";
  pollQ=document.getElementById("pollQuestion");
 pollQ.innerHTML="Processing...";
}

function pollReturns(id,returnVal)
{
 if(document.all)//thisbrowser="ie"
  pollQ=document.all["pollQuestion"];
 if(!document.all && document.getElementById)//thisbrowser="NN6";
  pollQ=document.getElementById("pollQuestion");
 output=pollInfo[1]+"<BR>";
 total=0;
 for(i=2;i<pollInfo.length-2;i+=3)
 {
	if(pollInfo[i]==id) pollInfo[i+2]++;
 	total+=pollInfo[i+2];
 }
 for(i=2;i<pollInfo.length-2;i+=3)
 {
	 percent=parseInt((pollInfo[i+2]/total)*100);
	 output+="<div style='height:5px; width:"+(81*(percent/100))+"px; border:1px solid #000000; overflow:hidden; float:left;'><img src='/images/pollPercent.gif' align='middle'></div><div style='font-size:10px; line-height:.7'> "+parseInt((pollInfo[i+2]/total)*100)+"%</div><div class='choice'>"+pollInfo[i+1]+"</div>";
 }
 output+="<input type='submit' value='Next Question' onclick='getNextQ();' class='greyBtn'>";
  pollQ.innerHTML=output;
}

function getNextQ()
{
 ans=makeHttpRequest("/changeCart.php?nextPollQ=true", 'nextQReturn','', false);
}

function nextQReturn(returnVal)
{
	javascript=returnVal.substr(0,returnVal.indexOf('###'));
	output=returnVal.substr(returnVal.indexOf('###')+3);
	if(document.all)//thisbrowser="ie"
     pollQ=document.all["pollQuestion"];
    if(!document.all && document.getElementById)//thisbrowser="NN6";
     pollQ=document.getElementById("pollQuestion");
	if(output=='')
	{
		pollQ.innerHTML="No more polls available.";	
	}
	else
	{
	 pollQ.innerHTML=output;
	 eval(javascript);
	}
//	alert(javascript);
//	alert(output);
}

function makeStateCombo()
{
 document.write("<li><br>Go to: <br> <select onchange=\"gotoPage(this.value)\">");
 document.write("<option value=\"-1\">Select a State<"+"/option>");
 for(i=0;i<states.length;i+=2)
  document.write("<option value=\""+i+"\">"+states[i]+"<"+"/option>");
 document.write("<"+"/select></li>");
}

	function moveGoogleToAnchor(anchorText)
	{
		var divCollection = document.anchors;
		for (var jmk=0; jmk<divCollection.length; jmk++) 
		{ 
			if(divCollection[jmk].name == anchorText)
			{
			
				var temp=divCollection[jmk];
				var divtop=0;
				while(temp.tagName!="BODY")
				{
					divtop+=temp.offsetTop;
					temp=temp.offsetParent;
				}
				if((divtop)>1500) 
				{
					 if(document.all)//thisbrowser="ie"
						googleAd1=document.all["googleAd"];
					 if(!document.all && document.getElementById)//thisbrowser="NN6";
						googleAd1=document.getElementById("googleAd");
					googleAd1.style.display="block";
					googleAd1.style.top=divtop+"px";
					googleAd1.style.left="0px";
					googleAd1.style.paddingLeft="5px";
				}
			}
		}
	}

function open_window1(page,name) { window.open(page, name, "width=520, height=300, scrollbars=no, menubar=no"); return false; }