// NIKAI
// Extra Java 
// @author    Damian Alarcón

var CPUWait = 0;
var INmage = 0;
var INscroll = 0;
var sbipress = 0;
var comboWaitingCall = 0;

ie5=document.all&&document.getElementById&&!browserinfos.match(/Opera/);
ie=document.all&&document.getElementById;
ns6=document.getElementById&&!document.all || browserinfos.match(/Opera/);
rmbcookie = document.cookie;
base_menu = "";

// PNG Fix
if(navigator.userAgent.toLowerCase().indexOf('msie')>0){
	is = document.getElementsByTagName('IMG');
	for(x=0; x<is.length; x++){
		if(is[x].src.indexOf('.png')){
			is[x].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+is[x].src+"', sizingMethod='scale')";
			is[x].src = e107_var_image_url+"baseimg/z.gif";
		}
	}
}

// -------------------------------------------------------------------
// DHTML Window Widget- By Dynamic Drive, available at: http://www.dynamicdrive.com
// v1.0: Script created Feb 15th, 07'
// v1.01: Updated to v1.01 Feb 21th, 07'
// -------------------------------------------------------------------

var dhtmlwindow={

imagefiles:[e107_var_image_url+'popup/min.gif', e107_var_image_url+'popup/close.gif', e107_var_image_url+'popup/restore.gif', e107_var_image_url+'popup/resize.gif'], //Path to 4 images used by script, in that order
ajaxbustcache: true, //Bust caching when fetching a file via Ajax?

minimizeorder: 0,
tobjects: [], //object to contain references to dhtml window divs, for cleanup purposes

init:function(t){
	var domwindow=document.createElement("div"); //create dhtml window div
	domwindow.id=t;
	domwindow.className="dhtmlwindow";
	var domwindowdata='';
	domwindowdata='<div class="drag-handle">';
	domwindowdata+='DHTML Window <div class="drag-controls"><img src="'+this.imagefiles[0]+'" title="Minimize" /><img src="'+this.imagefiles[1]+'" title="Close" /></div>';
	domwindowdata+='</div>';
	domwindowdata+='<div class="drag-contentarea"></div>';
	domwindowdata+='<div class="drag-statusarea"><div class="drag-resizearea" style="background: transparent url('+this.imagefiles[3]+') top right no-repeat;">&nbsp;</div></div>';
	domwindowdata+='</div>';
	domwindow.innerHTML=domwindowdata;
	document.getElementById("dhtmlwindowholder").appendChild(domwindow);
	this.zIndexvalue=(this.zIndexvalue)? this.zIndexvalue+1 : 100; //z-index value for DHTML window: starts at 0, increments whenever a window has focus
	var t=document.getElementById(t);
	var divs=t.getElementsByTagName("div");
	for (var i=0; i<divs.length; i++){ //go through divs inside dhtml window and extract all those with class="drag-" prefix
		if (/drag-/.test(divs[i].className))
		{
			t[divs[i].className.replace(/drag-/, "")]=divs[i]; //take out the "drag-" prefix for shorter access by name
		}
	}
	t.style.zIndex=this.zIndexvalue; //set z-index of this dhtml window
	t.handle._parent=t; //store back reference to dhtml window
	t.resizearea._parent=t; //same
	t.controls._parent=t; //same
	t.onclose=function(){return true;} //custom event handler "onclose"
	t.onmousedown=function(){dhtmlwindow.zIndexvalue++; this.style.zIndex=dhtmlwindow.zIndexvalue;} //Increase z-index of window when focus is on it
	t.handle.onmousedown=dhtmlwindow.setupdrag; //set up drag behavior when mouse down on handle div
	t.resizearea.onmousedown=dhtmlwindow.setupdrag; //set up drag behavior when mouse down on resize div
	t.controls.onclick=dhtmlwindow.enablecontrols;
	t.show=function(){dhtmlwindow.show(this);} //public function for showing dhtml window
	t.hide=function(){dhtmlwindow.close(this);} //public function for hiding dhtml window
	t.setSize=function(w, h){dhtmlwindow.setSize(this, w, h);} //public function for setting window dimensions
	t.moveTo=function(x, y){dhtmlwindow.moveTo(this, x, y);} //public function for moving dhtml window (relative to viewpoint)
	t.isResize=function(bol){dhtmlwindow.isResize(this, bol);} //public function for specifying if window is resizable
	t.isScrolling=function(bol){dhtmlwindow.isScrolling(this, bol);} //public function for specifying if window content contains scrollbars
	t.load=function(contenttype, contentsource, title){dhtmlwindow.load(this, contenttype, contentsource, title);} //public function for loading content into window
	this.tobjects[this.tobjects.length]=t;
	return t; //return reference to dhtml window div
},

open:function(t, contenttype, contentsource, title, attr, recalonload){
	var d=dhtmlwindow; //reference dhtml window object
	function getValue(Name){
		var config=new RegExp(Name+"=([^,]+)", "i"); //get name/value config pair (ie: width=400px,)
		return (config.test(attr))? parseInt(RegExp.$1) : 0; //return value portion (int), or 0 (false) if none found
	}
	if (document.getElementById(t)==null){ //if window doesn't exist yet, create it
		t=this.init(t) //return reference to dhtml window div;
	}else{
		t=document.getElementById(t);
	}
	t.setSize(getValue(("width")), (getValue("height"))); //Set dimensions of window
	var xpos=getValue("center")? "middle" : getValue("left"); //Get x coord of window
	var ypos=getValue("center")? "middle" : getValue("top"); //Get y coord of window
	t.moveTo(xpos, ypos); //Position window
	if (typeof recalonload!="undefined" && recalonload=="recal" && this.scroll_top==0){ //reposition window when page fully loads with updated window viewpoints?
		if (window.attachEvent && !window.opera){ //In IE, add another 400 milisecs on page load (viewpoint properties may return 0 b4 then)
			this.addEvent(window, function(){setTimeout(function(){t.moveTo(xpos, ypos)}, 400)}, "load");
		}else{
			this.addEvent(window, function(){t.moveTo(xpos, ypos)}, "load");
		}
	}
	t.isResize(getValue("resize")); //Set whether window is resizable
	t.isScrolling(getValue("scrolling")); //Set whether window should contain scrollbars
	t.style.visibility="visible";
	t.style.display="block";
	t.contentarea.style.display="block";
	t.load(contenttype, contentsource, title);
	return t;
},

setSize:function(t, w, h){ //set window size (min is 150px wide by 100px tall)
	t.style.width=Math.max(parseInt(w), 150)+"px";
	t.contentarea.style.height=Math.max(parseInt(h), 100)+"px";
},

moveTo:function(t, x, y){ //move window. Position includes current viewpoint of document
	this.getviewpoint(); //Get current viewpoint numbers
	t.style.left=(x=="middle")? this.scroll_left+(this.docwidth-t.offsetWidth)/2+"px" : this.scroll_left+parseInt(x)+"px";
	t.style.top=(y=="middle")? this.scroll_top+(this.docheight-t.offsetHeight)/2+"px" : this.scroll_top+parseInt(y)+"px";
},

isResize:function(t, bol){ //show or hide resize inteface (part of the status bar)
	t.statusarea.style.display=(bol)? "block" : "none";
},

isScrolling:function(t, bol){ //set whether loaded content contains scrollbars
	t.contentarea.style.overflow=(bol)? "auto" : "hidden";
},

load:function(t, contenttype, contentsource, title){ //loads content into window plus set its title (3 content types: "inline", "iframe", or "ajax")
	var contenttype=contenttype.toLowerCase(); //convert string to lower case
	if (typeof title!="undefined")
	{
		t.handle.firstChild.nodeValue=title;
	}
	if (contenttype=="inline")
	{
		t.contentarea.innerHTML=contentsource;
	}else if (contenttype=="div"){
		t.contentarea.innerHTML=document.getElementById(contentsource).innerHTML; //Populate window with contents of specified div on page
		document.getElementById(contentsource).style.display="none"; //hide that div
	}
	else if (contenttype=="iframe"){
		t.contentarea.style.overflow="hidden"; //disable window scrollbars, as iframe already contains scrollbars
		if (!t.contentarea.firstChild || t.contentarea.firstChild.tagName!="IFRAME"){ //If iframe tag doesn't exist already, create it first
			t.contentarea.innerHTML='<iframe src="" style="margin:0; padding:0; width:100%; height: 100%" marginwidth=0 marginheight=0 frameborder=0 name="_iframe-'+t.id+'"></iframe>';
			window.frames["_iframe-"+t.id].location.replace(contentsource); //set location of iframe window to specified URL
		}
	}
	else if (contenttype=="ajax"){
		this.ajax_connect(contentsource, t); //populate window with external contents fetched via Ajax
	}
	t.contentarea.datatype=contenttype; //store contenttype of current window for future reference
},

setupdrag:function(e){
	var d=dhtmlwindow; //reference dhtml window object
	var t=this._parent; //reference dhtml window div
	d.etarget=this; //remember div mouse is currently held down on ("handle" or "resize" div)
	var e=window.event || e;
	d.initmousex=e.clientX; //store x position of mouse onmousedown
	d.initmousey=e.clientY;
	d.initx=parseInt(t.offsetLeft); //store offset x of window div onmousedown
	d.inity=parseInt(t.offsetTop);
	d.width=parseInt(t.offsetWidth); //store width of window div
	d.contentheight=parseInt(t.contentarea.offsetHeight); //store height of window div's content div
	if (t.contentarea.datatype=="iframe"){ //if content of this window div is "iframe"
		t.style.backgroundColor="#F8F8F8"; //colorize and hide content div (while window is being dragged)
		t.contentarea.style.visibility="hidden";
	}
	document.onmousemove=d.getdistance; //get distance travelled by mouse as it moves
	document.onmouseup=function(){
		if (t.contentarea.datatype=="iframe"){ //restore color and visibility of content div onmouseup
			t.contentarea.style.backgroundColor="white";
			t.contentarea.style.visibility="visible";
		}
	d.stop();
	}
	return false;
},

getdistance:function(e){
	var d=dhtmlwindow;
	var etarget=d.etarget;
	var e=window.event || e;
	d.distancex=e.clientX-d.initmousex; //horizontal distance travelled relative to starting point
	d.distancey=e.clientY-d.initmousey;
	if (etarget.className=="drag-handle")//if target element is "handle" div
	{ 
		d.move(etarget._parent, e);
	}else if (etarget.className=="drag-resizearea"){ //if target element is "resize" div
		d.resize(etarget._parent, e);
	}
	return false; //cancel default dragging behavior
},

getviewpoint:function(){ //get window viewpoint numbers
	var ie=document.all && !window.opera;
	var domclientWidth=document.documentElement && parseInt(document.documentElement.clientWidth) || 100000; //Preliminary doc width in non IE browsers
	this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body; //create reference to common "body" across doctypes
	this.scroll_top=(ie)? this.standardbody.scrollTop : window.pageYOffset;
	this.scroll_left=(ie)? this.standardbody.scrollLeft : window.pageXOffset;
	this.docwidth=(ie)? this.standardbody.clientWidth : (/Safari/i.test(navigator.userAgent))? window.innerWidth : Math.min(domclientWidth, window.innerWidth-16);
	this.docheight=(ie)? this.standardbody.clientHeight: window.innerHeight;
},

rememberattrs:function(t){ //remember certain attributes of the window when it's minimized or closed, such as dimensions, position on page
	this.getviewpoint() //Get current window viewpoint numbers;
	t.lastx=parseInt((t.style.left || t.offsetLeft))-dhtmlwindow.scroll_left; //store last known x coord of window just before minimizing
	t.lasty=parseInt((t.style.top || t.offsetTop))-dhtmlwindow.scroll_top;
	t.lastwidth=t.style.width //store last known width of window just before minimizing;
},

move:function(t, e){
	t.style.left=dhtmlwindow.distancex+dhtmlwindow.initx+"px";
	t.style.top=dhtmlwindow.distancey+dhtmlwindow.inity+"px";
},

resize:function(t, e){
	t.style.width=Math.max(dhtmlwindow.width+dhtmlwindow.distancex, 150)+"px";
	t.contentarea.style.height=Math.max(dhtmlwindow.contentheight+dhtmlwindow.distancey, 100)+"px";
},

enablecontrols:function(e){
	var d=dhtmlwindow;
	var sourceobj=window.event? window.event.srcElement : e.target; //Get element within "handle" div mouse is currently on (the controls)
	if (/Minimize/i.test(sourceobj.getAttribute("title"))){ //if this is the "minimize" control
		d.minimize(sourceobj, this._parent);
	}else if (/Restore/i.test(sourceobj.getAttribute("title"))){ //if this is the "restore" control
		d.restore(sourceobj, this._parent);
	}else if (/Close/i.test(sourceobj.getAttribute("title"))){ //if this is the "close" control
		d.close(this._parent);
	}
	return false;
},

minimize:function(button, t){
	dhtmlwindow.rememberattrs(t);
	button.setAttribute("src", dhtmlwindow.imagefiles[2]);
	button.setAttribute("title", "Restore");
	t.state="minimized"; //indicate the state of the window as being "minimized"
	t.contentarea.style.display="none";
	t.statusarea.style.display="none";
	if (typeof t.minimizeorder=="undefined"){ //stack order of minmized window on screen relative to any other minimized windows
		dhtmlwindow.minimizeorder++ //increment order;
		t.minimizeorder=dhtmlwindow.minimizeorder;
	}
	t.style.left="10px"; //left coord of minmized window
	t.style.width="200px";
	var windowspacing=t.minimizeorder*10; //spacing (gap) between each minmized window(s)
	t.style.top=dhtmlwindow.scroll_top+dhtmlwindow.docheight-(t.handle.offsetHeight*t.minimizeorder)-windowspacing+"px";
},

restore:function(button, t){
	dhtmlwindow.getviewpoint();
	button.setAttribute("src", dhtmlwindow.imagefiles[0]);
	button.setAttribute("title", "Minimize");
	t.state="fullview"; //indicate the state of the window as being "fullview"
	t.style.display="block";
	t.contentarea.style.display="block";
	t.statusarea.style.display="block";
	t.style.left=parseInt(t.lastx)+dhtmlwindow.scroll_left+"px"; //position window to last known x coord just before minimizing
	t.style.top=parseInt(t.lasty)+dhtmlwindow.scroll_top+"px";
	t.style.width=parseInt(t.lastwidth)+"px";
},


close:function(t){
	try{
		var closewinbol=t.onclose();
	}
	catch(err){ //In non IE browsers, all errors are caught, so just run the below
		alert(err);
		var closewinbol=true;
 }
	finally{ //In IE, not all errors are caught, so check if variable isn't defined in IE in those cases
		if (typeof closewinbol=="undefined"){
			alert("An error has occured somwhere inside your \"onclose\" event handler");
			var closewinbol=true;
		}
	}
	if (closewinbol){ //if custom event handler function returns true
		if (t.state!="minimized"); //if this window isn't currently minimized
			dhtmlwindow.rememberattrs(t); //remember window's dimensions/position on the page before closing
		t.style.display="none";
	}
	return closewinbol;
},

show:function(t){
	if (t.lastx){ //If there exists previously stored information such as last x position on window attributes (meaning it's been minimized or closed)
		dhtmlwindow.restore(t.controls.firstChild, t); //restore the window using that info
	}else{
		t.style.display="block";
	}
	t.state="fullview"; //indicate the state of the window as being "fullview"
},

ajax_connect:function(url, t){
	var page_request = false;
	var bustcacheparameter="";
	if (window.XMLHttpRequest){ // if Mozilla, IE7, Safari etc
		page_request = new XMLHttpRequest();
	}else if (window.ActiveXObject){ // if IE6 or below
		try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e){
			try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){}
		}
	}
	else{
		return false;
	}
	page_request.onreadystatechange=function(){dhtmlwindow.ajax_loadpage(page_request, t)}
	if (this.ajaxbustcache){ //if bust caching of external page
		bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime();
	}
	page_request.open('GET', url+bustcacheparameter, true);
	page_request.send(null);
},

