//By webmaster@shalkith.com

if (document.images) {
   help_off = new Image;
   help_on = new Image;

   help_off.src = "images/help_off.gif";
   help_on.src  = "images/help_on.gif";
}
else {
   help_off = "";
   help_on = "";

   document.help = "";
}

function showDisclaimer(dis){
  var num_dis=1;
  var posy=0;
  var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
  var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1)

  for (var d=0; d<num_dis; d++) {
    if (d==dis) { document.getElementById("disclaimer"+d).style.display="block"; }
	else { document.getElementById("disclaimer"+d).style.display="none"; }
  }
  
  if (!e) var e=window.event;
  if (e)
  
  if (e.pageY) { posy = e.pageY; }
  else if (e.clientY) { 
    posy = e.clientY; 
	if (isIE) { posy += document.body.scrollTop; }
  }

  if (isIE) { var topWindow = posy-360; }
  else {var topWindow = posy;}
  
  if (dis!=-1) { document.getElementById("disclaimer"+dis).style.top=topWindow + "px"; }
}

function showHoard(hoard){
  var num_hoard=33;
  var posy=0;
  var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
  var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1)

  for (var h=0; h<num_hoard; h++) {
    if (h==hoard) { document.getElementById("hoard"+h).style.display="block"; }
	else { document.getElementById("hoard"+h).style.display="none"; }
  }
  
  if (!e) var e=window.event;
  if (e)
  
  if (e.pageY) { posy = e.pageY; }
  else if (e.clientY) { 
    posy = e.clientY; 
	if (isIE) { posy += document.body.scrollTop; }
  }

  if (isIE) { var topWindow = posy-210; }
  else {var topWindow = posy;}
  
  if (hoard!=-1) { document.getElementById("hoard"+hoard).style.top=topWindow + "px"; }
}

function showHelp(help){
  var num_help=30;
  var posy=0;
  var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
  var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1)

  for (var h=0; h<num_help; h++) {
    if (h==help) { document.getElementById("help"+h).style.display="block"; }
	else { document.getElementById("help"+h).style.display="none"; }
  }
  
  if (!e) var e=window.event;
  if (e)
  
  if (e.pageY) { posy = e.pageY; }
  else if (e.clientY) { 
    posy = e.clientY; 
	if (isIE) { posy += document.body.scrollTop; }
  }

  if (isIE) { var topWindow = posy-150; }
  else {var topWindow = posy;}
  
  if (help!=-1) { document.getElementById("help"+help).style.top=topWindow + "px"; }
}

function clearWarn() {
  var num_warn=7;
  for (var w=1; w<=num_warn; w++) { document.getElementById("warn"+w).style.display="none";}
}

function showWarn() {
  clearWarn();
  if (document.hatch.ess.value<document.hatch.bod.value) { document.getElementById("warn1").style.display="block"; }
  else if (document.hatch.ess.value<2 && document.hatch.aura.value>0) { document.getElementById("warn2").style.display="block"; }
  else if (document.hatch.ess.value<3 && document.hatch.tongue.value>0) { document.getElementById("warn3").style.display="block"; }
  else if (document.hatch.ess.value<4 && document.hatch.taunt.value>0) { document.getElementById("warn4").style.display="block"; }
  else if (document.hatch.aura.value<2 && document.hatch.aura.value>0) { document.getElementById("warn5").style.display="block"; }
  else if (document.hatch.advances.value<0) { document.getElementById("warn6").style.display="block"; }
  else if (document.hatch.aura.value>document.hatch.dis.value || (document.hatch.claw1.value>1 && document.hatch.claw1.value>document.hatch.dis.value) || document.hatch.tongue.value>document.hatch.dis.value || document.hatch.taunt.value>document.hatch.dis.value) { document.getElementById("warn7").style.display="block"; }
}


