//** Tab Content script- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
//** Last updated: Nov 8th, 06

var enabletabpersistence=0 //enable tab persistence via session only cookies, so selected tab is remembered?

////NO NEED TO EDIT BELOW////////////////////////
var tabcontentIDs=new Object()

function expandcontent(linkobj){
var ulid=linkobj.parentNode.parentNode.id //id of UL element
var ullist=document.getElementById(ulid).getElementsByTagName("li") //get list of LIs corresponding to the tab contents
for (var i=0; i<ullist.length; i++){
ullist[i].className=""  //deselect all tabs
if (typeof tabcontentIDs[ulid][i]!="undefined") //if tab content within this array index exists (exception: More tabs than there are tab contents)
document.getElementById(tabcontentIDs[ulid][i]).style.display="none" //hide all tab contents
}
linkobj.parentNode.className="selected"  //highlight currently clicked on tab
document.getElementById(linkobj.getAttribute("rel")).style.display="block" //expand corresponding tab content
saveselectedtabcontentid(ulid, linkobj.getAttribute("rel"))
}

function expandtab(tabcontentid, tabnumber){ //interface for selecting a tab (plus expand corresponding content)
var thetab=document.getElementById(tabcontentid).getElementsByTagName("a")[tabnumber]
if (thetab.getAttribute("rel"))
expandcontent(thetab)
}

function savetabcontentids(ulid, relattribute){// save ids of tab content divs
if (typeof tabcontentIDs[ulid]=="undefined") //if this array doesn't exist yet
tabcontentIDs[ulid]=new Array()
tabcontentIDs[ulid][tabcontentIDs[ulid].length]=relattribute
}

function saveselectedtabcontentid(ulid, selectedtabid){ //set id of clicked on tab as selected tab id & enter into cookie
if (enabletabpersistence==1) //if persistence feature turned on
createCookie(ulid, selectedtabid)
}

function getullistlinkbyId(ulid, tabcontentid){ //returns a tab link based on the ID of the associated tab content
var ullist=document.getElementById(ulid).getElementsByTagName("li")
for (var i=0; i<ullist.length; i++){
if (ullist[i].getElementsByTagName("a")[0].getAttribute("rel")==tabcontentid){
return ullist[i].getElementsByTagName("a")[0]
break
}
}
}

function initializetabcontent(){
for (var i=0; i<arguments.length; i++){ //loop through passed UL ids
if (enabletabpersistence==0 && readCookie(arguments[i])!="") //clean up cookie if persist=off
createCookie(arguments[i], "")
var clickedontab=readCookie(arguments[i]) //retrieve ID of last clicked on tab from cookie, if any
var ulobj=document.getElementById(arguments[i])
var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
for (var x=0; x<ulist.length; x++){ //loop through each LI element
var ulistlink=ulist[x].getElementsByTagName("a")[0]
if (ulistlink.getAttribute("rel")){
savetabcontentids(arguments[i], ulistlink.getAttribute("rel")) //save id of each tab content as loop runs
ulistlink.onclick=function(){
expandcontent(this)
return false
}
if (ulist[x].className=="selected" && clickedontab=="") //if a tab is set to be selected by default
expandcontent(ulistlink) //auto load currenly selected tab content
}
} //end inner for loop
if (clickedontab!=""){ //if a tab has been previously clicked on per the cookie value
var culistlink=getullistlinkbyId(arguments[i], clickedontab)
if (typeof culistlink!="undefined") //if match found between tabcontent id and rel attribute value
expandcontent(culistlink) //auto load currenly selected tab content
else //else if no match found between tabcontent id and rel attribute value (cookie mis-association)
expandcontent(ulist[0].getElementsByTagName("a")[0]) //just auto load first tab instead
}
} //end outer for loop
}

//***** END OF DYNAMIC DRIVE CODE *****//

//Start of Custom Code (Riot obviously sucks at coding)
createCookie('mid','0','1');
createCookie('top','0','1');
createCookie('bottom','0','1');
createCookie('ilow','0','1');
createCookie('imid','0','1');
createCookie('itop','0','1');
createCookie('custom','0','1');
var loadingprogress=0;
var job=0;
var gender=0;
var hair=1;
var hlocation=0
var viewid=0
var action=0;
var currentDir=0;
var left=0;
var right=0;
var last=0;
var next=0;
var dye=0;
var hdye='';
var currentFrame=0;
var cart='';

function getImage(pImageURL){
    var img = document.createElement('img');
    img.onload = function (evt) {
        document.body.appendChild(img);
    }
    img.src = pImageURL;
    return false;
}