ajax_loadpage:function(page_request, t){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
	t.contentarea.innerHTML=page_request.responseText;
	}
},


stop:function(){
	dhtmlwindow.etarget=null; //clean up
	document.onmousemove=null;
	document.onmouseup=null;
},

addEvent:function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
	var tasktype=(window.addEventListener)? tasktype : "on"+tasktype;
	if (target.addEventListener)
	{
		target.addEventListener(tasktype, functionref, false);
	}
	else if (target.attachEvent){
		target.attachEvent(tasktype, functionref);
	}
},

cleanup:function(){
	for (var i=0; i<dhtmlwindow.tobjects.length; i++){
		dhtmlwindow.tobjects[i].handle._parent=dhtmlwindow.tobjects[i].resizearea._parent=dhtmlwindow.tobjects[i].controls._parent=null;
	}
	window.onload=null;
}

} //End dhtmlwindow object

document.write('<div id="dhtmlwindowholder"><span style="display:none">.</span></div>'); //container that holds all dhtml window divs on page
window.onunload=dhtmlwindow.cleanup;

function GetCookie (name) { 
  var arg = name + "="; 
  var alen = arg.length; 
  var clen = document.cookie.length; 
  var i = 0; 

  while (i < clen)
  { 
    var j = i + alen; 

   if (document.cookie.substring(i, j) == arg)
   {
       return getCookieVal (j); 
   }

   i = document.cookie.indexOf(" ", i) + 1; 
   if (i == 0){ break;}

  } 

return null;

}