function showMsg(msg) {
  var num_msgs=18;
  for (var m=0; m<num_msgs; m++) {
    if (m==msg) { document.getElementById("msg"+m).style.display="block"; }
	else { document.getElementById("msg"+m).style.display="none"; }
  }
}

function showAvatars() {
  if (document.getElementById("rd_avatar1")) { document.getElementById("rd_avatar1").style.display="inline"; }
  if (document.getElementById("rd_avatar2")) { document.getElementById("rd_avatar2").style.display="inline"; }
  document.hatch.gender[0].checked=true;
  if (document.hatch.breed.length > 1) { document.hatch.breed[0].checked=true; }
  updatePic(0);
}

function hideAvatars(gvalue) {
  if (document.getElementById("rd_avatar1")) { document.getElementById("rd_avatar1").style.display="none"; }
  if (document.getElementById("rd_avatar2")) { document.getElementById("rd_avatar2").style.display="none"; }
  document.hatch.gender[0].checked=true;
  if (gvalue==2) {  document.hatch.breed[1].checked=true; }
  updatePic(0);
}

function showTongue() {
  document.getElementById("tongue").style.display="block";
  document.getElementById("taunt").style.display="none";
  document.hatch.taunt.value=0;
  checkAdv();
}

function showTaunt() {
  document.getElementById("tongue").style.display="none";
  document.getElementById("taunt").style.display="block";
  document.hatch.tongue.value=0;
  checkAdv();
}


function checkDis() {  
  if (document.hatch.breed.length > 1) {
    if (document.hatch.dis.value > 5 && document.hatch.breed[0].checked) {
      document.hatch.dis.value=5;
    }
  }
  else if (document.hatch.dis.value > 5) {
    document.hatch.dis.value=5;
  }
  
  checkAdv();
}

function disableSubmit(form) {
  if (document.all || document.getElementById) {
    for (i=0; i<form.length; i++) {
      var ele = form.elements[i];
      if (ele.type.toLowerCase()=="submit") { ele.disabled = true; }
    }
  }
}

function Feast1Off() { document.acct_option.d1_feast.checked = false; }  
function Feast2Off() { document.acct_option.d2_feast.checked = false; }  
function Feast3Off() { document.acct_option.d3_feast.checked = false; }  
function Feast4Off() { document.acct_option.d4_feast.checked = false; }  
function Mercy1Off() { document.acct_option.d1_mercy.checked = false; }  
function Mercy2Off() { document.acct_option.d2_mercy.checked = false; }  
function Mercy3Off() { document.acct_option.d3_mercy.checked = false; }  
function Mercy4Off() { document.acct_option.d4_mercy.checked = false; }  
  
function limitText(field, count, limit) {
  if (field.value.length > limit) { field.value = field.value.substring(0, limit); } 
  else { count.value = limit - field.value.length; }
}


function submitStage (num) {
  nav.stage.value=num;
}

function sendmail (num) {
  nav.stage.value="s_mail";
  nav.mailid.value=num;
}

function scout (num) {
  nav.stage.value="s_scout";
  nav.mailid.value=num;
}

function verifyNew(form) {
  if(form.email.value=="") {
    alert("Please enter your Email address");
    return false;
  }
  else if(form.rules.checked==false) {
    alert("You must read and agree to the Term of Use");
    return false;
  }
  else return true;
}

function verifyCurrent(form) {
  if(form.email.value=="") {
    alert("Please enter your Email address");
    return false;
  }
  else if(form.password.value=="") {
    alert("Please enter your password");
    return false;
  }
  else return true;
}

function verifyEmail(form) {
  if(form.email.value=="") {
    alert("Please enter your Email address");
    return false;
  }
  else return true;
}

function verifyAccount(form) {
  if(form.os0.value=="") {
    alert("Please enter your Shalkith Account Email");
    return false;
  }
  else { return true; }
}

