// JavaScript Document
/*------------------ DREAMWEAVER FUNCTIONS -------------------*/
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_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_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

/*------------------ INSERT HTML FUNCTIONS -------------------*/

var ns = (document.layers ? true : false);
var ie = (document.all ? true : false);
var gk = (navigator.userAgent.indexOf("Mozilla/5")>=0 ? true : false);

function changeCaption(text) { //change the text and the big image for collections and addition
  status='';
  if (ie) {
        document.all["caption"].innerHTML = text;
    } else if (gk)  {
        document.getElementById("caption").innerHTML = text;
    } else {
        document.layers["caption"].document.open();
        document.layers["caption"].document.writeln(text);
        document.layers["caption"].document.close();
    }
}

/*------------------ MISC FUNCTIONS -------------------*/

function geovisit() {
	return null;
}

function runBGSlideShow(Pic,j){
	
	// Set speed (milliseconds)
	var speed = 9000
	var t
	var p = Pic.length
		
	var preLoad = new Array()
	for (i = 0; i < p; i++){
		preLoad[i] = new Image()
		preLoad[i].src = Pic[i]
	}
	
	document.getElementById('mainTitle').src = Pic[j]
	
	j = j + 1
	if (j > (p-1)) j=0
	t = setTimeout('runBGSlideShow(Pic,'+j+')', speed)

}

function clf(e) { e.value = ""; }
function clearform () {		
	for (var n = 0; n < document.updateForm.elements.length; n++) { 
		field = document.updateForm.elements[n];
		if (field.type == "text") {
			if (field.value.substring(0,5)=="enter" || field.value.substring(0,6)=="please") field.value = "";
		}
	}	
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  //alert('Query Variable ' + variable + ' not found');
}

/*------------------ VISIBILITY FUNCTIONS -------------------*/
//toggle DIV visability
function displayHide (show,action,fade) {
		
	if (action == "hide") {
		if (fade==1) {
			opacity(show, 100, 0, 500);
		} else {
			document.getElementById(show).style.display = 'none';
		}
	} else if (action == "show") {
		document.getElementById(show).style.display = 'block';
		if (fade==1) opacity(show, 0, 100, 600);
	}
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
} 

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}



/*------------------ COOKIE / FLASH / BROWSER DETECTION FUNCTIONS -------------------*/
function browserDetection() {
	var browserType = "ie";
	if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) browserType="opera";
	else if (document.all) browserType="ie";
	else if (document.layers) browserType="ns";
	else if (!document.all && document.getElementById) browserType="mozilla";
	//else browserType = "ie";
	return browserType;
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date()
	exdate.setDate(expiredays)
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate)
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=")
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1 
			c_end=document.cookie.indexOf(";",c_start)
		if (c_end==-1) c_end=document.cookie.length
		return unescape(document.cookie.substring(c_start,c_end))
		} 
	}
	return null
}

function SetCookie(cookieName,cookieValue) 
{ var today = new Date();var expire = new Date();
expire.setTime(today.getTime() + 3600000*24*365);document.cookie=cookieName+"="+escape(cookieValue)+";expires="+expire.toGMTString();}
// moock fpi [f.lash p.layer i.nspector]
// version: 1.3.7
// written by colin moock
// code maintained at: http://www.moock.org/webdesign/flash/detection/moockfpi/
// terms of use posted at: http://www.moock.org/terms/
var requiredVersion=6;var useRedirect=false;var flash2Installed=false;var flash3Installed=false;var flash4Installed=false;var flash5Installed=false;var flash6Installed=false;var flash7Installed=false;var flash8Installed=false;var flash9Installed=false;var maxVersion=9;var actualVersion=0;var hasRightVersion=false;var jsVersion = 1.0;var isIE=(navigator.appVersion.indexOf("MSIE") != -1)?true:false;var isWin=(navigator.appVersion.toLowerCase().indexOf("win") != -1)?true:false;jsVersion = 1.1;
if(isIE && isWin){document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');document.write('on error resume next \n');document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');document.write('flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');document.write('<\/SCR' + 'IPT\> \n');}
function detectFlash() { if (navigator.plugins) {if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]){var isVersion2=navigator.plugins["Shockwave Flash 2.0"]?" 2.0":"";var flashDescription=navigator.plugins["Shockwave Flash"+isVersion2].description;var flashVersion = parseInt(flashDescription.substring(16));flash2Installed=flashVersion==2;flash3Installed=flashVersion==3;flash4Installed=flashVersion==4;flash5Installed=flashVersion==5;flash6Installed=flashVersion==6;flash7Installed=flashVersion==7;flash8Installed=flashVersion==8;flash9Installed=flashVersion>=9;}} for (var i = 2; i <= maxVersion; i++) { if (eval("flash" + i + "Installed") == true) actualVersion = i;} if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion=4;  
   //alert("version detected: " + actualVersion);
  if (actualVersion >= requiredVersion) {hasflash=true;SetCookie("hasflash",true);}
}