function SetCookie (name, value) { 
  var argv = SetCookie.arguments; 
  var argc = SetCookie.arguments.length; 
  var expires = (argc > 2) ? argv[2] : null; 
  var path = (argc > 3) ? argv[3] : null; 
  var domain = (argc > 4) ? argv[4] : null; 
  var secure = (argc > 5) ? argv[5] : false; 
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) + 
	((domain == null) ? "" : ("; domain=" + domain)) + 
	((secure == true) ? "; secure" : "");

}

function DeleteCookie (name) { 
  var exp = new Date(); 
  exp.setTime (exp.getTime() - 1); 
  var cval = GetCookie (name); 
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();

}

var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*60*60*1000));

function amt(){
  var count = GetCookie('count');
   
  if(count == null) {
    SetCookie('count','1');
    return 1;
} else {
   var newcount = parseInt(count) + 1;
   DeleteCookie('count');
   SetCookie('count',newcount,exp);
return count;

}

}

function getCookieVal(offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
	{
     endstr = document.cookie.length;
     return unescape(document.cookie.substring(offset, endstr));
	}
}

function checkCount() {
  var count = GetCookie('count');
  if (count == null) {
    count=1;
    SetCookie('count', count, exp);
	var popupwin=dhtmlwindow.open("popupwin", "iframe", page, "NIKAI", windowprops, "recal");
	popupwin.load('iframe', page, popname);
	return false;
  } else { 
    count++;
    SetCookie('count', count, exp);
  } 

}