function verifyChangePW(form) {
  if(form.oldpw.value=="") {
    alert("Please enter your current password");
    return false;
  }
  else if(form.newpw.value=="") {
    alert("Please enter a new password");
    return false;
  }
  else if(form.confirmpw.value=="") {
    alert("Please confirm your new password");
    return false;
  }
  else return true;
}


function updatePic (gvalue) {
  if (document.images) {
     male = new Image;
     female = new Image;
     male2 = new Image;
     female2 = new Image;
	 bl_male = new Image;
	 bl_female = new Image;

     male.src = "images/avatars/med/red_hatchling_m.jpg";
     female.src  = "images/avatars/med/red_hatchling_f.jpg";
     male2.src = "images/avatars/med/red_hatchling2_m.jpg";
     female2.src  = "images/avatars/med/red_hatchling2_f.jpg";
	 bl_male.src = "images/avatars/med/blue_hatchling_m.jpg"; 
	 bl_female.src = "images/avatars/med/blue_hatchling_f.jpg"; 
  }
  else {
     male = "";
     female = "";
     male2 = "";
     female2 = "";
	 bl_male = "";
	 bl_female = "";

     document.dpic = "";
  }

  if (gvalue == -1) {
     document.dpic.src = male.src;
	 clearWarn();
	 showTongue();
  }
  else if (gvalue == 0) {
     if (document.hatch.breed.length > 1) {
       if (document.hatch.breed[0].checked) { document.dpic.src = male.src; }
	   else if (document.hatch.breed[1].checked) {document.dpic.src = bl_male.src; }
	 }
	 else { document.dpic.src = male.src;  }
  }
  else if (gvalue == 1) {
     if (document.hatch.breed.length > 1) {
       if (document.hatch.breed[0].checked) { document.dpic.src = female.src; }
	   else if (document.hatch.breed[1].checked) {document.dpic.src = bl_female.src; }
	 }
	 else { document.dpic.src = female.src;  }
  }
  else if (gvalue == 2) {
    document.dpic.src = male2.src;
  }
  else if (gvalue == 3) {
    document.dpic.src = female2.src;
  }
}

function verifyHatch () {
  if (hatch.claw1.value > 1) {
    if (hatch.claw1.value > hatch.dis.value) {
      alert ("Claw Attack: Your discipline attribute is too low");
      return false;
    }
  }

  if (hatch.aura.value > hatch.dis.value) {
      alert ("Aura Darts: Your discipline attribute is too low");
      return false;
  }

  if (hatch.tongue.value > hatch.dis.value) {
      alert ("Flame Tongue: Your discipline attribute is too low");
      return false;
  }

  if (hatch.taunt.value > hatch.dis.value) {
      alert ("Taunt: Your discipline attribute is too low");
      return false;
  }
  
  if (hatch.advances.value < 0) {
    alert ("You have used more than 8 advances");
    return false;
  }
  else if (hatch.advances.value > 0) {
   alert ("You must use all of your advances");
   return false;
  }
  
  return true;

}

function checkAdv () {  
  var adv = 15;
  adv -= parseFloat (hatch.atk.value);
  adv -= parseFloat (hatch.def.value);
  adv -= parseFloat (hatch.bod.value);
  adv -= parseFloat (hatch.inl.value);
  adv -= parseFloat (hatch.wil.value);
  adv -= parseFloat (hatch.spd.value);
  adv -= parseFloat (hatch.res.value);
  adv -= parseFloat (hatch.ess.value);
  adv -= parseFloat (hatch.dis.value);
  adv -= parseFloat (hatch.lif.value);
  adv -= parseFloat (hatch.claw1.value);
  adv -= parseFloat (hatch.aura.value);
  if (document.hatch.breed.length > 1) {
    if (document.hatch.breed[0].checked) {
      adv -= parseFloat (hatch.tongue.value);	  
	}
	else if (document.hatch.breed[1].checked) {
	  adv -= parseFloat (hatch.taunt.value);	  
	}
  }
  else if (document.hatch.breed.checked) {
    adv -= parseFloat (hatch.tongue.value);
  }

  hatch.advances.value = adv;

  hatch.bash.value = hatch.bod.value;
}

