//::: DECLARE GLOBAL VARIABLES :::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::
var arVersion = navigator.appVersion.split("MSIE");
var currentSection = "";
var tmpHTML = "";
var tmpNav = "";

//::: UTLITY FUNCTIONS :::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::
function Browser() {
	var b=navigator.appName;
	if (b=="Netscape") this.b="ns";
	else if ((b=="Opera") || (navigator.userAgent.indexOf("Opera")>0)) this.b = "opera";
	else if (b=="Microsoft Internet Explorer") this.b="ie";
	//* remove for launch
	if (!b) alert('Unidentified browser./nThis browser is not supported,');
	//
	this.version=navigator.appVersion;
	this.v=parseInt(this.version);
	this.ns=(this.b=="ns" && this.v>=4);
	this.ns4=(this.b=="ns" && this.v==4);
	this.ns6=(this.b=="ns" && this.v==5);
	this.ie=(this.b=="ie" && this.v>=4);
	this.ie4=(this.version.indexOf('MSIE 4')>0);
	this.ie5=(this.version.indexOf('MSIE 5')>0);
	this.ie55=(this.version.indexOf('MSIE 5.5')>0);
	this.ie6=(this.version.indexOf('MSIE 6')>0);
	this.opera=(this.b=="opera");
	this.dom=(document.createElement && document.appendChild && document.getElementsByTagName)?true:false;
	this.def=(this.ie||this.dom); // most used browsers, for faster if loops
	var ua=navigator.userAgent.toLowerCase();
	if (ua.indexOf("win")>-1) this.platform="win32";
	else if (ua.indexOf("mac")>-1) this.platform="mac";
	else this.platform="other";
	this.Win=(this.platform=="win32");
}
is = new Browser();

//::: HELPING IE SHOW PNG IMAGES :::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::

function fixPNG(i) {
	if (is.ie55 || is.ie6) {
	var imgID = (i.id) ? "id='" + i.id + "' " : ""
	var imgClass = (i.className) ? "class='" + i.className + "' " : ""
	var imgTitle = (i.title) ? 
		          "title='" + i.title  + "' " : "title='" + i.alt + "' "
	var imgStyle = "display:inline-block;" + i.style.cssText
	var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + i.width 
			+ "px; height:" + i.height 
			+ "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + i.src + "\', sizingMethod='scale');\"></span>"
	i.outerHTML = strNewHTML;
    } else if (is.ie && is.ie5 && !is.ie55) {
		var imgSrc = i.src;
		var imgRoot = imgSrc.split(".");
		i.src = imgRoot[0] + ".gif";
    }
}

//::::::::::::::::::::::::::::::::::::::::::::::

function startCounter(){
	alphaBackgrounds();
	fixPrintLogo();
}

function fixPrintLogo(){
	// if(document.images) document.getElementById("printLogoImg").src = "/images/print/wyju_logo_print.gif";
	if(document.images) document.images[0].src = "/images/print/wyju_logo_print.gif";
}

function fixComments(){
	/*
	if(document.getElementById){
	var expertsBoxes = document.getElementById("expertExcerpts");
	var firstButton = document.getElementById("Discuss_list1_btnFirst2");
	if(expertsBoxes) {
		if(!firstButton){
		expertsBoxes.style.display = "block";
		}
	}	
	}
	*/
}

function alphaBackgrounds(){
	var replaceDiv = document.getElementById("joinDiscussionTopic");
	var topicLinks = document.getElementById("joinDiscussionLinks");
	if(replaceDiv && is.ie && is.Win){
	var bgImagePath = "/images/dynamic/homecurrentdiscussion";
	if ((is.ie55) || (is.ie6) && (document.body.filters)){
		replaceDiv.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+bgImagePath+".png', sizingMethod='scale')";
		replaceDiv.style.backgroundImage = "url('/images/blankpixel.gif')";
	} else {
		replaceDiv.style.backgroundImage = "url('" + bgImagePath + ".gif')";
	}
	}
	if(topicLinks)
	topicLinks.style.display = "block";
	if(replaceDiv)
	replaceDiv.style.display = "block";
	
}