var flashlinks=new Array();

function changelinkcolor(){
	for (i=0; i< flashlinks.length; i++){
	var flashcolor=document.getElementById? flashlinks[i].getAttribute("rel") : flashlinks[i].flashcolor;
		if (flashlinks[i].style.color!=flashcolor)
		{
			flashlinks[i].style.color=flashcolor;
		}else{
			flashlinks[i].style.color=''
		}
	}
}
 
function flashlinkstart(){
var i=0;
if (document.all){
while (eval("document.all.flashlink"+i)!=null){
flashlinks[i]= eval("document.all.flashlink"+i);
i++;
} 
}
else if (document.getElementById){
while (document.getElementById("flashlink"+i)!=null){
flashlinks[i]= document.getElementById("flashlink"+i);
i++;
}
}
setInterval("changelinkcolor()", 1000);
}

var offsetfromcursorX=12; //Customize x offset of tooltip
var offsetfromcursorY=10; //Customize y offset of tooltip

var offsetdivfrompointerX=10; //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14; //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip"></div>'); //write out tooltip DIV
document.write('<img id="dhtmlpointer" style="visibility: hidden;" src="'+e107_var_image_url+'baseimg/arrow.png">'); //write out pointer image
var ie=document.all;
var ns6=document.getElementById && !document.all;
var enabletip=false;
if (ie||ns6)
{
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "";
}
var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : "";

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function ddrivetip(thetext, thewidth, thecolor){
if (ns6||ie){
if (typeof thewidth!="undefined"){ tipobj.style.width=thewidth+"px";}
if (typeof thecolor!="undefined" && thecolor!=""){ tipobj.style.backgroundColor=thecolor;}
tipobj.innerHTML=thetext;
enabletip=true;
return false;
}
}

function positiontip(e){
if (enabletip){
var nondefaultpos=false;
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20;
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20;

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX;
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY;

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000;

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px";
nondefaultpos=true;
}
else if (curX<leftedge){
tipobj.style.left="5px";
}else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px";
pointerobj.style.left=curX+offsetfromcursorX+"px";
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px";
nondefaultpos=true;
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px";
pointerobj.style.top=curY+offsetfromcursorY+"px";
}
tipobj.style.visibility="visible";
if (!nondefaultpos)
{
pointerobj.style.visibility="visible";
}else{
pointerobj.style.visibility="hidden";
}
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false;
tipobj.style.visibility="hidden";
pointerobj.style.visibility="hidden";
tipobj.style.left="-1000px";
tipobj.style.backgroundColor='';
tipobj.style.width='';
}
}

document.onmousemove=positiontip;