function changeImage(pExistingImageID, pImageURL){
	if(loadingprogress == 1) {
		return false;
	}
    var img = document.createElement('img');
    loadingprogress=1;
    	//Loading indicator
    	document.getElementById('loading').width='220';
    	document.getElementById('loading').height='19';
    	document.getElementById('loading').src='ajax-loader.gif';
    	//Onload runs AFTER the process is finished
   		img.onload = function (evt) {
        document.getElementById(pExistingImageID).src=this.src+'&rand='+randomNumber(9999999);
        document.getElementById(pExistingImageID).width=this.width;
        document.getElementById(pExistingImageID).height=this.height;

        //Loading var
		loadingprogress=0;
		//Reset the loading image
		document.getElementById('loading').src='blank.gif';
    }
    img.onerror = function (evt) {
    	alert("Unable to load the image");
		//Reset the loading image
		document.getElementById('loading').src='blank.gif';
    	loadingprogress=0;
    }
    img.src = pImageURL;

    return false;
}

function subImage(div,g,j,h,v,l,d,a,y,e,b,f,c) {
	a = a || 0;
	y = y || 0;
	e = e || 0;
	b = b || 0;
	if(c != 0 && c != 1 && c != 2 && c != 3 && c != 4)
		c='';
	if(f < 0) f=0;
	currentDir = d;
	currentFrame = f;
	left=currentDir-1;
	right=currentDir+1;
	last=currentFrame-1;
	next=currentFrame+1;
	if(left == -1)
		left=7;
	if(right == 8)
		right=0;
	job=j;
	gender=g;
	hair=h;
	viewid=v;
	hlocation=l;
	action=a;
	if(e > 553 || e < 0)
		e=0;
	if(y == '')
		y=0;
	if(y > 263 || y < 0)
		y=0;
	hdye=y;
	dye=e;
	bg=b;
	cart=c;
	updateDye();
	//alert('http://ro-character-simulator.ratemyserver.net/charsim.php?gender='+g+'&job='+j+'&hair='+h+'&viewid='+v+'&location='+l+'&direction='+d+'&action='+a+'&hdye='+y+'&dye='+e+'&framenum='+f+'&bg='+b);
	changeImage(div,'http://ro-character-simulator.ratemyserver.net/charsim.php?gender='+g+'&job='+j+'&hair='+h+'&viewid='+v+'&location='+l+'&direction='+d+'&action='+a+'&hdye='+y+'&dye='+e+'&framenum='+f+'&bg='+b+'&cart='+c);
	return false;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = 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 c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function randomNumber(max) {
	return randomnumber=Math.floor(Math.random()*(max+1))
}


//Layer Manipulation functions
var browserType;

if (document.layers) {browserType = "nn4"}
if (document.all) {browserType = "ie"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {
   browserType= "gecko"
}

function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function jobImage(g,t) {
	  var ename;
	  var suffix;
	  var img;
	  var anchor;
	  var miscjob,firstjob,secondjob,transjob,specialjob;
	  var miscjobid,firstjobid,secondjobid,transjobid,specialjobid;
	  
	  //Define all the image names
	  miscjob = ["ÃÊº¸ÀÚ","½´ÆÛ³ëºñ½º","ÆäÄÚÆäÄÚ_±â»ç","½ÅÆäÄÚÅ©·ç¼¼ÀÌ´õ","·ÎµåÆäÄÚ","ÆäÄÚÆÈ¶óµò","·é³ªÀÌÆ®»Ú¶ì","±×¸®Æù°¡µå","·¹ÀÎÁ®´Á´ë","¸¶µµ±â¾î"];
	  miscjobid = [0,23,13,21,4014,4022,5006,5014,5015,9997];
	  firstjob = ["°Ë»ç","¸¶¹ý»ç","±Ã¼ö","¼ºÁ÷ÀÚ","»óÀÎ","µµµÏ","´ÑÀÚ","°Ç³Ê","ÅÂ±Ç¼Ò³â"];
	  firstjobid = [1,2,3,4,5,6,25,24,4046];
	  secondjob = ["±â»ç","ÇÁ¸®½ºÆ®","À§Àúµå","Á¦Ã¶°ø","ÇåÅÍ","¾î¼¼½Å","Å©·ç¼¼ÀÌ´õ","¸ùÅ©","¼¼ÀÌÁö","·Î±×","¿¬±Ý¼ú»ç","¹Ùµå","±Ç¼º","¼Ò¿ï¸µÄ¿"];
	  secondjobid = [7,8,9,10,11,12,14,15,16,17,18,19,4047,4049];
	  thirdjob = ["·é³ªÀÌÆ®","¾ÆÅ©ºñ¼ó","¿ö·Ï","¹ÌÄÉ´Ð","·¹ÀÎÁ®","±æ·ÎÆ¾Å©·Î½º","°¡µå","½´¶ó","¼Ò¼­·¯","½¦µµ¿ìÃ¼ÀÌ¼­","Á¦³×¸¯","¹Î½ºÆ®·²"];
	  thirdjobid = [5000,5001,5002,5003,5004,5005,5007,5008,5009,5010,5011,5012];
	  transjob = ["·Îµå³ªÀÌÆ®","ÇÏÀÌÇÁ¸®","ÇÏÀÌÀ§Àúµå","È­ÀÌÆ®½º¹Ì½º","½º³ªÀÌÆÛ","¾î½Ø½ÅÅ©·Î½º","ÆÈ¶óµò","Ã¨ÇÇ¿Â","ÇÁ·ÎÆä¼­","½ºÅäÄ¿","Å©¸®¿¡ÀÌÅÍ","Å¬¶ó¿î"];
	  transjobid = [4008,4009,4010,4011,4012,4013,4015,4016,4017,4018,4019,4020];
	  specialjob = ["¿î¿µÀÚ","¿©¸§","°áÈ¥","»êÅ¸"];
	  specialjobid = [9998,9999,22,26];
	  
	  if(g == 0) {
	  	specialjob[2] = "¿þµù";
	  	secondjob[11] = "¹«Èñ";
	  	secondjobid[11] = "20";
	  	transjob[11] = "Áý½Ã";
	  	transjobid[11] = "4021";
	  	thirdjob[11] = "¿ø´õ·¯";
	  	thirdjobid[11] = "5013";
	  	suffix = "¿©";
	  }
	  else
	  	suffix = "³²";
	  if(t == 0) { ename = "misc_job"; }
	  else if(t == 1) { ename = "first_job"; }
	  else if(t == 2) { ename = "second_job"; }
	  else if(t == 3) { ename = "trans_job"; }
	  else if(t == 4) { ename = "special_job"; }
	  else if(t == 5) { ename = "third_job"; }
	  
	  removechild(ename);
	  
	  var ni = document.getElementById(ename);
	  var path;
	  if(t == 0) {
	  	  for(var i = 0; i <= miscjob.length-1; i++) {
	  		  path = escape(miscjob[i]+'_'+suffix+'.gif');
			  img = document.createElement('img');
			  img.setAttribute('src','images/bodies/'+path);
			  anchor = document.createElement('a');
			  anchor.setAttribute('href','##');
			  (function(i){anchor.onclick = function() { subImage('pH',gender,miscjobid[i],hair,'','',currentDir,action,hdye,dye,bg,currentFrame,cart); }})(i);
			  img.setAttribute('border','0');
			  ni.appendChild(anchor);
			  anchor.appendChild(img);
	  	  }
	  }
	  else if(t == 1) {
	  	  for(var i = 0; i <= firstjob.length-1; i++) {
	  		  path = escape(firstjob[i]+'_'+suffix+'.gif');
			  img = document.createElement('img');
			  img.setAttribute('src','images/bodies/'+path);
			  anchor = document.createElement('a');
			  anchor.setAttribute('href','##');
			  (function(i){anchor.onclick = function() { subImage('pH',gender,firstjobid[i],hair,'','',currentDir,action,hdye,dye,bg,currentFrame,cart); }})(i);
			  img.setAttribute('border','0');
			  ni.appendChild(anchor);
			  anchor.appendChild(img);
	  	  }
	  	  
	  }
	  else if(t == 2) {
	  	  for(var i = 0; i <= secondjob.length-1; i++) {
			  path = escape(secondjob[i]+'_'+suffix+'.gif');
			  img = document.createElement('img');
			  img.setAttribute('src','images/bodies/'+path);
			  anchor = document.createElement('a');
			  anchor.setAttribute('href','##');
			  (function(i){anchor.onclick = function() { subImage('pH',gender,secondjobid[i],hair,'','',currentDir,action,hdye,dye,bg,currentFrame,cart); }})(i);
			  img.setAttribute('border','0');
			  ni.appendChild(anchor);
			  anchor.appendChild(img);
	  	  }
	  }
	  else if(t == 3) {
	  	  for(var i = 0; i <= transjob.length-1; i++) {
	  	  	  path = escape(transjob[i]+'_'+suffix+'.gif');
			  img = document.createElement('img');
			  img.setAttribute('src','images/bodies/'+path);
			  anchor = document.createElement('a');
			  anchor.setAttribute('href','##');
			  (function(i){anchor.onclick = function() { subImage('pH',gender,transjobid[i],hair,'','',currentDir,action,hdye,dye,bg,currentFrame,cart); }})(i);
			  img.setAttribute('border','0');
			  ni.appendChild(anchor);
			  anchor.appendChild(img);
	  	  }
	  }
	  else if(t == 4) {
	  	  for(var i = 0; i <= specialjob.length-1; i++) {
	  	  	  path = escape(specialjob[i]+'_'+suffix+'.gif');
			  img = document.createElement('img');
			  img.setAttribute('src','images/bodies/'+path);
			  anchor = document.createElement('a');
			  anchor.setAttribute('href','##');
			  (function(i){anchor.onclick = function() { subImage('pH',gender,specialjobid[i],hair,'','',currentDir,action,hdye,dye,bg,currentFrame,cart); }})(i);
			  img.setAttribute('border','0');
			  ni.appendChild(anchor);
			  anchor.appendChild(img);
	  	  }
	  }
	  else if(t == 5) {
	  	  for(var i = 0; i <= thirdjob.length-1; i++) {
	  	  	  path = escape(thirdjob[i]+'_'+suffix+'.gif');
			  img = document.createElement('img');
			  img.setAttribute('src','images/bodies/'+path);
			  anchor = document.createElement('a');
			  anchor.setAttribute('href','##');
			  (function(i){anchor.onclick = function() { subImage('pH',gender,thirdjobid[i],hair,'','',currentDir,action,hdye,dye,bg,currentFrame,cart); }})(i);
			  img.setAttribute('border','0');
			  ni.appendChild(anchor);
			  anchor.appendChild(img);
	  	  }
	  }
}

function hairImage(g) {
	  var suffix;
	  var img;
	  var anchor;
	  
	  //Define all the image names
	  if(g == 0)
	  	suffix = "¿©";
	  else
	  	suffix = "³²";
	  
	  removechild('orig_head');
	  removechild('cust1_head');
	  
	  var ni = document.getElementById('orig_head');
	  var path;
	  	  for(var z = 1; z < 26; z++) {
	  	  	  path = escape(z+'_'+suffix+'.gif');
			  img = document.createElement('img');
			  img.setAttribute('src','images/heads/'+path);
			  //img.setAttribute('src','images/about.gif');
			  anchor = document.createElement('a');
			  anchor.setAttribute('href','##');
			  (function(z){anchor.onclick = function() { subImage('pH',gender,job,z,'','',currentDir,action,hdye,dye,bg,currentFrame,cart); }})(z);
			  img.setAttribute('border','0');
			  ni.appendChild(anchor);
			  anchor.appendChild(img);
	  	  }
	  ni = document.getElementById('cust1_head');
	  	  for(var z = 26; z < 46; z++) {
			   //Messed up heads
			  if(g==0 && z == 35)
				continue;
			  else if(g==1 && z == 44)
				continue;
	  	  	  path = escape(z+'_'+suffix+'.gif');
			  img = document.createElement('img');
			  img.setAttribute('src','images/heads/'+path);
			  //img.setAttribute('src','images/about.gif');
			  anchor = document.createElement('a');
			  anchor.setAttribute('href','##');
			  (function(z){anchor.onclick = function() { subImage('pH',gender,job,z,'','',currentDir,action,hdye,dye,bg,currentFrame,cart); }})(z);
			  img.setAttribute('border','0');
			  ni.appendChild(anchor);
			  anchor.appendChild(img);
	  	  }	  
}

function updateDye() {
		  var ni = document.getElementById('hairdye');
		  ni.value = hdye;
	  	  ni = document.getElementById('dyeinput');
	  	  ni.value = dye;
}

function dyeMenu() {
	  var select,option,input;

	  var ni = document.getElementById('dyebox');
	  ni.innerHTML="Hair Dyes<br>";	  

	  //Hair Dyes
	  select = document.createElement('select');
	  select.setAttribute('size','1');
	  select.setAttribute('name','hairdye');
	  select.setAttribute('id','hairdye');
	  select.setAttribute('onchange','subImage(\'pH\',gender,job,hair,\'\',\'\',currentDir,action,parseInt(this.options[selectedIndex].value),dye,bg,currentFrame,cart);');
	  for(var i = 0; i <= 263; i++) {
	  	  option = document.createElement('option');
		  option.value=i;
		  option.innerText=i;
		  option.text=i;
		  select.appendChild(option);
	  }
	  ni.appendChild(select);
	  ni.innerHTML=ni.innerHTML+"<a href=\"#\" OnClick=\"subImage('pH',gender,job,hair,'','',currentDir,action,parseInt(hdye+1),dye,bg,currentFrame,cart); return false;\"><img src=\"images/plus.gif\" border=\"0\"></a><a href=\"#\" OnClick=\"subImage('pH',gender,job,hair,'','',currentDir,action,parseInt(hdye-1),dye,bg,currentFrame,cart); return false;\"><img src=\"images/minus.gif\" border=\"0\"></a>";
	  ni.innerHTML=ni.innerHTML+"<br>Classic Dyes<br>";
	  //Classic Dyes
	  select = document.createElement('select');
	  select.setAttribute('size','1');
	  select.setAttribute('name','classic');
	  for(var i=0; i<=77; i++) {
	  	option = document.createElement('option');
	  	option.value=i;
	  	option.innerText=i;
	  	option.text=i;
	  	select.setAttribute('onchange','subImage(\'pH\',gender,job,hair,\'\',\'\',currentDir,action,hdye,parseInt(this.options[selectedIndex].value),bg,currentFrame,cart);');
	  	select.appendChild(option);
	  }
	  ni.appendChild(select);
	  ni.innerHTML=ni.innerHTML+"<br>Amber's Dyes<br>";
	  //Amber Dragon Dyes
	  select = document.createElement('select');
	  select.setAttribute('size','1');
	  select.setAttribute('name','amber');
	  for(var i=78; i<=303; i++) {
	  	option = document.createElement('option');
	  	option.value=i;
	  	option.innerText=i;
	  	option.text=i;
	  	select.setAttribute('onchange','subImage(\'pH\',gender,job,hair,\'\',\'\',currentDir,action,hdye,parseInt(this.options[selectedIndex].value),bg,currentFrame,cart);');
	  	select.appendChild(option);
	  }
	  ni.appendChild(select);
	  ni.innerHTML=ni.innerHTML+"<br>Looney's Dyes<br>";
	  //Sir Looney Dyes
	  select = document.createElement('select');
	  select.setAttribute('size','1');
	  select.setAttribute('name','looney');
	  for(var i=304; i<=425; i++) {
	  	option = document.createElement('option');
	  	option.value=i;
	  	option.innerText=i;
	  	option.text=i;
	  	select.setAttribute('onchange','subImage(\'pH\',gender,job,hair,\'\',\'\',currentDir,action,hdye,parseInt(this.options[selectedIndex].value),bg,currentFrame,cart);');
	  	select.appendChild(option);
	  }
	  ni.appendChild(select);
	  ni.innerHTML=ni.innerHTML+"<br>Kowai's Dyes<br>";
	  //Sir Kowai Dyes
	  select = document.createElement('select');
	  select.setAttribute('size','1');
	  select.setAttribute('name','kowai');
	  for(var i=426; i<=553; i++) {
	  	option = document.createElement('option');
	  	option.value=i;
	  	option.innerText=i;
	  	option.text=i;
	  	select.setAttribute('onchange','subImage(\'pH\',gender,job,hair,\'\',\'\',currentDir,action,hdye,parseInt(this.options[selectedIndex].value),bg,currentFrame,cart);');
	  	select.appendChild(option);
	  }
	  ni.appendChild(select);
	  ni.innerHTML=ni.innerHTML+"<br>";
	  input = document.createElement('input');
	  input.setAttribute('size','1');
	  input.setAttribute('id','dyeinput');
	  input.setAttribute('type','text');
	  ni.appendChild(input);
	  ni.innerHTML=ni.innerHTML+"<button OnClick=\"subImage('pH',gender,job,hair,'','',currentDir,action,hdye,parseInt(document.getElementById('dyeinput').value),bg,currentFrame,cart);\">Set</button>";
	  ni.innerHTML=ni.innerHTML+"<a href=\"#\" OnClick=\"subImage('pH',gender,job,hair,'','',currentDir,action,hdye,parseInt(dye+1),bg,currentFrame,cart); return false;\"><img src=\"images/plus.gif\" border=\"0\"></a><a href=\"#\" OnClick=\"subImage('pH',gender,job,hair,'','',currentDir,action,hdye,parseInt(dye-1),bg,currentFrame,cart); return false;\"><img src=\"images/minus.gif\" border=\"0\"></a>";
}

function sigAva() {
	  var select,option,input,font,signame,sigfile;

	  var ni = document.getElementById('background');
	  ni.innerHTML="<u>Backgrounds</u>:<br><br>";	  

	  for(var i = 1; i <= 35; i++) {
	  	  ni.innerHTML=ni.innerHTML+"<a href=\"##\" onclick=\"subImage('pH',gender,job,hair,'','',currentDir,action,hdye,dye,"+i+",currentFrame,cart);\"><img src=\"images/bg/thumb_"+i+".jpg\" border=\"1\" style=\"border-style: collapse; color: #FFFFFF;\"></a>&nbsp;";
	  }
	  ni.innerHTML=ni.innerHTML+"<a href=\"##\" onclick=\"subImage('pH',gender,job,hair,'','',currentDir,action,hdye,dye,0,currentFrame,cart);\"<img src=\"blank.gif\" border=\"1\" width=\"24\" height=\"24\" style=\"border-style: collapse; color: #FFFFFF;\"></a>&nbsp;";
	  
	  //Signature
	  ni = document.getElementById('signature');
	  ni.innerHTML=ni.innerHTML+"<center><u>Signatures:</u></center><br>";
	  select = document.createElement('select');
	  select.setAttribute('size','1');
	  select.setAttribute('name','sigfont');
	  select.setAttribute('id','sigfont');
	  font = ["Dummy","28 Days Later","Acid Label","Arial","Birth of a Hero","Blazed","Cheri","Chopin","Christopherhand","Epoxy Rebirth","Final Fantasy","Graffogie","Greenpill","Nosegrind","Riesling","RUFA","Times New Roman"];
	  option = document.createElement('option');
	  option.value=0;
	  option.text="Select a font";
	  option.innerText="Select a font";
	  select.appendChild(option);
	  for(var i = 1; i < font.length; i++) {
	  	  option = document.createElement('option');
		  option.value=i;
		  option.text=font[i];
		  option.innerText=font[i];
		  option.setAttribute('onmouseover','toolTip("<img src=\'fontsample.php?font='+i+'\'>")');
		  option.setAttribute('onmouseout','toolTip()');
		  select.appendChild(option);
	  }
	  ni.appendChild(select);
	  select = document.createElement('select');
	  select.setAttribute('size','1');
	  select.setAttribute('name','sigtype');
	  select.setAttribute('id','sigtype');
	  option = document.createElement('option');
	  option.value=0;
	  option.text="Select a signature";
	  option.innerText="Select a signature";
	  select.appendChild(option);
	  signame = ["Dummy","Rachel","Crusader","Geffen","Hunter","Gates","Summer Break","Crystal","Sin Blow","Fight-o!","Kafra Services"];
	  for(var i = 1; i < signame.length; i++) {
	  	  option = document.createElement('option');
		  option.value=i;
		  option.text=signame[i];
		  option.innerText=signame[i];
		  option.setAttribute('onmouseover','toolTip("<img src=\'images/sigs/Sig_'+i+'.png\'>")');
		  option.setAttribute('onmouseout','toolTip()');
		  select.appendChild(option);
	  }
	  ni.appendChild(select);
	  ni.innerHTML=ni.innerHTML+"<br><br><u>Sig Text:</u>&nbsp; &nbsp;";
	  input = document.createElement('input');
	  input.setAttribute('size','18');
	  input.setAttribute('id','siginput');
	  input.setAttribute('type','text');
	  ni.appendChild(input);

	  select = document.createElement('select');
	  select.setAttribute('size','1');
	  select.setAttribute('name','fontsize');
	  select.setAttribute('id','fontsize');
	  option = document.createElement('option');
	  option.value=0;
	  option.text="Fontsize";
	  option.innerText="Fontsize";
	  select.appendChild(option);
	  for(var i = 1; i <= 25; i++) {
	  	  option = document.createElement('option');
		  option.value=i;
		  option.text=i;
		  option.innerText=i;
		  select.appendChild(option);
	  }
	  ni.appendChild(select);

	  ni.innerHTML=ni.innerHTML+"<br><center><button OnClick=\"window.open('http://ro-character-simulator.ratemyserver.net/sigava.php?gender='+gender+'&job='+job+'&hair='+hair+'&direction='+currentDir+'&action='+action+'&hdye='+hdye+'&dye='+dye+'&framenum='+currentFrame+'&cart='+cart+'&sig='+parseInt(document.getElementById('sigtype').value)+'&text='+document.getElementById('siginput').value+'&font='+document.getElementById('sigfont').value+'&fsize='+document.getElementById('fontsize').value,'Signature','width=500,height=400')\">Generate</button></center>";

	  //Avatars
	  ni.innerHTML=ni.innerHTML+"<br><br><u>Avatar:</u>&nbsp; &nbsp;";
	  ni.innerHTML=ni.innerHTML+"<button OnClick=\"window.open('http://ro-character-simulator.ratemyserver.net/sigava.php?gender='+gender+'&job='+job+'&hair='+hair+'&direction='+currentDir+'&action='+action+'&hdye='+hdye+'&dye='+dye+'&framenum='+currentFrame+'&cart='+cart,'Avatar','width=400,height=300')\">Generate</button><br><br>";


	  //ni.innerHTML=ni.innerHTML+"<br><div id='fontspace'><img id='fH' border='0' src='blank.gif'></div>";

	  
}

function removechild(node)
{
	var cell = document.getElementById(node);

	if ( cell.hasChildNodes() )
	{
	    while ( cell.childNodes.length >= 1 )
	    {
		cell.removeChild( cell.firstChild );       
	    } 
	}
}

function infob(id,newloc) {
	var a;
	var text;
	var templow,tempmid,temptop;
	var old3;
	templow = readCookie('ilow');
	tempmid = readCookie('imid');
	temptop = readCookie('itop');
	hlocation=readCookie('oldlocation');
	old3 = readCookie('old3');
		
	//Using if statement because switch pissed me off
	if(old3 == 768) {
		if(newloc == 512 || newloc == 513) {
			temptop = 0;
		}
		else if(newloc == 256) {
			tempmid = 0;
		}
	}
	else if(old3 == 513) {
		if(newloc == 1) {
			tempmid = 0;
		}
		else if(newloc == 512 || newloc == 768) {
			templow = 0;
		}
	}
	else if(old3 == 257) {
		if(newloc == 1) {
			temptop = 0;
		}
		else if(newloc == 256) {
			templow = 0;
		}
	}

	if(hlocation == 768) {
		if(newloc == 512) {
			temptop = 0;
		}
		else if(newloc == 256) {
			tempmid = 0;
		}
	}
	else if(hlocation == 513) {
		if(newloc == 1) {
			tempmid = 0;
		}
		else if(newloc == 512) {
			templow = 0;
		}
	}
	else if(hlocation == 257) {
		if(newloc == 1) {
			temptop = 0;
		}
		else if(newloc == 256) {
			templow = 0;
		}
	}
	else if(hlocation == 769) {
			if(newloc == 1) {
				temptop = 0;
				tempmid = 0;
			}
			else if(newloc == 256) {
				tempmid = 0;
				templow = 0;
			}
			else if(newloc == 512) {
				temptop = 0;
				templow = 0;
			}
			else if(newloc == 768) {
				templow = 0;
			}
			else if(newloc == 513) {
				temptop =0;
			}
			else if(newloc == 257) {
				tempmid = 0;
			}		
	}
	if(id == 0 && newloc == 0) templow = "null";
	else if(id == 1 && newloc == 0) tempmid = "null";
	else if(id == 2 && newloc == 0) temptop = "null";
	else if(id == 3 && newloc == 0) {
		templow = "null";
		temptop = "null";
		tempmid = "null";
	}

	removechild('infobox');
	var ni = document.getElementById('infobox');
	if((templow > 0 || tempmid > 0 || temptop > 0) && ((templow != null && templow != "null") || (tempmid != null && tempmid != "null") || (temptop != null && temptop !="null"))) {
		text = document.createTextNode('Last Headgear Information');
		a = document.createElement('a');
		a.setAttribute('href','#');
		a.setAttribute('onclick','popItem(' + id + ',1,1);');
		a.appendChild(text);
		ni.appendChild(a);
		ni.appendChild(document.createElement('br'));
	}
	/*if(templow > 0 && (templow != null || templow != "null")) {
		text = document.createTextNode('Lower Headgear Information');
		a = document.createElement('a');
		a.setAttribute('href','#');
		a.setAttribute('onclick','popItem(' + id + ',1,1);');
		a.appendChild(text);
		ni.appendChild(a);
		ni.appendChild(document.createElement('br'));
	}
	if(tempmid > 0 && (tempmid != null || tempmid != "null")) {
		text = document.createTextNode('Middle Headgear Information');
		a = document.createElement('a');
		a.setAttribute('href','#');
		a.setAttribute('onclick','popItem(' + id + ',1,1);');
		a.appendChild(text);
		ni.appendChild(a);
		ni.appendChild(document.createElement('br'));
	}
	if(temptop > 0 && (temptop != null || temptop != "null")) {
		text = document.createTextNode('Upper Headgear Information');
		a = document.createElement('a');
		a.setAttribute('href','#');
		a.setAttribute('onclick','popItem(' + id + ',1,1);');
		a.appendChild(text);
		ni.appendChild(a);
		ni.appendChild(document.createElement('br'));
	}*/


}

function resetall() {
	createCookie('ilow','0','1');
	createCookie('imid','0','1');
	createCookie('itop','0','1');
	createCookie('mid','0','1');
	createCookie('top','0','1');
	createCookie('bottom','0','1');
	createCookie('custom','0','1');
	createCookie('oldlocation','0','1');
	createCookie('old3','0','1');
	job=0;
	hair=1;
	hlocation=0;
	viewid=0;
	action=0;
	left=0;
	right=0;
	currentDir=0;
	currentFrame=0;
	removechild('infobox');
	hairImage(0);
	jobImage(0,0);
	jobImage(0,1);
	jobImage(0,2);
	jobImage(0,3);
	jobImage(0,4);
	jobImage(0,5);
	hdye=0;
	dye=0;
	bg=0;
	cart=0;
	subImage('pH',0,job,hair,'','',0,hdye,dye,bg,currentFrame,'');
}

function reset(a) {
	//0 = Bottom / 1 = Mid / 2 = Top / 3 = Mix
	if(a == 0) {
		createCookie('bottom','0','1');
		createCookie('ilow','0','1');
		subImage('pH',gender,job,hair,-1,0,currentDir,action,hdye,dye,bg,currentFrame);
		
	}
	else if(a == 1) {
		createCookie('mid','0','1');
		createCookie('imid','0','1');
		subImage('pH',gender,job,hair,-512,0,currentDir,action,hdye,dye,bg,currentFrame);
	}
	else if(a == 2) {
		createCookie('top','0','1');
		createCookie('itop','0','1');
		subImage('pH',gender,job,hair,-256,0,currentDir,action,hdye,dye,bg,currentFrame);
	}
	else if(a == 3) {
		createCookie('bottom','0','1');
		createCookie('ilow','0','1');
		createCookie('mid','0','1');
		createCookie('imid','0','1');
		createCookie('top','0','1');
		createCookie('itop','0','1');
		subImage('pH',gender,job,hair,-769,0,currentDir,action,hdye,dye,bg,currentFrame);
	}
	else if(a == 4) {
		createCookie('custom','0','1');
		subImage('pH',gender,job,hair,-9000,0,currentDir,action,hdye,dye,bg,currentFrame);
	}
	infob(a,0);
}

if (document.images) {
    aboutup       = new Image();
    aboutup.src   = "images/emotebubble.gif" ;
    aboutdown     = new Image() ;
    aboutdown.src = "images/about.gif" ;
}
function buttondown( buttonname )
{
    if (document.images) {
      document[ buttonname ].src = eval( buttonname + "down.src" );
    }
}
function buttonup ( buttonname )
{
    if (document.images) {
      document[ buttonname ].src = eval( buttonname + "up.src" );
    }
}

var item_dim = 'top=20, left=100, height=620,width=780, scrollbars=yes,resizable=yes';

// pop win with link intergrated
function popItem(i_id, small, back){
	
	var url = '../item_db.php?item_id=' + i_id + '&small=' + small + '&back=' + back;

	newwindow=window.open(url, 'name', item_dim);
	if (window.focus) {newwindow.focus()}
	try{
		event.returnValue=false; // for IE7
	} catch(exception) {
	}
	return false;

}

///*************TOOLTIPS***************
    var agt=navigator.userAgent.toLowerCase();
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    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));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav6 = (is_nav && (is_major == 5));
    var is_nav6up = (is_nav && (is_major >= 5));
    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    