function fadeInSlow(objId,opacity){
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 90) {
      setOpacity(obj, 99);
      //opacity += 5;
      //window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 50);
    }else{
    }
    }
}


//::: SECTION SWITCHING FOR THE ISSUES PAGES :::
//::::::::::::::::::::::::::::::::::::::::::::::

function changeLocalNav() {
	var args = changeLocalNav.arguments;
	var objLink = args[0];
	var objType = typeof(objLink);
	if(objType=="object"){
		var objParent = objLink.parentNode;
	} else {
		var objParent = document.getElementById(objLink);
	}
	var tmp = "";
	if(tmpNav) document.getElementById(tmpNav).innerHTML = tmpHTML;
	deselectNav(objParent);
}

function deselectNav() {
	var args = deselectNav.arguments, tmp = "";
	with(args[0]) {
		tmpNav = getAttribute('id');
		tmpHTML = innerHTML;
		for(i=0;i<childNodes.length;i++) {
			with(childNodes[i]) {
				switch(nodeType) {
					case 1:
						tmp += firstChild.nodeValue;
						break;
					case 3:
						tmp += nodeValue;
						break;
				}
			}
		}
		innerHTML = tmp;
	}
}

function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();

	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
	for(var j=0; j < this.keyValuePairs.length; j++) {
		if(this.keyValuePairs[j].split("=")[0] == s);
		return this.keyValuePairs[j].split("=")[1];
	}
	return false;
	}

	this.getParameters = function() {
	var a = new Array(this.getLength());
	for(var j=0; j < this.keyValuePairs.length; j++) {
		a[j] = this.keyValuePairs[j].split("=")[0];
	}
	return a;
	}
	this.getLength = function() { return this.keyValuePairs.length;}
}

function queryString(key){
	var page = new PageQuery(window.location.search);
	return unescape(page.getValue(key));
}

function displaySection(){
	var q = queryString("s");
	showEnergySection(q);

}

function showEnergySection(objId){
	var tmp = "";
	if(objId !== currentSection){
		if(currentSection) killCurrent(currentSection);
		if(!(document.getElementById(objId))) objId = "sectionDefault";
		document.getElementById(objId).style.display = "block";
		currentSection = objId;
		if(!tmpNav) {
			var elId = "l_" + objId;
			var elObj = document.getElementById(elId);
			deselectNav(elObj);
		}	
	}
}

function showSection(objId){
	objId = objId.split("#");
	if(objId[1] !== currentSection){
		if(!currentSection) currentSection = "sectionDefault";
		killCurrent(currentSection);
	obj = document.getElementById(objId[1]);
	obj.style.display = "block";	
	currentSection = objId[1];
	}
}

function killCurrent(objId){
	obj = document.getElementById(objId);
	obj.style.display = "none";
}


function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
  // IE/Win
  obj.style.filter = "alpha(opacity="+opacity+")";
}


var stopFadeIn;
function fadeIn(objId,opacity){
if (stopFadeIn !== true){
  if (document.getElementById) {
//    fadeCurrent = objId;
    obj = document.getElementById(objId);
    if (opacity <= 90) {
  //    fstopFadeOut();
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 20);
    }else{
  //   fallowFadeOut();
	//something
    }
  }
}
}


var stopFadeOut;
function fadeOut(objId,opacity) {
if (stopFadeOut !== true){
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity >= 5) {
    //	fstopFadeIn();
      setOpacity(obj, opacity);
      opacity -= 20;
      window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 20);
    }else{

    	}    
	//   	fallowFadeIn();
    }
  }
}


// FIX ANCHORS :::::::::::::::::::::
// :::::::::::::::::::::::::::::::::
function fixAnchor(link){
	link.href="javascript:voidLink()";
}

function voidLink(){

}


// CONTENT TOGGLE ::::::::::::::::::
// :::::::::::::::::::::::::::::::::
function toggleContentType() {

}

// CONTACT US PULLDOWN ::::::::::::::::
// ::::::::::::::::::::::::::::::::::::
function checkContactPulldown(selectedValue){
	var emailField = document.getElementById("emailField");
	if(selectedValue == "other"){
	emailField.style.display = "block";
	} else {
	emailField.style.display = "none";
	}
}