/***********************************************
* Ajax Includes script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

//To include a page, invoke ajaxinclude("afile.htm") in the BODY of page
//Included file MUST be from the same domain as the page displaying it.

var rootdomain="http://"+window.location.hostname;

function ajaxinclude(url,change) {
var page_request = false;
if (window.XMLHttpRequest)
{ // if Mozilla, Safari etc
	page_request = new XMLHttpRequest();
}else if (window.ActiveXObject){ // if IE
	try {
	page_request = new ActiveXObject("Msxml2.XMLHTTP");
	} 

	catch (e){
		try{
		page_request = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e){}
	}
}else{
	return false;
}

page_request.open('GET', url, false); //get page synchronously 
page_request.send(null);
	if(change){
		var sp2 = document.getElementById(change);
		change.innerHTML(page_request.responseText);	
	}else{
		writecontent(page_request);
	}
}

function writecontent(page_request){
if (window.location.href.indexOf("http")==-1 || page_request.status==200)
{
document.write(page_request.responseText);
}
}

/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, quality, xiRedirectUrl, redirectUrl, detectKey) {
	if (!document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
	if (!window.opera && document.all && this.installedVer.major > 7) {
		// only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
		deconcept.SWFObject.doPrepUnload = true;
	}
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', false);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	useExpressInstall: function(path) {
		this.xiSWFPath = !path ? "expressinstall.swf" : path;
		this.setAttribute('useExpressInstall', true);
	},
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs[variablePairs.length] = key +"="+ variables[key];
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "PlugIn");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "ActiveX");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){ // if Windows CE
		var axo = 1;
		var counter = 3;
		while(axo) {
			try {
				counter++;
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
//				document.write("player v: "+ counter);
				PlayerVersion = new deconcept.PlayerVersion([counter,0,0]);
			} catch (e) {
				axo = null;
			}
		}
	} else { // Win IE (non mobile)
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param) {
		var q = document.location.search || document.location.hash;
		if (param == null) { return q; }
		if(q) {
			var pairs = q.substring(1).split("&");
			for (var i=0; i < pairs.length; i++) {
				if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
					return pairs[i].substring((pairs[i].indexOf("=")+1));
				}
			}
		}
		return "";
	}
}
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i = objects.length - 1; i >= 0; i--) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = function(){};
			}
		}
	}
}
// fixes bug in some fp9 versions see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
if (deconcept.SWFObject.doPrepUnload) {
	if (!deconcept.unloadSet) {
		deconcept.SWFObjectUtil.prepUnload = function() {
			__flash_unloadHandler = function(){};
			__flash_savedUnloadHandler = function(){};
			window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs);
		}
		window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload);
		deconcept.unloadSet = true;
	}
}
/* add document.getElementById if needed (mobile IE < 5) */
if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no);
var loadstatustext="<img src='" + e107_var_image_url + "baseimg/loading.gif' /> Cargando contenido...";

////NO NEED TO EDIT BELOW////////////////////////
var loadedobjects="";
var defaultcontentarray=new Object();
var bustcacheparameter="";

function ajaxpage(url, containerid, targetobj){
var page_request = false;
if (window.XMLHttpRequest){ // if Mozilla, Safari etc
	page_request = new XMLHttpRequest();
}else if (window.ActiveXObject){ // if IE
	try {
	page_request = new ActiveXObject("Msxml2.XMLHTTP")
	} 
	catch (e){
		try{
		page_request = new ActiveXObject("Microsoft.XMLHTTP")
		}
		catch (e){}
	}
}else{
return false;
}
var ullist=targetobj.parentNode.parentNode.getElementsByTagName("li");
for (var i=0; i<ullist.length; i++){
ullist[i].className="unsel";  //deselect all tabs
}
targetobj.parentNode.className="selected";  //highlight currently clicked on tab
if (url.indexOf("#default")!=-1){ //if simply show default content within container (verus fetch it via ajax)
document.getElementById(containerid).innerHTML=defaultcontentarray[containerid];
return;
}
containerleft = getElementLeft(containerid);
containertop  = getElementTop(containerid);

if( containertop ){ containertop = containertop + 50 + "px"; }else{ containertop = "50%";}
if( containerleft ){ containerleft = containerleft + 200 + "px"; }else{ containerleft = "50%";}

document.getElementById('loading-layer').style.display="block";
document.getElementById('loading-layer').style.position="absolute";
document.getElementById('loading-layer').style.top=containertop;
document.getElementById('loading-layer').style.left=containerleft;


page_request.onreadystatechange=function(){
loadpage(page_request, containerid);
}
if (bustcachevar){ //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime();
}
page_request.open('GET', url+bustcacheparameter, true);
page_request.send(null);
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
document.getElementById(containerid).innerHTML=page_request.responseText;
}
if (page_request.readyState == 3) {
document.getElementById('loading-layer').style.display="none";
}
}

function loadobjs(revattribute){
if (revattribute!=null && revattribute!=""){ //if "rev" attribute is defined (load external .js or .css files)
var objectlist=revattribute.split(/\s*,\s*/); //split the files and store as array
for (var i=0; i<objectlist.length; i++){
var file=objectlist[i];
var fileref="";
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script');
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link");
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("hreq", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref);
loadedobjects+=file+" "; //Remember this object as being already added to page
}
}
}
}

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")){
ajaxpage(thetab.getAttribute("href"), thetab.getAttribute("rel"), thetab);
loadobjs(thetab.getAttribute("rev"));
}
}

function savedefaultcontent(contentid){// save default ajax tab content
if (typeof defaultcontentarray[contentid]=="undefined")
{
defaultcontentarray[contentid]=document.getElementById(contentid).innerHTML;
}
}

function startajaxtabs(){
for (var i=0; i<arguments.length; i++){ //loop through passed UL ids
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")){
var modifiedurl=ulistlink.getAttribute("hreq").replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/");
ulistlink.setAttribute("hreq", modifiedurl); //replace URL's root domain with dynamic root domain, for ajax security sake
savedefaultcontent(ulistlink.getAttribute("rel")); //save default ajax tab content
ulistlink.onclick=function(){
if(this.getAttribute("inmage"))
{
	change_image(this.getAttribute("inmage"));
}
ajaxpage(this.getAttribute("hreq"), this.getAttribute("rel"), this);
loadobjs(this.getAttribute("rev"));
return false;
}
if (ulist[x].className=="selected"){
ajaxpage(ulistlink.getAttribute("hreq"), ulistlink.getAttribute("rel"), ulistlink); //auto load currenly selected tab content
loadobjs(ulistlink.getAttribute("rev")); //auto load any accompanying .js and .css files
}
}
}
}
}

function change_image(imageid) {
	var imageq = document.getElementById(current_tab);
	var imagef = document.getElementById(imageid);

	imageq_off = imageq.getAttribute("off");
	imagef_off = imagef.getAttribute("off");

	imageq_src = imageq.src;
	imagef_src = imagef.src;

	imageq.setAttribute("off", imageq_src);
	imagef.setAttribute("off", imagef_src);

	imageq.src = imageq_off;
	imagef.src = imagef_off;

	current_tab = imageid;
}