function setDragon () {  
  hatch.def.value=1;
  hatch.inl.value=0;
  hatch.wil.value=0;
  hatch.res.value=0;
  hatch.dis.value=0;
  hatch.aura.value=0;
  hatch.tongue.value=0;
  hatch.taunt.value=0;
  hatch.claw1.value=1;
  hatch.bod.value=1;
  hatch.ess.value=2;
  hatch.atk.value=2;
  hatch.spd.value=2;
  hatch.lif.value=6;
  clearWarn();
  checkAdv();
}

function verifyComment(form) {
  if (form.email.value=="") {
    alert("Please Enter Your Email");
    return false;
  }
  else if (form.contact_txt.value=="") {
    alert("Please Enter A Message");
    return false;
  }
  else return true;
}

function verifyMail(form) {

  if (form.contact_txt.value=="") {
    alert("Please Enter A Message");
    return false;
  }
  else return true;
}

//rankings search
function searchRankings (stage) {
  nav.stage.value=stage;
  nav.submit();
}

//Used when out of sync
function flee () {
  submitStage('s_flee');
  nav.submit();
}

//Used when button pushed
function flee2 () {
  submitStage('s_flee3');
  nav.submit();
}

//Used when button pushed
function set_id (num) {
  nav.yd_id.value = num;
}


function ai_flee () {
  submitStage('s_flee2'); 
  nav.submit();
}

function defeat () {
  submitStage('s_death'); 
  nav.submit();
}

function victory () {
  submitStage('s_win0'); 
  nav.submit();
}

//legendary
function victory2 () {
  submitStage('s_win3'); 
  nav.submit();
}

//new shalkith
function victory3 () {
  submitStage('s_win4'); 
  nav.submit();
}

//shadow
function victory4 () {
  submitStage('s_combat0'); 
  nav.submit();
}

//bloodbath
function victory5 () {
  submitStage('s_combat2'); 
  nav.submit();
}

//yanthas
function elite_yanthas () {
  submitStage('s_win5'); 
  nav.submit();
}

//opearlca
function elite_opearlca () {
  submitStage('s_win6'); 
  nav.submit();
}

//bloodbath score
function bb_score () {
  submitStage('s_score'); 
  nav.submit();
}

function feast () {
  submitStage('s_win1'); 
  nav.submit();
}

function mercy () {
  submitStage('s_win2'); 
  nav.submit();
}

// General DHTML functions
function showLayer (i) {
  resolveLayer('Layer'+i,'','show');
}

function hideLayer (i) {
  resolveLayer('Layer'+i,'','hide');
}

function resolveLayer () {
  var vis, obj, args;

  args=resolveLayer.arguments;
  obj = findObj(args[0]);

  if (obj != null) { 
    vis=args[2];
    if (obj.style) { 
      obj=obj.style;
        if (vis=='show') vis = 'visible';
        if (vis=='hide') vis = 'hidden';
    }
    obj.visibility=vis; 
  }
}

function findObj(layer, doc) {
  var p,i,obj;  

  if(!doc) doc=document; 

  if((p=layer.indexOf("?"))>0&&parent.frames.length) {
    doc=parent.frames[layer.substring(p+1)].document; 
    layer=layer.substring(0,p);
  }
  
  if(!(obj=doc[layer])&&doc.all) obj=doc.all[layer]; 

  for(i=0;!obj&&i<doc.forms.length;i++) obj=doc.forms[i][layer];
 
  for(i=0;!obj&&doc.layers&&i<doc.layers.length;i++) 
  obj=findObj(layer,doc.layers[i].document);
 
  if(!obj && document.getElementById) obj=document.getElementById(layer); 

  return obj;
} 