// COUNTRY PULLDOWN :::::::::::::::::::
// ::::::::::::::::::::::::::::::::::::
var currentStateSelect = "otherStateSelect";

function checkCountry(country){
	setStateSection(country);
}

function onorgtypechange(orgPulldown){
	setOrgTypeSection(orgPulldown);
}

function onfieldchange(fieldPulldown){
	setFieldSection(fieldPulldown);
}


function killCurrentState(objId){
	obj = document.getElementById(objId);
	obj.style.display = "none";
}

function setStateSection(countryPulldown){
	if(countryPulldown.value == "United States"){
	killCurrentState(currentStateSelect);
	obj = document.getElementById('stateSelect');
	obj.style.display = "block";
	currentStateSelect = "stateSelect";
	} 
	if(countryPulldown.value == "Canada"){
	killCurrentState(currentStateSelect);
	obj = document.getElementById('provinceSelect');
	obj.style.display = "block";
	currentStateSelect = "provinceSelect";	
	}
	if((countryPulldown.value != "United States")&&(countryPulldown.value != "Canada")){
	killCurrentState(currentStateSelect);
	obj = document.getElementById('otherStateSelect');
	obj.style.display = "block";
	currentStateSelect = "otherStateSelect";	
	}
}

function setOrgTypeSection(orgPulldown){
	var orgSpecify = document.getElementById('orgSpecify');
	if(orgPulldown){
		if(orgPulldown.value == "Other"){
		orgSpecify.style.display = ("block");
		}else{
		orgSpecify.style.display = ("none");
		}
	}
}

function setFieldSection(fieldPulldown){
	var fieldSpecify = document.getElementById("fieldSpecify");
	if(fieldPulldown){
		if(fieldPulldown.value == "Other"){
		fieldSpecify.style.display = ("block");
		}else{
		fieldSpecify.style.display = ("none");
		}
	}
}

//This is a helper method to activate any block sections in registration/modify user page
//after a post back
function activateBlockSections(countryPulldownId,orgPulldownId,fieldPulldownId){
	var countryPulldown = document.getElementById(countryPulldownId);
	var orgPulldown = document.getElementById(orgPulldownId);
	var fieldPulldown = document.getElementById(fieldPulldownId);
	
	setStateSection(countryPulldown);
	setOrgTypeSection(orgPulldown);
	setFieldSection(fieldPulldown);	
}


/* FOR REGISTRATION AND MODIFY PULLDOWNS 091805 */
var signupSwitch;

function cleanReg(){
	//TEACHER STUDENT RADIO BUTTONS
	var orgSpecify = document.getElementById("orgSpecify");
	var fieldSpecify = document.getElementById("fieldSpecify");
	var countryPulldown = document.getElementById("Discuss_register1_ddlCountry");
	if(orgSpecify){
	orgSpecify.style.display = ("none");
	fieldSpecify.style.display = ("none");
	var orgPulldown = document.getElementById("Discuss_register1_ddlOrganizationType");
	var fieldPulldown = document.getElementById("Discuss_register1_Field");
	var modorgPulldown = document.getElementById("Modify_register1_ddlOrganizationType");
	var modfieldPulldown = document.getElementById("Modify_register1_Field");	
	if(orgPulldown){
		if(orgPulldown.value == "Other"){
		orgSpecify.style.display = ("block");
		}
	}
	if(modorgPulldown){
		if(modorgPulldown.value == "Other"){
		orgSpecify.style.display = ("block");
		}
	}
	if(fieldPulldown){
		if(fieldPulldown.value == "Other"){
		fieldSpecify.style.display = ("block");
		}
	}
	if(modfieldPulldown){
		if(modfieldPulldown.value == "Other"){
		fieldSpecify.style.display = ("block");
		}
	}
	}
}

/* Clean up login ms js */
function cleanLogin(){
	submitBut = document.getElementById("Discuss_login1_butLogin");
	if(submitBut){
	submitBut.onclick = "";
	}
}


//COOKIES FOR FLASH
/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}