function timed_toggleview(argument,timed,onlyclose){
	
	if(argument)
	{
		base_menu = argument;
		if(onlyclose)
		{
			var displaybox = document.getElementById(argument);
			if(displaybox.style.display == "")
			{
				clearTimeout(myTimer);
				return;
			}
		}
		myTimer = setTimeout('toggleview(base_menu)', timed);
	}

}

function window_popup(dircls, name, widthsz, heightsz)
{
   window.open(dircls, name, 'width='+widthsz+',height='+heightsz+',toolbar=0,location=0,resizable=no,menubar=0,directories=0,scrollbars=no');
}

function firefox_google()
{
	if(ie)
	{
		document.getElementById("ffgoogle").style.display="block";
		document.writeln('Su explorador no es 100% compatible con NIKAI, \n<script type="text\/javascript"><!--\ngoogle_ad_client = "pub-2821833103064236";\ngoogle_ad_output = "textlink";\ngoogle_ad_format = "ref_text";\ngoogle_cpa_choice = "CAAQiav2_gEaCNZPUcKfVktOKOW14YcBMAA";\ngoogle_ad_channel = "8012785934";\n\/\/-->\n<\/script>\n<script type="text\/javascript" src="http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js">\n<\/script>');
	}
}

function getElementLeft(Elem) {
	var elem;
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	xPos = elem.offsetLeft;
	tempEl = elem.offsetParent;
  		while (tempEl != null) {
  			xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  		}
	return xPos;
}


function getElementTop(Elem) {

	if(document.getElementById) {	
		var elem = document.getElementById(Elem);
	} else if (document.all) {
		var elem = document.all[Elem];
	}
	yPos = elem.offsetTop;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
  			yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  		}
	return yPos;
}

function showanother(menu1,menu2,off)
{
	if(!off)
	{
		if(document.getElementById(menu2))
		{
			document.getElementById(menu1).style.display="none";
			document.getElementById(menu2).style.display="block";
		}
	}else{
		if(document.getElementById(menu2))
		{
			document.getElementById(menu1).style.display="block";
			document.getElementById(menu2).style.display="none";
		}
	}
}

function tryloadchat()
{
	if (document.getElementById('jal_lastID') == undefined)
	{
		shitty = 0;
	}
	else
	{
		shitty = document.getElementById('jal_lastID');
	}

	if ( shitty.value ) 
	{
		clearTimeout(cmwait);
		initJavaScript();
	}
	else
	{
		if( runcount == 0 )
		{
			chatmesscount = 0;
			resettimeout();
			countChatText();
		}
	}
}

var tamActual = 11;

function tamTexto(idT,content) {

	if (idT == 2) {
		if (tamActual <= 14) {
			tamActual++;
			document.getElementById(content).style.fontSize = tamActual+"px";
		}	
	} else {
		if (tamActual >= 10) {
			tamActual--;
			document.getElementById(content).style.fontSize = tamActual+"px";
		}
	}
}

function selectAmount(object, amount, unselect) {
if(typeof object=="string"){object=document.getElementById(object);};
if(!object || typeof object!="object" || !object.options || !object.options.length){return false;}
amount=( typeof parseFloat(amount)=="number" )?parseFloat(amount):object.options.length-1; amount=Math.abs(amount);
	for(var i=0, limit=0; i < object.options.length; i++){
		if(object.options[i].selected && ++limit>amount){
		alert("SÃ³lo puedes seleccionar "+amount+" como mÃ¡ximo.");
			if(unselect){
				for(var x=i; x < object.options.length; x++){
				object.options[x].selected=false;
				}
			};
		return false;
		};
	}
return true;
}


//** Ajax Tabs Content script v2.0- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
//** Updated Oct 21st, 07 to version 2.0. Contains numerous improvements

//** Updated Feb 18th, 08 to version 2.1: Adds a public "tabinstance.cycleit(dir)" method to cycle forward or backward between tabs dynamically. Only .js file changed from v2.0.

var ddajaxtabssettings={}
ddajaxtabssettings.bustcachevar=1  //bust potential caching of external pages after initial request? (1=yes, 0=no)
ddajaxtabssettings.loadstatustext="<div id='loading_esc'><img src='"+ e107_var_image_url +"baseimg/loading.gif' /> Cargando contenido...</div>" 


////NO NEED TO EDIT BELOW////////////////////////

function ddajaxtabs(tabinterfaceid, contentdivid){
	this.tabinterfaceid=tabinterfaceid //ID of Tab Menu main container
	this.tabs=document.getElementById(tabinterfaceid).getElementsByTagName("a") //Get all tab links within container
	this.enabletabpersistence=true
	this.hottabspositions=[] //Array to store position of tabs that have a "rel" attr defined, relative to all tab links, within container
	this.currentTabIndex=0 //Index of currently selected hot tab (tab with sub content) within hottabspositions[] array
	this.contentdivid=contentdivid
	this.defaultHTML=""
	this.defaultIframe='<iframe src="about:blank" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" class="tabcontentiframe" style="width:100%; height:auto; min-height: 100px"></iframe>'
	this.defaultIframe=this.defaultIframe.replace(/<iframe/i, '<iframe name="'+"_ddajaxtabsiframe-"+contentdivid+'" ')
this.revcontentids=[] //Array to store ids of arbitrary contents to expand/contact as well ("rev" attr values)
	this.selectedClassTarget="link" //keyword to indicate which target element to assign "selected" CSS class ("linkparent" or "link")
}