var hasflash;
var theCookie=""+document.cookie;var ind=theCookie.indexOf("hasflash"); if (ind==-1) { detectFlash(); } else { hasflash = true; }



/*------------------ SENDSTUDIO FUNCTIONS -------------------*/
// check multi checkboxes based on the name passed in.
function CheckMultiple(name) {
	
	theFrm = document.frmSS;
	for (var i=0; i < theFrm.length; i++) 
	{
		fldObj = theFrm.elements[i];
		var fieldnamecheck=fldObj.name.indexOf(name);
		if (fieldnamecheck != -1) {
			if (fldObj.checked) {
				return true;
			}
		}
	}
	return false;
}


function CheckSS() {
	
	theFrm = document.frmSS;

	hasDot = theFrm.email.value.indexOf(".");
	hasAt = theFrm.email.value.indexOf("@");
	
	if (hasDot == -1 || hasAt == -1)
	{
		alert("Please enter a valid email address.");
		theFrm.email.focus();
		theFrm.email.select();
		return false;
	}

	
	return true;
}

/*------------------ XML FUNCTIONS -------------------*/
// global flag
var isIE = false;

// global request and XML document objects
var req;

// retrieve XML document (reusable generic function);
// parameter is URL string (relative or complete) to
// an .xml file whose Content-Type is a valid XML
// type, such as text/xml; XML source must be from
// same domain as HTML file
function loadXMLDoc(url) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

// handle onreadystatechange event of req object
function processReqChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
			showDetail();
         } else {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
         }
    }
}

// loads chosen XML document
function loadDoc(evt) {
    // equalize W3C/IE event models to get event object
    evt = (evt) ? evt : ((window.event) ? window.event : null);
    if (evt) {
        // equalize W3C/IE models to get event target reference
        var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
        if (elem) {
            try {
                if (elem.selectedIndex > 0) {
                    loadXMLDoc(elem.options[elem.selectedIndex].value);
                }	
            }
            catch(e) {
                var msg = (typeof e == "string") ? e : ((e.message) ? e.message : "Unknown Error");
                alert("Unable to get XML data:\n" + msg);
                return;
            }
        }
    }
}

// retrieve text of an XML document element, including
// elements using namespaces
function getElementTextNS(prefix, local, parentElem, index) {
    var result = "";
    if (prefix && isIE) {
        // IE/Windows way of handling namespaces
        result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
    } else {
        // the namespace versions of this method 
        // (getElementsByTagNameNS()) operate
        // differently in Safari and Mozilla, but both
        // return value with just local name, provided 
        // there aren't conflicts with non-namespace element
        // names
        result = parentElem.getElementsByTagName(local)[index];
    }
    if (result) {
        // get text, accounting for possible
        // whitespace (carriage return) text nodes 
        if (result.childNodes.length > 1) {
            return result.childNodes[1].nodeValue;
        } else {
            return result.firstChild.nodeValue;    		
        }
    } else {
        return "n/a";
    }
}