//Check Div Height
function setTall(page) {
  if (document.getElementById) {
	// the divs array contains references to each column's div element.  
    if (page==0) {
	  var divs = new Array(document.getElementById('profileblock'), document.getElementById('dragonblock'), document.getElementById('content'));
	}
    else if (page==14) {
	  var divs = new Array(document.getElementById('profileblock'), document.getElementById('milestoneblock'), document.getElementById('content'));
	}
    else if (page==10 || page==11 || page==12 || page==13) {
	  var divs = new Array(document.getElementById('profileblock'), document.getElementById('dragonblock'), document.getElementById('content'), document.getElementById('milestoneblock'));
	}
	else if (page==1) {
	  var divs = new Array(document.getElementById('contentblock'), document.getElementById('rankingsblockBB'), document.getElementById('content'));
	}
	else if (page==2) {
  	  var divs = new Array(document.getElementById('contentblock'), document.getElementById('rankingsblockTD'), document.getElementById('content'));
	}
	else if (page==3) {
  	  var divs = new Array(document.getElementById('contentblock'), document.getElementById('rankingsblockSH'), document.getElementById('content'));
	}
	else if (page==4) {
  	  var divs = new Array(document.getElementById('contentblock'), document.getElementById('rankingsblockFD'), document.getElementById('content'));
	}	  
	else if (page==5) {
  	  var divs = new Array(document.getElementById('contentblock'), document.getElementById('rankingsblock'), document.getElementById('content'));
	}	 
	else if (page==6) {
  	  var divs = new Array(document.getElementById('contentblock'), document.getElementById('shopblock'), document.getElementById('content'));
	}
	else if (page==7) {
  	  var divs = new Array(document.getElementById('contentblock'), document.getElementById('accountblock'), document.getElementById('content'));
	}
	else if (page==8) {
  	  var divs = new Array(document.getElementById('contentblock'), document.getElementById('aboutblock'), document.getElementById('content'));
	}	
	else if (page==9) {
  	  var divs = new Array(document.getElementById('contentblock'), document.getElementById('creditsblock'), document.getElementById('content'));
	}		
    // Let's determine the maximum height out of all columns specified
    var maxHeight = 0;
   
		if (page==10) {
			var lairHeight = divs[1].offsetHeight * 1 + divs[3].offsetHeight;
			if (maxHeight < lairHeight) { maxHeight = lairHeight; }
		}
		else if (page==11) {
			var lairHeight = divs[1].offsetHeight * 2 + divs[3].offsetHeight;
			if (maxHeight < lairHeight) { maxHeight = lairHeight; }
		}
		else if (page==12) {
			var lairHeight = divs[1].offsetHeight * 3 + divs[3].offsetHeight;
			if (maxHeight < lairHeight) { maxHeight = lairHeight; }
		}
		else if (page==13) {
			var lairHeight = divs[1].offsetHeight * 4 + divs[3].offsetHeight;
			if (maxHeight < lairHeight) { maxHeight = lairHeight; }
		}		
	

	for (var i = 0; i < divs.length; i++) {
	  if (divs[i].offsetHeight > maxHeight) maxHeight = divs[i].offsetHeight;
	}
	
    if (!isIE()) {
	  rankingsHeight=maxHeight+95;
	  contentHeight=rankingsHeight+35;
	}
	else {
	  rankingsHeight=maxHeight;
	  contentHeight=rankingsHeight+5;
	}
	divs[0].style.height=rankingsHeight + 'px';
	divs[2].style.height=contentHeight + 'px';
  }
}

function isIE() {
  var agt=navigator.userAgent.toLowerCase();
  var appVer = navigator.appVersion.toLowerCase();

  var is_opera = (agt.indexOf("opera") != -1);
  var is_konq = (agt.indexOf("konqueror") != -1);
  var is_mac = (agt.indexOf("mac")!=-1);
  var iePos  = appVer.indexOf('msie');
  var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
  var is_khtml  = (is_safari || is_konq);
  
  var is_ie   = ((iePos!=-1) && (!is_opera) && (!is_khtml));
  return is_ie;
}