ddajaxtabs.connect=function(pageurl, tabinstance){
	var page_request = false
	var bustcacheparameter=""
	if (window.XMLHttpRequest) // if Mozilla, IE7, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE6 or below
		try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else
		return false
	var ajaxfriendlyurl=pageurl.replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/") 
	page_request.onreadystatechange=function(){ddajaxtabs.loadpage(page_request, pageurl, tabinstance)}
	if (ddajaxtabssettings.bustcachevar) //if bust caching of external page
		bustcacheparameter=(ajaxfriendlyurl.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	page_request.open('GET', ajaxfriendlyurl+bustcacheparameter, true)
	page_request.send(null)
}

ddajaxtabs.loadpage=function(page_request, pageurl, tabinstance){
	var divId=tabinstance.contentdivid
	document.getElementById(divId).innerHTML=ddajaxtabssettings.loadstatustext //Display "fetching page message"
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
		document.getElementById(divId).innerHTML=page_request.responseText
		ddajaxtabs.ajaxpageloadaction(pageurl, tabinstance)
	}
}

ddajaxtabs.ajaxpageloadaction=function(pageurl, tabinstance){
	tabinstance.onajaxpageload(pageurl) //call user customized onajaxpageload() function when an ajax page is fetched/ loaded
}

ddajaxtabs.getCookie=function(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return ""
}

ddajaxtabs.setCookie=function(name, value){
	document.cookie = name+"="+value+";path=/" //cookie value is domain wide (path=/)
}

ddajaxtabs.prototype={

	expandit:function(tabid_or_position){ //PUBLIC function to select a tab either by its ID or position(int) within its peers
		this.cancelautorun() //stop auto cycling of tabs (if running)
		var tabref=""
		try{
			if (typeof tabid_or_position=="string" && document.getElementById(tabid_or_position).getAttribute("rel")) //if specified tab contains "rel" attr
				tabref=document.getElementById(tabid_or_position)
			else if (parseInt(tabid_or_position)!=NaN && this.tabs[tabid_or_position].getAttribute("rel")) //if specified tab contains "rel" attr
				tabref=this.tabs[tabid_or_position]
		}
		catch(err){alert("Invalid Tab ID or position entered!")}
		if (tabref!="") //if a valid tab is found based on function parameter
			this.expandtab(tabref) //expand this tab
	},

	cycleit:function(dir, autorun){ //PUBLIC function to move foward or backwards through each hot tab (tabinstance.cycleit('foward/back') )
		if (dir=="next"){
			var currentTabIndex=(this.currentTabIndex<this.hottabspositions.length-1)? this.currentTabIndex+1 : 0
		}
		else if (dir=="prev"){
			var currentTabIndex=(this.currentTabIndex>0)? this.currentTabIndex-1 : this.hottabspositions.length-1
		}
		if (typeof autorun=="undefined") //if cycleit() is being called by user, versus autorun() function
			this.cancelautorun() //stop auto cycling of tabs (if running)
		this.expandtab(this.tabs[this.hottabspositions[currentTabIndex]])
	},

	setpersist:function(bool){ //PUBLIC function to toggle persistence feature
			this.enabletabpersistence=bool
	},

	loadajaxpage:function(pageurl){ //PUBLIC function to fetch a page via Ajax and display it within the Tab Content instance's container
		ddajaxtabs.connect(pageurl, this)
	},

	loadiframepage:function(pageurl){ //PUBLIC function to fetch a page and load it into the IFRAME of the Tab Content instance's container
		this.iframedisplay(pageurl, this.contentdivid)
	},

	setselectedClassTarget:function(objstr){ //PUBLIC function to set which target element to assign "selected" CSS class ("linkparent" or "link")
		this.selectedClassTarget=objstr || "link"
	},

	getselectedClassTarget:function(tabref){ //Returns target element to assign "selected" CSS class to
		return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref
	},

	onajaxpageload:function(pageurl){ //PUBLIC Event handler that can invoke custom code whenever an Ajax page has been fetched and displayed
		//do nothing by default
	},

	expandtab:function(tabref){
		var relattrvalue=tabref.getAttribute("rel")
		//Get "rev" attr as a string of IDs in the format ",john,george,trey,etc," to easy searching through
		var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+"," : ""
		if (relattrvalue=="#default")
			document.getElementById(this.contentdivid).innerHTML=this.defaultHTML
		else if (relattrvalue=="#iframe")
			this.iframedisplay(tabref.getAttribute("href"), this.contentdivid)
		else
			ddajaxtabs.connect(tabref.getAttribute("href"), this)
		this.expandrevcontent(associatedrevids)
		for (var i=0; i<this.tabs.length; i++){ //Loop through all tabs, and assign only the selected tab the CSS class "selected"
			this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("href")==tabref.getAttribute("href"))? "selected" : ""
		}
		if (this.enabletabpersistence) //if persistence enabled, save selected tab position(int) relative to its peers
			ddajaxtabs.setCookie(this.tabinterfaceid, tabref.tabposition)
		this.setcurrenttabindex(tabref.tabposition) //remember position of selected tab within hottabspositions[] array
	},

	iframedisplay:function(pageurl, contentdivid){
		if (typeof window.frames["_ddajaxtabsiframe-"+contentdivid]!="undefined"){
			try{delete window.frames["_ddajaxtabsiframe-"+contentdivid]} //delete iframe within Tab content container if it exists (due to bug in Firefox)
			catch(err){}
		}
		document.getElementById(contentdivid).innerHTML=this.defaultIframe
		window.frames["_ddajaxtabsiframe-"+contentdivid].location.replace(pageurl) //load desired page into iframe
	},


	expandrevcontent:function(associatedrevids){
		var allrevids=this.revcontentids
		for (var i=0; i<allrevids.length; i++){ //Loop through rev attributes for all tabs in this tab interface
			//if any values stored within associatedrevids matches one within allrevids, expand that DIV, otherwise, contract it
			document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block" : "none"
		}
	},

	setcurrenttabindex:function(tabposition){ //store current position of tab (within hottabspositions[] array)
		for (var i=0; i<this.hottabspositions.length; i++){
			if (tabposition==this.hottabspositions[i]){
				this.currentTabIndex=i
				break
			}
		}
	},

	autorun:function(){ //function to auto cycle through and select tabs based on a set interval
		this.cycleit('next', true)
	},

	cancelautorun:function(){
		if (typeof this.autoruntimer!="undefined")
			clearInterval(this.autoruntimer)
	},

	init:function(automodeperiod){
		var persistedtab=ddajaxtabs.getCookie(this.tabinterfaceid) //get position of persisted tab (applicable if persistence is enabled)
		var persisterror=true //Bool variable to check whether persisted tab position is valid (can become invalid if user has modified tab structure)
		this.automodeperiod=automodeperiod || 0
		this.defaultHTML=document.getElementById(this.contentdivid).innerHTML
		for (var i=0; i<this.tabs.length; i++){
			this.tabs[i].tabposition=i //remember position of tab relative to its peers
			if (this.tabs[i].getAttribute("rel")){
				var tabinstance=this
				this.hottabspositions[this.hottabspositions.length]=i //store position of "hot" tab ("rel" attr defined) relative to its peers
				this.tabs[i].onclick=function(){
					tabinstance.expandtab(this)
					tabinstance.cancelautorun() //stop auto cycling of tabs (if running)
					return false
				}
				if (this.tabs[i].getAttribute("rev")){ //if "rev" attr defined, store each value within "rev" as an array element
					this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/))
				}
				if (this.enabletabpersistence && parseInt(persistedtab)==i || !this.enabletabpersistence && this.getselectedClassTarget(this.tabs[i]).className=="selected"){
					this.expandtab(this.tabs[i]) //expand current tab if it's the persisted tab, or if persist=off, carries the "selected" CSS class
					persisterror=false //Persisted tab (if applicable) was found, so set "persisterror" to false
				}
			}
		} //END for loop
		if (persisterror) //if an error has occured while trying to retrieve persisted tab (based on its position within its peers)
			this.expandtab(this.tabs[this.hottabspositions[0]]) //Just select first tab that contains a "rel" attr
		if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){
			this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod)
		}
	} //END int() function

} //END Prototype assignment

