ns4 = (document.layers)? true:false
dom = (document.all)? true:false
ie5=navigator.userAgent.indexOf('MSIE 5')>0?true:false;

var collection="";
var styleObj="";
if (dom) {
	collection="all.";
	styleObj=".style";
	}



//**********Makes the Drop-Down Function Work**********
function doSel(obj)
{
   for (i = 1; i < obj.length; i++)
      if (obj[i].selected == true)
        eval(obj[i].value);
}



var lastDiv = "";
function showDiv(divName) {
	// hide last div
	if (lastDiv) {
		document.getElementById(lastDiv).className = "hiddenDiv";
	}
	//if value of the box is not nothing and an object with that name exists, then change the class
	if (divName && document.getElementById(divName)) {
		document.getElementById(divName).className = "visibleDiv";
		lastDiv = divName;
	}
}

//**********Code for the drop-down menu with hidden divs **********


function showHide(vThis)
{
// http://www.javascriptjunkie.com

	vParent = vThis.parentNode;
	vSibling = vParent.nextSibling;
	while (vSibling.nodeType==3) {   // Fix for Mozilla/FireFox Empty Space becomes a TextNode or Something
    	vSibling = vSibling.nextSibling;
  	};
 
	if(vSibling.style.display == "none")
	{
		vThis.src="../graphics/collapse.gif";
		vThis.alt = "Hide";
		vSibling.style.display = "block";
	} else {
		vSibling.style.display = "none";
		vThis.src="../graphics/expand.gif";
		vThis.alt = "Show";
	}
return;
}


//**********popup window size and conditions**********


	// Everything uses this baby
function getObject(obj) {
	var theObj;
	if (typeof obj=="string") {
		theObj= eval("document." + collection + obj + styleObj);
	}
	else {
		theObj=obj;
	}
	return theObj;
}

function show(obj) {
	var theObj=getObject(obj);
	theObj.visibility='visible';
}
	
function hide(obj) {
	var theObj=getObject(obj);
	theObj.visibility='hidden';
}

function moveTo(obj,xL,yL) {
        obj.left = xL;
        obj.top = yL;
}


function popup(path,winName){
	//Ignore winName
	popDialog=window.open(path,'winName',"width=550,height=375,scrollbars=auto,resizable=no,menubar=no,top=10,left=20,marginwidth=0,marginheight=0");
	setTimeout("popDialog.focus()",200);
}

function popup2(path,winName){
	//Ignore winName
	popDialog2=window.open(path,'winName2',"width=550,height=425,scrollbars=auto,resizable=no,menubar=no,top=10,left=10");
	setTimeout("popDialog2.focus()",200);
}

function popup3(path,winName){
	//Ignore winName
	popDialog3=window.open(path,'winName3',"width=400,height=340,scrollbars=yes,resizable=no,menubar=no,top=10,left=30");
	setTimeout("popDialog3.focus()",200);
}

function popup4(path,winName){
	//Ignore winName
	popDialog3=window.open(path,'winName3',"width=550,height=525,scrollbars=auto,resizable=no,menubar=no,top=10,left=30");
	setTimeout("popDialog3.focus()",200);
}

function link_popup(path,winName){
	//Ignore winName
	popDialog4=window.open(path,'winName4',"width=790,height=350,scrollbars=yes,resizable=yes,menubar=yes,top=10,left=30,toolbar=yes,location=yes");
	setTimeout("popDialog4.focus()",200);
}

function med_popup(path,winName){
	//Ignore winName
	popDialog3=window.open(path,'winName',"width=550,height=260,scrollbars=auto,resizable=no,menubar=no,top=10,left=30");
	setTimeout("popDialog3.focus()",200);
}
function medlarge_popup(path,winName){
	//Ignore winName
	popDialog3=window.open(path,'winName3',"width=560,height=350,scrollbars=auto,resizable=no,menubar=no,top=10,left=30");
	setTimeout("popDialog3.focus()",200);
}

function small_popup(path,winName){
	//Ignore winName
	popDialog3=window.open(path,'winName',"width=550,height=225,scrollbars=auto,resizable=no,menubar=no,top=10,left=30");
	setTimeout("popDialog3.focus()",200);
}

function large_popup(path,winName){
	//Ignore winName
	popDialog3=window.open(path,'winName3',"width=550,height=530,scrollbars=auto,resizable=no,menubar=no,top=10,left=30");
	setTimeout("popDialog3.focus()",200);
}
 
function xsmall_popup(path,winName){
	//Ignore winName
	popDialog3=window.open(path,'winName',"width=250,height=200,scrollbars=no,resizable=no,menubar=no,top=10,left=30");
	setTimeout("popDialog3.focus()",200);
}

