/*Disney's Pirates of the Caribbean Online (c)*/

/* VERSION/ENVIRONMENT SETTINGS */
//PDomain = "apps.pirates.go.com/pirates/v3"
PDomain = "piratesonline.go.com"
PVersion = "v3"
imgPath='http://a.disney.go.com/pirates/online/'+PVersion+'/global/images/';
swfPath='http://a.disney.go.com/pirates/online/'+PVersion+'/global/flash/';


//Begin splash.js
//Begin code found in splash page (welcome)
function buttonPlay(){
  top.window.location='https://'+PDomain+'/index?pageId=createAccount';
}
function button_about_mc(){
  top.window.location='http://'+PDomain+'/#/game_info/about.html';
}
function button_gamepass_mc(){
  top.window.location='https://register.go.com/commerce/InComm/gameCard';
}
function button_trailer_mc(){
  top.window.location='http://'+PDomain+'/#/game_info/video.html?viewTrailer=true';
}
function button_news_mc(){
  top.window.location='http://'+PDomain+'/#/news_blog/currentnews.html';
}
function password_btn(){
  top.window.open('https://register.go.com/global/pirates/recoverPassword','external','');
}
function createAccount_btn(){
  top.window.location='https://'+PDomain+'/index?pageId=createAccount';
}
//End code found in splash page (welcome)
//End splash.js

//Begin code found on layout_default
function runCurrentNewsAjax(){
  var varAtlasIframe=document.getElementById('atlasIframe');
  varAtlasIframe.src="http://switch.atdmt.com/iaction/tgmptc_HomepageCurrentNews_1";
}
function runCongratBasicAjax(){
  var varAtlasIframe=document.getElementById('atlasIframe');
  varAtlasIframe.src="http://switch.atdmt.com/iaction/tgmptc_BasicAccountTrialConfirmation_1";
}
function runCongratUnlimitedAjax(disMem){
  if(disMem == undefined || disMem == "" || disMem == "null") return;
  var varAtlasIframe=document.getElementById('atlasIframe');
  varAtlasIframe.src="http://switch.atdmt.com/iaction/tgmptc_SubscriptionConfirmation_1/v3/ato.pirates/atc1."+disMem;
}
function checkIframe(){
//alert("called Iframe check")
  if(document.iframesfix){
    var windowlocator=new PageLocator("window.location.href", "#");
    document.write("<iframe id='ajaxnav' name='ajaxnav' src='/"+PVersion+"/global/backbutton?hash="+windowlocator.getHash()+"' class='DisplayNone'></iframe>");
  }
}
//End code found on layout_default