//tooltip Position
var offsetX = -300;
var offsetY = -200;
var opacity = 100;
var toolTipSTYLE;

function initToolTips(){
  if(document.getElementById){
          toolTipSTYLE = document.getElementById("toolTipLayer").style;
  }
  if(is_ie || is_nav6up)
  {
    toolTipSTYLE.visibility = "visible";
    toolTipSTYLE.display = "none";
    document.onmousemove = moveToMousePos;
  }
}

function moveToMousePos(e)
{
  if(!is_ie){
    x = e.pageX;
    y = e.pageY;
  }else{
    x = event.x + document.body.scrollLeft;
    y = event.y + document.body.scrollTop;
  }

  toolTipSTYLE.left = x + offsetX+'px';
  toolTipSTYLE.top = y + offsetY+'px';
  return true;
}

function toolTip(msg, fg, bg)
{

    
  if(toolTip.arguments.length < 1) // if no arguments are passed then hide the tootip
  {
    if(is_nav4)
        toolTipSTYLE.visibility = "hidden";
    else
        toolTipSTYLE.display = "none";
  }
  else // show
  {
    if(!fg) fg = "#777777";
    if(!bg) bg = "#ffffe5";
    var content = '<table border="0" cellspacing="0" cellpadding="0" class="toolTip"><tr><td bgcolor="' + fg + '">' +
                                  '<table border="0" cellspacing="1" cellpadding="0"<tr><td bgcolor="' + bg + '">'+
                                  '<font face="sans-serif" color="' + fg + '" size="-2">' + msg +
                                  '</font></td></tr></table>'+
                                  '</td></tr></table>';
   if(is_nav4)
    {
      toolTipSTYLE.document.write(content);
      toolTipSTYLE.document.close();
      toolTipSTYLE.visibility = "visible";
    }

    else if(is_ie || is_nav6up)
    {
      document.getElementById("toolTipLayer").innerHTML = content;
      toolTipSTYLE.display='block'
    }
  }
}

/////////// added my yC when moving to subdomain ////////////////
// note: name cannot have space and must be quoted when sent in
function popWin(url, name, dim)
{
	newwindow=window.open(url,name, dim);
	if (window.focus) {newwindow.focus()}
	try{
		event.returnValue=false; // for IE7
	} catch(exception) {
	}
	return false;
}
// pop win with link intergrated
function popItem(i_id, small, back){
	var item_url = 'http://ratemyserver.net/item_db.php?item_id=' + i_id + '&small=' + small + '&back=' + back;
	return popWin(item_url, 'name', item_dim);
}