var disappeardelay = 250;
var verticaloffset = -10;
var enablearrowhead = 1;
var arrowheadimg = [e107_var_image_url+"baseimg/arrow.png", e107_var_image_url+"baseimg/arrow.png"];
var arrowheadheight = 14;

verticaloffset=(enablearrowhead)? verticaloffset+arrowheadheight : verticaloffset;
tiparrow=document.createElement("img");
tiparrow.setAttribute("src", arrowheadimg[0]);
tiparrow.setAttribute("id", "arrowhead");
document.body.appendChild(tiparrow);

function getposOffset(what, offsettype)
{
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;

	while (parentEl!=null)
	{
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}

	return totaloffset;
}

function showhide(obj, e)
{
	dropmenuobj.style.left=dropmenuobj.style.top="-500px";
	obj.visibility="visible";
}

function iecompattest()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function clearbrowseredge(obj, whichedge)
{
	if (whichedge=="rightedge")
	{
		edgeoffsetx=0;
		var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15;
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth;
		
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
		{
			edgeoffsetx=dropmenuobj.contentmeasure-obj.offsetWidth;
		}
	
		return edgeoffsetx;
	}
	else
	{
		edgeoffsety=0;
		var topedge=ie && !window.opera? iecompattest().scrollTop : window.pageYOffset;
		var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight;

		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
		{
			edgeoffsety=dropmenuobj.contentmeasure+obj.offsetHeight+(verticaloffset*2);
		}

		return edgeoffsety;
	}
}

function displayballoontip(obj, e)
{
	if (window.event)
	{
		event.cancelBubble=true;
	}
	else if (e.stopPropagation)
	{
		e.stopPropagation();
	}

	if (typeof dropmenuobj!="undefined")
	{
		dropmenuobj.style.visibility="hidden";
	}

	clearhidemenu()

	dropmenuobj=document.getElementById(e);
	dobj=document.getElementById(obj);
	showhide(dropmenuobj.style);
	dropmenuobj.x=getposOffset(dobj, "left");
	dropmenuobj.y=getposOffset(dobj, "top")+verticaloffset;
	dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(dobj, "rightedge")+40+"px";
	dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(dobj, "bottomedge")+dobj.offsetHeight+"px";

	if (enablearrowhead)
	{
		displaytiparrow();
	}
}

function displaytiparrow()
{
	tiparrow=document.getElementById("arrowhead");
	tiparrow.src=(edgeoffsety!=0)? arrowheadimg[0] : arrowheadimg[1];
	var ieshadowwidth=(dropmenuobj.filters && dropmenuobj.filters[0])? dropmenuobj.filters[0].Strength-1 : 0;
	tiparrow.style.left=(edgeoffsetx!=0)? parseInt(dropmenuobj.style.left)+dropmenuobj.offsetWidth-tiparrow.offsetWidth-10+"px" : parseInt(dropmenuobj.style.left)+5+"px";
	tiparrow.style.top=(edgeoffsety!=0)? parseInt(dropmenuobj.style.top)+dropmenuobj.offsetHeight-tiparrow.offsetHeight-ieshadowwidth+arrowheadheight+"px" : parseInt(dropmenuobj.style.top)-arrowheadheight+"px";
	tiparrow.style.visibility="visible";
}

function delayhidemenu()
{
	delayhide=setTimeout("dropmenuobj.style.visibility='hidden'; dropmenuobj.style.left=0; if (enablearrowhead) tiparrow.style.visibility='hidden'",disappeardelay);
}

function clearhidemenu()
{
	if (typeof delayhide!="undefined")
	{
		clearTimeout(delayhide);
	}
}

function reltoelement(linkobj)
{
	var relvalue=linkobj.getAttribute("rel");
	return (relvalue!=null && relvalue!="" && document.getElementById(relvalue)!=null && document.getElementById(relvalue).className=="balloonstyle")? true : false;
}