//Begin utilities.js
function searchAndReplace(input, stringToFind, stringToInsert){
  var output="";
  var findLen=stringToFind.length;
  while(input.indexOf(stringToFind)>=0){
    var currOffset=input.indexOf(stringToFind);
    output += input.substr(0, currOffset);
    output=output.substr(0, output.length);
    // delete the last char of output
    output=output += stringToInsert;
    input=input.substr((currOffset)+findLen, input.length-1);
  }
  output += input;
  return output;
}
function thisMovie(movieName){
//alert('thisMovie being called ');
  if (navigator.appName.indexOf("Microsoft")!=-1){
    return window[movieName];
  }else{return document[movieName];}
}
function onPurchase(){top.window.location='http://'+piratesDomain+'/pirates/v3/register/finalization';}
function popContest(url){window.open(url,"popContest","width=612,height=816,scrollbars=0,resizable=1");}
function popUp(url, width, height){window.open(url,"popUp","width="+width+",height="+height+",scrollbars=0,resizable=0");}
function popUp2(url, width, height){window.open(url,"popUp","width="+width+",height="+height+",scrollbars=1,resizable=1");}
function reset_form(id){document.getElementById(id).reset();}
function validate_field(id){
  //check if an input field is null or blank
  if(document.getElementById(id).value==null || document.getElementById(id).value==""){return false;}
  else{return true;}
}
function validate_email(email){
  //simple email validation, returns true or false
  return (email.indexOf(".") > 2) && (email.indexOf("@") > 0);
}
function max_chars(max){
  //we need a better way to make this a reusable function
  var textField=document.upload_video_form.description;
  if (max==null || max==''){var max=35 /*max chars allowed*/ }
  if (textField.value.length>max){
    textField.value= textField.value.substring(0,max);
    textField.blur();//alert("You have reached the maximum characters allowed.")
  }
}
function upload_video_validation(){
  submit_form=false;
  no_blank_fields=false;
  valid_email=false;
  terms=false;
  valid_comments=false;
  textField=document.upload_video_form.comments;
  if (textField.value.length>0){
    valid_comments=true;
  }
  if ( valid_comments && validate_field('email') && validate_field('address') &&
  validate_field('city') && validate_field('state') && validate_field('zip') ){
    //if all fields are NOT blank
    no_blank_fields=true;
  }
  eMail=document.getElementById("email");
  if (validate_email(eMail.value)){valid_email=true;}
  else{ /*eMail.focus()*/}
  if (document.upload_video_form.terms.checked==true){terms=true;}
  if (no_blank_fields && valid_email && terms){
    //alert('switch btn:');
    object=document.getElementById('upload_btn_id_off');
    object.style.display='none';
    object=document.getElementById('upload_btn_id_on');
    object.style.display='';
    return true;
  }
  //return submit_form
}
function upload_video_submit_form(){
  //submit form is validation is true
  if ( upload_video_validation()){
    document.forms['upload_video_form'].submit();
  }
}
function upload_video_reset_form(){reset_form('upload_video_form');}
function redirectToPiratesChannel(){
  var xmlHttp;
  try {
    xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
  } catch (e){ // Internet Explorer
    try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e){
      try {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e){
        //alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState==4){
      //alert(xmlHttp.responseText);
      xmlDoc=createXMLParser(xmlHttp.responseText);
      if(xmlDoc.getElementsByTagName("status").length > 0){
        statusValue=xmlDoc.getElementsByTagName("status")[0].childNodes[0].nodeValue;
        //alert("status="+statusValue);
        if(statusValue == "success"){
          if(xmlDoc.getElementsByTagName("url").length > 0){
            url=xmlDoc.getElementsByTagName("url")[0].childNodes[0].nodeValue;
            if(url != undefined && url.indexOf("http:") || url.indexOf("https:")){
              top.window.location=url;
            }
          }
        }else{
	top.window.location="http://disney.go.com/dxd/index.html?channel=96099";
	
	}
      }
    }
  };
  if (isLoggedIn){
	  xmlHttp.open("GET","http://"+PDomain+"/"+PVersion+"/util/rpc/getPiratesChannel?cacheBuster=" + Math.random(), true);
	  xmlHttp.send(null);
  } else {
	top.window.location="http://disney.go.com/dxd/index.html?channel=96099";  
  }
}
var varDisplayLiveSupport="false";
function checkLiveSupport(){
  var xmlHttp;
  try{
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  } catch (e){ // Internet Explorer
    try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e){
      try {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e){
        //alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState==4){
      //alert(xmlHttp.responseText);
      xmlDoc=createXMLParser(xmlHttp.responseText);
      result=xmlDoc.getElementsByTagName("result")[0].childNodes[0].nodeValue;
      if(result != null && result != 'undefined' && result == "success"){
        if(xmlDoc.getElementsByTagName("dayAndTime").length > 0){
          dayAndTime=xmlDoc.getElementsByTagName("dayAndTime")[0].childNodes[0].nodeValue;
          dayAndTimeArray=dayAndTime.split("|");
          params=getURLParams();
          if(params["day"] != undefined && params["hour"] != undefined && params["meridian"] != undefined){
            day=params["day"];
            hour=params["hour"];
            meridian=params["meridian"];
          } else {
            day=dayAndTimeArray[0];
            hour=dayAndTimeArray[1];
            meridian=dayAndTimeArray[2];
          }
          /*
          day="Sat";
          hour="3";
          meridian="PM";
          */
          isSatOrSun=(day.indexOf("Sat") == 0 || day.indexOf("Sun") == 0);
          isWithinTimeSpanSatOrSun=(hour >= 6 && hour <=11 && meridian == "AM") || hour == 12 && meridian == "PM" || (hour >= 1 && hour < 7  && meridian == "PM");
          isMonThruFri=(isSatOrSun != true);
          isWithinTimeSpanMonThruFri=(hour >= 10 && hour <=11 && meridian == "AM") || hour == 12 && meridian == "PM" || (hour >= 1 && hour < 7  && meridian == "PM");
          /*
          alert("isSatOrSun="+isSatOrSun);
          alert("isWithinTimeSpanSatOrSun="+isWithinTimeSpanSatOrSun);
          alert("isMonThruFri="+isMonThruFri);
          alert("isWithinTimeSpanMonThruFri="+isWithinTimeSpanMonThruFri);
          */
          if((isSatOrSun && isWithinTimeSpanSatOrSun) || (isMonThruFri && isWithinTimeSpanMonThruFri)){
            //document.getElementById("liveSupportLink").className="DisplayBlock";
            //document.getElementById("liveSupportLink").style.display="block";//leftnav
            //alert("live support should be on")
            varDisplayLiveSupport="true";
          } else {
            //document.getElementById("liveSupportLink").className="DisplayNone";
            //document.getElementById("liveSupportLink").style.display="none";//leftnav
          }
        }
      }
    }
  };
  var  varURL = "http://"+PDomain+"/"+PVersion+"/util/calendar/dayAndTime?cacheBuster=" + Math.random()
  xmlHttp.open("GET",varURL, true);
  xmlHttp.send(null);
}
function createXMLParser(xText){
  if(typeof DOMParser != "undefined"){
    var parseX=new DOMParser();
    return parseX.parseFromString(xText, "text/xml");
  } else if(typeof ActiveXObject != "undefined"){
    var XMLobj=new ActiveXObject("Microsoft.XMLDOM");
    if(XMLobj){
      XMLobj.async=false;
      XMLobj.loadXML(xText);
      return XMLobj;
    } else {
      //alert("Could not parse XML in IE");
      return false;
    }
  } else {
    //alert("Failed");
    return false;
  }
}
function postProcessor(){
  checkLiveSupport();
  //window.setTimeout("checkLiveSupport()", 5000); // 5 seconds
  window.setInterval("checkLiveSupport()", 60000 * 15); // 60 seconds * 15
  //alert("end post process")
}
function getURLParams(){
  var params=[];
  var strHref=window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString=strHref.substr(strHref.indexOf("?")+1);
    var re=new RegExp("^(.*)?\#.*", "g");
    strQueryString=strQueryString.replace(re, "$1");
    var aQueryString=strQueryString.split("&");
    for ( var iParam=0; iParam < aQueryString.length; iParam++ ){
      var aParam=aQueryString[iParam].split("=");
      params[aParam[0]]=aParam[1];
    }
  }
  return params;
}
function getUsername(){
  if(getcookie("USERNAME") != null && getcookie("USERNAME") != ""){
    return getcookie("USERNAME");
  } else {
    return "Guest";
  }
}
function updateElementTextByElementId(id, newText){
  document.getElementById(id).innerHTML=newText;
}
function setFocus(id){
  document.getElementById(id).focus();
}
var varNavInit=false;
var varNAVURLs_Array=[];
function getNavURLS_Array(){
  thisMovie("leftnav").updateURLSArray(varNAVURLs_Array);

}
function navInit(){
  varNavInit=true;
  setNavSection(document.location.toString());
}