function largescroll_popup(path,winName){
	//Ignore winName
	popDialog3=window.open(path,'winName3',"width=650,height=500,scrollbars=yes,resizable=no,menubar=no,top=10,left=30");
	setTimeout("popDialog3.focus()",200);
}

function writeTextInput(){
 var size;
 navigator.appName=="Netscape"?size=10:size=16;
 document.write('<form method="get" action="http://search.atomz.com/search/"><input size="'+size+'" name="sp-q"><p><input type=submit value="Submit"><input type=hidden name="sp-a" value="sp1000f8ea"></form>');
}

function writeTextInput1(){
 var size;
 navigator.appName=="Netscape"?size=14:size=14;
 document.write('<table border="0" cellspacing="0" cellpadding="0" style="margin: -3px -10px -3px 0px;"><tr><td><form method="get" action="http://search.atomz.com/search/"><input type="hidden" name="sp_a" value="sp1003890c"><input size="'+size+'" name="sp-q"></td><td><input type="image" value="submit" src="http://www.andamandiscoveries.com/images/button_search.gif" alt="Submit" align="right" width="56" height="24" border="0"><input type="hidden" name="sp_p" value="all"><input type="hidden" name="sp_f" value="ISO-8859-1"></form></td></tr></table>');
}

function writeTextInput2(){
 var size;
 navigator.appName=="Netscape"?size=14:size=14;
 document.write('<table border="0" cellspacing="0" cellpadding="0" style="margin: -3px 0px -3px 0px;"><tr><td><form method="get" action="http://search.atomz.com/search/"><input type="hidden" name="sp_a" value="sp1003890c"><input size="'+size+'" name="sp-q"></td><td><input type="image" value="submit" src="../images/button_search.gif" alt="Submit" align="right" width="56" height="24" border="0"><input type="hidden" name="sp_p" value="all"><input type="hidden" name="sp_f" value="ISO-8859-1"></form></td></tr></table>');
}
         
function writeTextarea(){
 var size;
 navigator.appName=="Netscape"?cols=25:cols=35;
 navigator.appName=="Netscape"?rows=5:rows=5;
 document.write('<textarea rows="'+rows+'" cols="'+cols+'" wrap="virtual"></textarea>');
}


/***********************************************
*Code to make the form functionality work
*Primarily the hidden fields
***********************************************/

/*Check the form fields*/
function formvalid(theForm)
{
  if (theForm.realname.value == "")
  {
    alert("Please enter a value for the \"Name\" field.");
    theForm.realname.focus();
    return (false);
  }
  if (theForm.email.value == "")
  {
    alert("Please enter a value for the \"E-Mail\" field.");
    theForm.email.focus();
    return (false);
  }
  if (theForm.email2.value == "")
  {
    alert("Please enter a value for the \"Confirm E-Mail\" field.");
    theForm.email2.focus();
    return (false);
  }  
  /*if(theForm.email.value != theForm.email2.value)
  {
    alert('The e-mail addresses you provided do not match!');
    return false;
  }
  else
  {
    return true;
  } */
  if (theForm.Age.value == "")
  {
    alert("Please enter a value for the \"Age\" field.");
    theForm.Age.focus();
    return (false);
  }
  if (theForm.Age.value.length > 3)
  {
    alert("Please enter no more than 3 characters in the \"Age\" field.");
    theForm.Age.focus();
    return (false);
  } 
  if (theForm.Phone_Number.value == "")
  {
    alert("Please enter a value for the \"Phone Number\" field.");
    theForm.Phone_Number.focus();
    return (false);
  }
  if (theForm.Contact_Time.value == "")
  {
    alert("Please enter a time when we can call you to in the \"Best time to contact you?\" field.");
    theForm.Contact_Time.focus();
    return (false);
  }
  if (theForm.Terms_and_Conditions.value == "Disagree")
  {
    alert("You must read and agree to the Terms and Conditions to proceed with this request.");
    theForm.Terms_and_Conditions.focus();
    return (false);
  }
   if (theForm.Trip.value == "")
  {
    alert("Please select the trip you'd like to book from the drop-down menu.");
    theForm.Contact_Time.focus();
    return (false);
  }   
  return (true);
}

/*Opens Hidden fields on the Res Form*/
function showMe (it, box) {
  var vis = (box.checked) ? "block" : "none";
  document.getElementById(it).style.display = vis;
}

