/***********************************************
* Switch Content script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use. Last updated April 2nd, 2005.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var enablepersist="on" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="no" //Collapse previously open content when opening present? (yes/no)

var contractsymbol='- ' //HTML for contract symbol. For image, use: <img src="whatever.gif">
var expandsymbol='+ ' //HTML for expand symbol.


if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcontent{display:none;}')
document.write('</style>')
}

function getElementbyClass(rootobj, classname){
var temparray=new Array()
var inc=0
for (i=0; i<rootobj.length; i++){
if (rootobj[i].className==classname)
temparray[inc++]=rootobj[i]
}
return temparray
}

function sweeptoggle(ec){
var thestate=(ec=="expand")? "block" : "none"
var inc=0
while (ccollect[inc]){
ccollect[inc].style.display=thestate
inc++
}
revivestatus()
}


function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

function expandcontent(curobj, cid){
var spantags=curobj.getElementsByTagName("SPAN")
var showstateobj=getElementbyClass(spantags, "showstate")
if (ccollect.length>0){
if (collapseprevious=="yes")
contractcontent(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
if (showstateobj.length>0){ //if "showstate" span exists in header
if (collapseprevious=="no")
showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol
else
revivestatus()
}
}
}

function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
}

function revivestatus(){
var inc=0
while (statecollect[inc]){
if (ccollect[inc].style.display=="block")
statecollect[inc].innerHTML=contractsymbol
else
statecollect[inc].innerHTML=expandsymbol
inc++
}
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}

function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
}

document.cookie=window.location.pathname+"="+selectedItem
}

function do_onload(){
uniqueidn=window.location.pathname+"firsttimeload"
var alltags=document.all? document.all : document.getElementsByTagName("*")
ccollect=getElementbyClass(alltags, "switchcontent")
statecollect=getElementbyClass(alltags, "showstate")
if (enablepersist=="on" && ccollect.length>0){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0"
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
if (!firsttimeload)
revivecontent()
}
if (ccollect.length>0 && statecollect.length>0)
revivestatus()
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate

// end switch content

function get_contribute_submit_msg() {
  msg  = "All finished, partner? If you\'ve spent a lot of time on this suggestion,\n";
  msg += "and haven\'t backed up your work, you probably ought to hit CANCEL right now.\n";
  msg += "\n";
  msg += "Then, you can copy all the text you toiled over, and paste it into wordpad, notepad,\n";
  msg += "or some such text editor. That way, if something goes wrong with this form, you\n";
  msg += "won\'t lose all your hard-earned work!\n";
  msg += "\n";
  msg += "Otherwise, click OK to process the form...\n";
  msg += "\n";
  msg += "Cheers!\n";
  msg += "CostaRicaTraveller.com\n";
  
  return msg;
}
function resize(x,y) {
  window.resizeTo(x,y);
}
function maximize() {
  x = screen.width;
  y = screen.height;
  window.resizeTo(x,y);
}
function trapKeyDown(){
  // if user tries to enter a ' or ", refuse
  if(event.keyCode == 222) {
    // oOutput.innerText+="[trap = " + event.keyCode + "]";
    event.returnValue=false;
    alert("Sorry, quote characters are not allowed.");
  }
}
var win=null;
function NewWindow(mypage,myname,w,h,scroll){
  var settings  ='height='+h+','+'width='+w+','+'top =0,'+'left=0,'+'scrollbars=1,'+'resizable=0'+'toolbar=0,menubar=0';
  win=window.open(mypage,myname,settings);
}
// dreamweaver drop menu
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// externalLinks()
// DESCRIPTION: XHTML Strict pop-up links (the standard compliant way)
//
// This function is based on that provided by SitePoint in the article:
// http://www.sitepoint.com/article/standards-compliant-world
// It has been modified to better support the REL attribute, as the original
// function did not allow space seperated values. This one does.
// It has also been extended to show you how you might create sized, positioned
// pop-ups
//
//
// I have included two default values you can use for the REL attribute; as
// follows:
//
// <a href="http://someurl" rel="external">pop-up</a>
// Which acts exactly the same as target=_BLANK used to
//
// <a href="http://someurl" rel="sized">
// this will open a new window 450px by 590px.
//
// You can extend this function by defining your own values for use in the REL
// attribute and defining appropriate actions for that value.
// You can also delete all the comments so it all loads faster ;)
//
// This file provided by Matthew Wilcox, as part of the article 
// 'Popup windows with XHTML Strict' which can be read at:
// http://mattwilcox.net/devblog/5/

function externalLinks() {
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++) 
    {
    // DONT EDIT THESE TWO VARS
    var anchor   = anchors[i];
    var rel      = anchor.getAttribute("rel");

    // VALUES FOR THE rel ATTRIBUTE. YOU CAN DEFINE MORE var's HERE
    var external = /external/;
    var sized    = /sized/;

    // ACTIONS FOR MATCHING rel VALUES

    // what to do if the rel is set to 'external'
    if (anchor.getAttribute("href") &&
        external.test(rel))
          {
          var link = anchor.getAttribute("href");
          anchor.href = "javascript: void window.open('"+link+"')";
          window.status = "";
          }

    // what to do if the rel is set to 'sized'
    if (anchor.getAttribute("href") &&
        sized.test(rel))
          {
          var link = anchor.getAttribute("href");
          anchor.href = "javascript: void window.open('"+link+"','sized','toolbar=1,scrollbars=1,statusbar=1,menubar=1,resizable=1,width=450,height=590')";
          window.status = "";
          }

    }
  }
window.onload = externalLinks;
// END function externalLinks()