function setNavSection(xURL){

  //alert('xURL: '+xURL+"\n"+'varNavInit: '+varNavInit)
  if (varNavInit && thisMovie("leftnav") != null){
    //alert("varDisplayLiveSupport="+varDisplayLiveSupport)
    thisMovie("leftnav").setSection(xURL, varNAVURLs_Array, varDisplayLiveSupport, isLoggedIn);
  }
}
//End utilities.js

//Begin init.js
function runPageLoaded(){
  if (document.getElementById("adbar") != null || document.getElementById("adbar") != "null"){
  //FRAMEWORK INITIALIZATION
    var varURL=varHBPath+varHBPageName;
	varURL=searchAndReplace(varURL, "v3/content_html","");
	varURL=searchAndReplace(varURL, "content/","");
    var varAdText="<iframe id=\"adIFrame2\" src=\"http://disney.go.com/Adserver?CallDown&AdTypes=Skyscraper;&url=/pirates/mmo"+varURL+"&secure=false\" width=\"160\" height=\"610\" marginwidth=\"0\" marginheight=\"0\" hspace=\"0\" vspace=\"0\" frameborder=\"0\" scrolling=\"no\" bordercolor=\"#000000\"></iframe>";
    document.getElementById("adbar").innerHTML=varAdText;
    setNavSection(document.location.toString());
  }
  //hitbox.Set_hbPageView(varHBPageName, "/pirates/"+varHBPath);
  pageTrack(varHBPageName, "/pirates/"+varHBPath);
  runHBXAlt(varHBPageName,"/pirates/"+varHBPath);
}
var dosTrak_url='http://apps.pirates.go.com/logging/collector.php';
function dosTrak_genAjaxObj(){
  var xmlHttp;
  try{
    xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
  }
  catch (e){// Internet Explorer
    try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
    catch (e){
      try{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
      catch (e){
      //alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  return xmlHttp;
}
function dosTrak_sendData(data){
  var xmlHttp=dosTrak_genAjaxObj();
  if(!xmlHttp){ return; }
  xmlHttp.onreadystatechange=function(){
  //provide a callback function that does nothing
  };
  //alert("navigator.appMinorVersion="+navigator.appMinorVersion)
  var navigator=window.navigator;
  data+="&CodeName="+navigator.appCodeName;
  data+="&MinorVer="+getMinorVersion();
  data+="&appName="+navigator.appName;
  data+="&version="+navigator.appVersion;
  data+="&CookieEnabled="+navigator.cookieEnabled;
  data+="&Platform="+navigator.platform;
  data+="&UA="+navigator.userAgent;
  var n=navigator.userAgent;
  if(/MSIE/.test(n)){
    data+="&CPUClass="+navigator.cpuClass;
    data+="&bLang="+navigator.browserLanguage;
    data+="&sLang="+navigator.systemLanguage;
    data+="&uLang="+navigator.userLanguage;
  }else{
    data+="&bLang="+navigator.language;
  };
  data += "&sid="+Math.random();// bust cache
  if (document.referrer != ''){
    data += "&referer=" + document.referrer;
  }
  /*
  xmlHttp.open("POST",dosTrak_url,true);
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Content-length", data.length);
  xmlHttp.setRequestHeader("Connection", "close");
  xmlHttp.send(data);
  */
}
function getMinorVersion(){
  var varAppVersion=navigator.appVersion.toLowerCase();
  var ua=navigator.userAgent.toLowerCase();
  if(ua.indexOf("sv1") != -1){
  spb=true;
  }else{
  if (ua.indexOf("msie 7") == -1){
    spb=false;
  }else{
    spb=true;
  }
  }
  if (varAppVersion.indexOf("windows")<0){
  return "MAC"
  }
  //alert ("varAppVersion="+varAppVersion)

  var n=navigator.userAgent;
  if(/msie/.test(ua)){

  varOsVersion=varAppVersion.substring(varAppVersion.indexOf("windows")+7, varAppVersion.length);
  }else{
  //alert ("ua="+ua)
  varOsVersion=ua.substring(ua.indexOf("; windows")+10, ua.length);
  varOsVersion=varOsVersion.substring(0, varOsVersion.indexOf(";"));
  }
  //alert ("varOsVersion="+varOsVersion)

  varOsVersionNum=searchAndReplace(varOsVersion,"nt","");
  varOsVersionNum=searchAndReplace(varOsVersionNum," ","");
  varOsVersionNum=parseFloat(varOsVersionNum);

  var varMinorVersion="";
  //alert("varOsVersion="+varOsVersion)
  switch(true){
  //javascript detect xp service pack
  case (varOsVersion.indexOf("nt")<0):

  varMinorVersion="nt";
  break;
  //
  case (varOsVersionNum == 4.1):

  varMinorVersion="win98";
  //alert("we are on win98")
  break;
  //
  case (varOsVersionNum == 4.9):
  varMinorVersion="winME";
  //alert("we are on winME")
  break;
  //
  case (varOsVersionNum == 5):
  //loadContent(varSP1_URL, 'dynamicContent');
  varMinorVersion="win2k";
  //alert("we are on win2k");
  break;
  //
  case (varOsVersionNum == 5.1):
  if (spb == true){
    varMinorVersion="XPSP1";
  }else{
    varMinorVersion="XPSP2";
  }

  break;
  case (varOsVersionNum >= 6 && varOsVersionNum != 98):
  //loadContent(varSP2_URL, 'dynamicContent');
  //window.location=varVista_URL;
  varMinorVersion="VISTA";
  break;
  //
  //case (varOsVersionNum > 5.1):
  //alert("we are on win98")
  //window.location="http://disney.go.com/games/downloads/setup/xpsp1explain.html?retURL="+varRetURL
  //break;
  default:
  //loadContent(varSP2_URL, 'dynamicContent')
  varMinorVersion="XPSP2";
  }
  return varMinorVersion;
}
function dosTrak_trackPage(page, path){
  //alert("tracking page=" + page + "&path=" + path)
  dosTrak_sendData("page=" + page + "&path=" + path);
}
function runHBXAlt(xPage, xPath){
  dosTrak_trackPage(xPage, xPath);
  return;
  var xmlHttp;
  try{
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  } catch (e){ // Internet Explorer
    try {xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
    catch (e){
      try {xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
      catch (e){
        //alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState==4){
      //alert(xmlHttp.responseText);
      if(xmlHttp.responseText == "undefined" || xmlHttp.responseText == ""){
        return;
      }
      //alert("xmlHttp.responseText ="+xmlHttp.responseText )
    }
  };
  var varPOSTPath="http://"+piratesDomain+"/pirates/util/hitbox/getHitboxAlt?page="+escape(xPage)+"&path="+escape(xPath)+"&sid=" + Math.random();
  xmlHttp.open("GET",varPOSTPath, true);
  xmlHttp.send(null);
}
function createXMLParser(xText){
  if(typeof DOMParser != "undefined"){
    var parseX=new DOMParser();
    return parseX.parseFromString(xText, "text/xml");
  } else if(typeof ActiveXObject != "undefined"){
    var XMLobj=new ActiveXObject("Microsoft.XMLDOM");
    if(XMLobj){
      XMLobj.async=false;
      XMLobj.loadXML(xText);
      return XMLobj;
    } else {
      //alert("Could not parse XML in IE");
      return false;
    }
  } else {
    //alert("Failed");
    return false;
  }
}
function putcookie(c_name,value,expiredays){
  var date=new Date();
  date.setTime(date.getTime()+(expiredays*24*60*60*1000));
  document.cookie=c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+date.toGMTString() + ";path=/");
}
function remove_cookie(cookie_name){
  var cookie_date=new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie=cookie_name += "=; expires=" + cookie_date.toGMTString();
}
function getcookie(c_name){

	var nameEQ = c_name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) { 
			return unescape(c.substring(nameEQ.length,c.length));
		}
	}
	return null;
}
/*
08/28 - disabled internation gate temporarily per producer request
potcoInternationalUser=getcookie("POTCO_INTERNATIONAL_USER");
if(potcoInternationalUser == null || potcoInternationalUser == true || potcoInternationalUser == "true"){
  putcookie("POTCO_INTERNATIONAL_BACK_URL", document.location, 1);
  window.location="http://"+piratesDomain+"/pirates/v3/util/internationalUserCheck";
}
*/
// begin redirect the user to https if http
/*
09/06 - disabled https
if(location.href.match(/^http:/)){
  redirectTo=location.href.replace(/http:/, 'https:')
  window.location=redirectTo;
}
*/
// end redirect the user to https if http
// begin platform detection
var platform=navigator.platform.toLowerCase();
var appVersion=navigator.appVersion.toLowerCase();
var userAgent=navigator.userAgent.toLowerCase();
//alert("platform="+platform+" appVersion="+appVersion+" userAgent="+userAgent)
var isMac=platform.indexOf('mac') == 0 || userAgent.indexOf('macintosh') >= 0 || userAgent.indexOf('mac os') >= 0;
var isWindows=platform.indexOf('win32') == 0 || userAgent.indexOf('windows') >= 0;
var isOldWindows=false;
if(isWindows){
  if(
    appVersion.indexOf('windows 95')>=0
    || appVersion.indexOf('windows 98')>=0
    || userAgent.indexOf('win95')>=0
    || userAgent.indexOf('win98')>=0
    || userAgent.indexOf('win 9x')>=0
    || userAgent.indexOf('windows 95')>=0
    || userAgent.indexOf('windows 98')>=0
    || userAgent.indexOf('windows me')>=0
  ){
    isOldWindows=true;
  }
}
if(isMac){
  //window.location='http://disney.go.com/pirates/online/v3/help/mac.html';
} else if(isWindows && isOldWindows){
  window.location='http://disney.go.com/pirates/online/v3/help/minspec.html';
}
// end platform detection
//End init.js

//Begin web analytics
function pageTrack(pn,mlc,account){
  try{
    var pattern=/(\x2Fpirates){1,2}\x2Fv\d\x2F/;
    var omni_sec=mlc.replace(pattern, "");
    omni_sec=omni_sec.replace(/content_html\//, "");
    if (omni_sec.length>0 && omni_sec.substring(omni_sec.length-1)=="/") omni_sec=omni_sec.substring(0, omni_sec.length-1);
    if (omni_sec.length>0){
      omni_sec=omni_sec.replace(/[^\w\/]+/g, "_");  //replace everything that's not alphanumeric or "/"
      omni_sec=omni_sec.toLowerCase().replace(/[\/]/g, ":");  // lowercase and replace "/" with ":"
      omni_sec="website:" + omni_sec;
    } else {
      omni_sec="website";
    }
    var omni_pn=pn.toLowerCase().replace(/.htm[l]?/, "").replace(/[^\w]+/g, "_");

    cto.h.mlc=mlc;
    cto.h.pageName=pn;
    cto.account="piratesonline";
    cto.category="dgame";
    cto.site="pir_onl";
    cto.siteSection=omni_sec;
    cto.pageName=omni_pn;
    cto.contentType="regular";
    cto.property="pir";
    cto.track();
  }
  catch(err){
    /* Use these while developing, comment it out when finish - Viwer don't need to see these stuff */
    //alert("Please update _hbxKey");
    //document.write(mlc + ":" + pn);
  }
}
//End web analytics

//Begin pirates poll 9/18/08
function pollSent(pollName){
  var cookieValue=getcookie("polls");
  var newValue=true;

  if (cookieValue){
    var pollValues=cookieValue.split('|');
    for (var i=0; i<pollValues.length; i++){
      if (pollValues[i] == pollName){
        newValue=false;
      }
    }
  }

  if (newValue){
    if (cookieValue && cookieValue != ""){
      putcookie("polls",cookieValue + "|" +pollName,365);
    } else {
      putcookie("polls",pollName,365);
    }
  }
}
//End pirates poll

function sanitySet(){
  document.cookie="WDIGAGE=1;path=/;domain=.go.com;";
}
function sanityClear(){
  document.cookie="WDIGAGE=0;path=/;domain=.go.com;";
}
function findDomFile(file){
  //find file in the DOM - works for .js and .css
  fileFound=false;
  if (file.indexOf('.js')>=0){
    tag='script';
    attr='src';
  }else if(file.indexOf('.css')>=0){
    tag='link';
    attr='href';
  }else if(file.indexOf('.jpg')>=0 || file.indexOf('.gif')>=0 || file.indexOf('.png')>=0){
    tag='img';
    attr='src';
  }else {return fileFound;}
  //traverse the DOM and search for file backwards
  var allsuspects=document.getElementsByTagName(tag);
  for (var i=allsuspects.length; i>=0; i--){
    if (allsuspects[i] && allsuspects[i].getAttribute(attr)!=null && allsuspects[i].getAttribute(attr).indexOf(file)!=-1){
      fileFound=true;//file found in the DOM
      break;
    }
  }
  return fileFound;
}
function loadJs(file,path){
  jsFound=false;
  var tag='script';
  var attr='src';
  var varScriptPath='';
  if (path=='' || path==null){
    varScriptPath=baseUrlJavascript+'/'+file;
  }else{
    varScriptPath=path+file;
  }
  jsFound=findDomFile(file);
  if (!jsFound){
    //add the file to the DOM if the file was NOT found in the DOM
    var head=document.getElementsByTagName('head')[0];
    var script=document.createElement('script');
    script.type='text/javascript';
    script.src=varScriptPath;
    head.appendChild(script);
  }
}
function loadCss(file,path){
  cssFound=false;
  var tag='link';
  var attr='href';
  cssFound=findDomFile(file);
  if (!cssFound){
    //add the file to the DOM if the file was NOT found in the DOM
    var fileref='';
    var loadedobjects='';
    if (path=='' || path==null){
      file=baseUrlMedia+'/css/'+file;
    }
    fileref=document.createElement("link");
    fileref.setAttribute("rel", "stylesheet");
    fileref.setAttribute("type", "text/css");
    fileref.setAttribute("href", file);
    document.getElementsByTagName("head").item(0).appendChild(fileref);
  }
}
function addPopDisclaimerJs(){
  fileFound=false;
  if (location.protocol=='https'){
    file='https://disney.go.com/features/javascript/featuresGlobalSecure.js';
  }else{
    file='http://a.disney.go.com/features/javascript/featuresGlobal.js';
  }
  fileFound=findDomFile(file);
  if (!fileFound){
    var head= document.getElementsByTagName('head')[0];
    var script= document.createElement('script');
    script.type= 'text/javascript';
    var varScriptPath=file;
    script.src= varScriptPath;
    head.appendChild(script);
  }
}
function backBtnFix(){
  //load js for back button fix
  platform=navigator.platform.toLowerCase();
  userAgent=navigator.userAgent.toLowerCase();
  var isMac=platform.indexOf('mac') == 0 || userAgent.indexOf('macintosh') >= 0 || userAgent.indexOf('mac os') >= 0;
  //alert(userAgent.indexOf("version/3"));
  if(isMac && userAgent.indexOf("safari") != -1 && userAgent.indexOf("version/3") == -1){
    loadJs('backbutton-safari.js');
  }else{
    loadJs('backbutton.js');
  }
}
fileFoundCounter=0;
function loadImg2(file){
  if (fileFoundCounter==0){
    document.write('<div class="preload"><img src="'+file+'" /></div>');
  }
}
function initPotco(){
  html='';
  html+='<div id="prldTxt">Please wait while loading</div>';
  html+='<img id="imgLoading" src="'+imgPath+'sworsdman.gif" width="483" height="58" alt="Loading" border="0" />';
  document.write(html);
}
var maxTime=1;//seconds
var imgLoadCounter=0;
var maxImgLoadCounter=60;//maxTime (seconds) x maxImgLoadCounter (number) = max total seconds until togglePotco()
var bgImg='potcoHdr2.jpg';
function togglePotco(){
  document.getElementById("potcoLoad").style.display="none";
  document.getElementById("potcoLogin").style.display="block";
  document.getElementById("html_rightbar_game_cards").style.display="block";
  if (document.getElementById("html_rightbar_game_mobile"))
    document.getElementById("html_rightbar_game_mobile").style.display="block";
  document.getElementById("nav").style.display="block";
  document.getElementById("navMain").style.display="block";
  document.getElementById("atlastag").style.display="block";
  document.getElementById("esrb").style.display="block";
  document.getElementById("foot").style.display="block";
  bgUrl=imgPath+bgImg;
  document.getElementById("potco_body").style.backgroundImage="url("+bgUrl+")";
}
function checkImgLoad(id){
  imgLoaded=document.getElementById(id).complete;
  if (imgLoaded || (imgLoadCounter >= maxImgLoadCounter)){
    togglePotco();//apply toggle if image has downloaded or if max time reached
  }else{
    imgLoadCounter++;
    //alert('imgLoadCounter: '+imgLoadCounter);
    setTimeout('checkImgLoad("'+id+'")',maxTime*1000);//seconds
  }
}
function initHiddenDivs(){
  loadCss('core.css');
  loadJs('databases/db.js');
  loadJs('databases/news_db.js');
  loadJs('featuresGlobal.js','http://a.disney.go.com/features/javascript/');//pop disclaimer
  initPageType();
  togglePotco();
}
function loadingHtml(){
  html='';
  html+='<div class="preload"><img id="potcoBg" src="'+imgPath+bgImg+'" /></div>';
  html+='<img src="http://a.disney.go.com/pirates/online/v3/global/images/spacer.gif" height="0" width="0" onload="checkImgLoad(\'potcoBg\')">';
  return html;
}