/*Opens the additional field for "how did you hear?"*/

	function switchinputs(){
		sVal = document.requestform.How_Did_You_Hear.options[document.requestform.How_Did_You_Hear.selectedIndex].value; 

		eArr = document.getElementsByTagName('tr');
		for(var x = 0; x < eArr.length; x++){
			idVal = eArr[x].id.split("-");

			if(idVal[0] == 'toggle'){
				if(idVal[1] == sVal){
					eval("document.getElementById('toggle-" + sVal + "').style.visibility='visible'");
				} else {
					eArr[x].style.visibility = 'hidden';
				}
			}
		}		
	}

	function morph(){
		sVal = document.requestform.How_Did_You_Hear.options[document.requestform.How_Did_You_Hear.selectedIndex].value;

		if(sVal == 'Agent'){
			document.getElementById('morph-td').innerHTML='<p class="required">Tour Agent Name:</p><p class="break"><input type="text" size="30" name="Tour_agent">';
			document.getElementById('morph-tr').style.visibility='visible';} 
			
			else if(sVal == 'Advertisement'){
			document.getElementById('morph-td').innerHTML='<p class="required">Advertisement Source:</p><p class="break"><input type="text" size="30" name="Advertisement_source">';
			document.getElementById('morph-tr').style.visibility='visible';} 

			else if(sVal == 'Brochure'){
			document.getElementById('morph-td').innerHTML='<p class="required">Where did you see our brochure?</b><p class="break"><input type="text" size="30" name="Where_brochure">';
			document.getElementById('morph-tr').style.visibility='visible';} 	
						
			else if(sVal == 'Newspaper_article'){
			document.getElementById('morph-td').innerHTML='<p class="required">Newspaper Name:</p><p class="break"><input type="text" size="30" name="Newspaper_name">';
			document.getElementById('morph-tr').style.visibility='visible';} 
			
			else if(sVal == 'Magazine_article'){
			document.getElementById('morph-td').innerHTML='<p class="required">Magazine Name:</p><p class="break"><input type="text" size="30" name="Magazine_name">';
			document.getElementById('morph-tr').style.visibility='visible';} 
			
			else if(sVal == 'Television'){
			document.getElementById('morph-td').innerHTML='<p class="required">Television Program:</p><p class="break"><input type="text" size="30" name="Television_program">';
			document.getElementById('morph-tr').style.visibility='visible';} 
			
			else if(sVal == 'Internet_search'){
			document.getElementById('morph-td').innerHTML='<p class="required">Keywords used:</p><p class="break"><input type="text" size="30" name="Internet_keywords">';
			document.getElementById('morph-tr').style.visibility='visible';} 
			
			else if(sVal == 'Google_sponsored_link'){
			document.getElementById('morph-td').innerHTML='<p class="required">Keywords used:</p><p class="break"><input type="text" size="30" name="Google_sponsored_keywords">';
			document.getElementById('morph-tr').style.visibility='visible';} 
						
			else if(sVal == 'Website_Referal'){
			document.getElementById('morph-td').innerHTML='<p class="required">Website Name:</p><p class="break"><input type="text" size="30" name="Website_name">';
			document.getElementById('morph-tr').style.visibility='visible';} 			
						
			else if(sVal == 'Blog_Referal'){
			document.getElementById('morph-td').innerHTML='<p class="required">Blog Name:</p><p class="break"><input type="text" size="30" name="Blog_name">';
			document.getElementById('morph-tr').style.visibility='visible';} 	
			
			else if(sVal == 'Friend_or_colleague'){
			document.getElementById('morph-td').innerHTML='<p class="required">Friend or colleague\'s name:</p><p class="break"><input type="text" size="30" name="Friend_colleague_name">';
			document.getElementById('morph-tr').style.visibility='visible';} 
			
			else if(sVal == 'Another_CBT_program'){
			document.getElementById('morph-td').innerHTML='<p class="required">CBT program name:</p><p class="break"><input type="text" size="30" name="CBT_program">';
			document.getElementById('morph-tr').style.visibility='visible';} 
			
			else if(sVal == 'Tradeshow_or_fair'){
			document.getElementById('morph-td').innerHTML='<p class="required">Tradeshow or fair name:</p><p class="break"><input type="text" size="30" name="Tradeshow_fair_name">';
			document.getElementById('morph-tr').style.visibility='visible';} 
			
			else if(sVal == 'Guidebook'){
			document.getElementById('morph-td').innerHTML='<p class="required">Guidebook name:</p><p class="break"><input type="text" size="30" name="Guidebook_name">';
			document.getElementById('morph-tr').style.visibility='visible';} 
			
			else if(sVal == 'Other_source'){
			document.getElementById('morph-td').innerHTML='<p class="required">Please elaborate:</p><p class="break"><TEXTAREA type="text" name="Please_elaborate" rows="3" cols="30" class="input"></TEXTAREA>';
			document.getElementById('morph-tr').style.visibility='visible';}							
	}