function check_browser() {
  // JavaScript Browser Sniffer
  // Original by: Eric Krok, Andy King, Michel Plungjan Jan. 31, 2002
  // See http://www.webreference.com/ for more information
  // Adapted from Netscape's Ultimate client-side JavaScript client sniffer and andy king's sniffer

  // convert all characters to lowercase to simplify testing
  var agt=navigator.userAgent.toLowerCase();
  var appVer = navigator.appVersion.toLowerCase();
  var is_minor = parseFloat(appVer);
  var is_major = parseInt(is_minor);

  var is_opera = (agt.indexOf("opera") != -1);
  var is_konq = (agt.indexOf("konqueror") != -1);

  var is_mac = (agt.indexOf("mac")!=-1);
  var iePos  = appVer.indexOf('msie');
  if (iePos !=-1) {
    if(is_mac) {
      var iePos = agt.indexOf('msie');
      is_minor = parseFloat(agt.substring(iePos+5,agt.indexOf(';',iePos)));
    }
    else is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
    is_major = parseInt(is_minor);
  }

  var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;

  var is_khtml  = (is_safari || is_konq);
  var is_gecko = ((!is_khtml)&&(navigator.product)&&(navigator.product.toLowerCase()=="gecko"))?true:false;
 
  var is_fb = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
              (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
              (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
              (is_gecko) && (navigator.vendor=="Firebird"));
  var is_fx = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
              (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
              (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
              (is_gecko) && ((navigator.vendor=="Firefox")||(agt.indexOf('firefox')!=-1)));
  var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)
                && (!is_khtml) && (!(is_moz)) && (!is_fb) && (!is_fx));

  var is_moz   = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
                 (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
                 (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
                 (is_gecko) && (!is_fb) && (!is_fx) &&
                 ((navigator.vendor=="")||(navigator.vendor=="Mozilla")||(navigator.vendor=="Debian")));
  if ((is_moz)||(is_fb)||(is_fx)) { 
    var is_moz_ver = (navigator.vendorSub)?navigator.vendorSub:0;
    if(is_fx&&!is_moz_ver) {
      is_moz_ver = agt.indexOf('firefox/');
      is_moz_ver = agt.substring(is_moz_ver+8);
      is_moz_ver = parseFloat(is_moz_ver);
    }
    if(!(is_moz_ver)) {
      is_moz_ver = agt.indexOf('rv:');
      is_moz_ver = agt.substring(is_moz_ver+3);
      is_paren   = is_moz_ver.indexOf(')');
      is_moz_ver = is_moz_ver.substring(0,is_paren);
    }
    is_minor = is_moz_ver;
    is_major = parseInt(is_moz_ver);
  }

  if ((navigator.vendor)&&((navigator.vendor=="Netscape6")||(navigator.vendor=="Netscape"))&&(is_nav)) {
    is_major = parseInt(navigator.vendorSub);
    is_minor = parseFloat(navigator.vendorSub);
  }

  //if (is_safari) { is_minor = parseFloat( agt.substring( agt.lastIndexOf('safari/') + 7 ) ); }
  if (is_moz) { is_minor = parseFloat (is_minor.substring(0,3)); }

  var is_nav8   = (is_nav && is_major == 8);
  var is_nav8up = (is_nav && is_minor >= 8);
  var is_ie   = ((iePos!=-1) && (!is_opera) && (!is_khtml));
  var is_ie6   = (is_ie && is_major == 6);
  var is_ie6up = (is_ie && is_minor >= 6);
  var is_moz1_7 = (is_moz && is_minor >=1.7 );
  //var is_safari2_3 = (is_safari && is_minor >= 417.8);

  //if (!is_ie6 && !is_ie6up && !is_nav8 && !is_nav8up && !is_fx && !is_moz1_7) { location=('browser.html'); }
}