var is_regexp = (window.RegExp) ? true : false;

// make an array to store cached locations of objects called by fetch_object
var vBobjects = new Array();

var BrowserInfo = new Object() ;
var sAgent = navigator.userAgent.toLowerCase() ;
BrowserInfo.IsIE			= ( sAgent.indexOf("msie") != -1 ) ;
BrowserInfo.IsGecko		= !BrowserInfo.IsIE ;
BrowserInfo.IsSafari		= ( sAgent.indexOf("safari") != -1 );
BrowserInfo.IsNetscape	= ( sAgent.indexOf("netscape") != -1 ) ;

function openWin(sURL,sName,iWidth,iHeight){
	var top,left;
	top=(screen.height-iHeight)/2;
	left=(screen.width-iWidth)/2;
	if(top<0)top=0;
	if(left<0)left=0;
	return window.open(sURL,sName,'scrollbars=yes,width='+iWidth+',height='+iHeight+',left='+left+',top='+top);
}

// #############################################################################


function findObj(n, d) { //v4.01
	var p,i,x;
	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++)
	x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++)
	x=findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n);
	return x;
}

/**
* listbox redirection
*/
function jumpSelectMenu(targ,selObj){
	if(selObj.options[selObj.selectedIndex].value!='')
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");

}
// #############################################################################
// ##################### vBulletin Cookie Functions ############################
// #############################################################################

// #############################################################################
// function to set a cookie
function set_cookie(name, value, expires)
{
	if (!expires)
	{
		expires = new Date();
	}
	document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() +  "; path=/";
}

// #############################################################################
// function to retrieve a cookie
function fetch_cookie(name)
{
	cookie_name = name + "=";
	cookie_length = document.cookie.length;
	cookie_begin = 0;
	while (cookie_begin < cookie_length)
	{
		value_begin = cookie_begin + cookie_name.length;
		if (document.cookie.substring(cookie_begin, value_begin) == cookie_name)
		{
			var value_end = document.cookie.indexOf (";", value_begin);
			if (value_end == -1)
			{
				value_end = cookie_length;
			}
			return unescape(document.cookie.substring(value_begin, value_end));
		}
		cookie_begin = document.cookie.indexOf(" ", cookie_begin) + 1;
		if (cookie_begin == 0)
		{
			break;
		}
	}
	return null;
}

// #############################################################################
// function to delete a cookie
function delete_cookie(name)
{
	var expireNow = new Date();
	document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}

// #############################################################################
// ################## vBulletin Collapse HTML Functions ########################
// #############################################################################

// #############################################################################
// function to toggle the collapse state of an object, and save to a cookie
function toggle_collapse(objid)
{
	if (!is_regexp)
	{
		return false;
	}

	obj = findObj("collapseobj_" + objid);
	but = findObj("collapsebutton_" + objid);
	cel = findObj("collapsecel_" + objid);

	if (!obj)
	{
		// nothing to collapse!
		if (but)
		{
			// hide the clicky image if there is one
			but.style.display = "none";
		}
		return false;
	}

	if (obj.style.display == "none")
	{
		obj.style.display = "";
		save_collapsed(objid, false);
		if (but)
		{
			but.className = but.className.replace(/^(.+)(_collapsed)$/, '$1');
		}
		if (cel)
		{
			cel.className = cel.className.replace(/^(.+)(_collapsed)$/, '$1');
		}
	}
	else
	{
		obj.style.display = "none";
		save_collapsed(objid, true);
		if (but)
		{
			but.className = but.className.replace(/^(.+)$/, '$1_collapsed');
		}
		if (cel)
		{
			cel.className = cel.className.replace(/^(.+)$/, '$1_collapsed');
		}
	}
	return false;
}

// #############################################################################
// update vbulletin_collapse cookie with collapse preferences
function save_collapsed(objid, addcollapsed)
{
	var collapsed = fetch_cookie("vbulletin_collapse");
	var tmp = new Array();

	if (collapsed != null)
	{
		collapsed = collapsed.split("\n");

		for (i in collapsed)
		{
			if (collapsed[i] != objid && collapsed[i] != "")
			{
				tmp[tmp.length] = collapsed[i];
			}
		}
	}

	if (addcollapsed)
	{
		tmp[tmp.length] = objid;
	}

	expires = new Date();
	expires.setTime(expires.getTime() + (1000 * 86400 * 365));
	set_cookie("vbulletin_collapse", tmp.join("\n"), expires);
}

/**
* Sets/unsets the pointer and marker in browse mode
*
* @param   object    the table row
* @param   interger  the row number
* @param   string    the action calling this script (over, out or click)
* @param   string    the default background color
* @param   string    the color to use for mouseover
* @param   string    the color to use for marking a row
*
* @return  boolean  whether pointer is set or not
*/
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
	var theCells = null;

	// 1. Pointer and mark feature are disabled or the browser can't get the
	//    row -> exits
	if ((thePointerColor == '' && theMarkColor == '')
	|| typeof(theRow.style) == 'undefined') {
		return false;
	}

	// 2. Gets the current row and exits if the browser can't get it
	if (typeof(document.getElementsByTagName) != 'undefined') {
		theCells = theRow.getElementsByTagName('td');
	}
	else if (typeof(theRow.cells) != 'undefined') {
		theCells = theRow.cells;
	}
	else {
		return false;
	}

	// 3. Gets the current color...
	var rowCellsCnt  = theCells.length;
	var domDetect    = null;
	var currentColor = null;
	var newColor     = null;
	// 3.1 ... with DOM compatible browsers except Opera that does not return
	//         valid values with "getAttribute"
	if (typeof(window.opera) == 'undefined'
	&& typeof(theCells[0].getAttribute) != 'undefined') {
		currentColor = theCells[0].getAttribute('bgcolor');
		domDetect    = true;
	}
	// 3.2 ... with other browsers
	else {
		currentColor = theCells[0].style.backgroundColor;
		domDetect    = false;
	} // end 3

	// 4. Defines the new color
	// 4.1 Current color is the default one
	if (currentColor == ''
	|| currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
		if (theAction == 'over' && thePointerColor != '') {
			newColor              = thePointerColor;

		}else if (theAction == 'click' && theMarkColor != '') {
			newColor              = theMarkColor;
			marked_row[theRowNum] = true;
		}
	}
	// 4.1.2 Current color is the pointer one
	else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
	&& (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
		if (theAction == 'out') {
			newColor              = theDefaultColor;
		}
		else if (theAction == 'click' && theMarkColor != '') {
			newColor              = theMarkColor;
			marked_row[theRowNum] = true;
		}
	}
	// 4.1.3 Current color is the marker one
	else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
		if (theAction == 'click') {
			newColor              = (thePointerColor != '')
			? thePointerColor
			: theDefaultColor;
			marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
			? true
			: null;
		}
	} // end 4

	// 5. Sets the new color...
	if (newColor) {
		var c = null;
		// 5.1 ... with DOM compatible browsers except Opera
		if (domDetect) {
			for (c = 0; c < rowCellsCnt; c++) {
				theCells[c].setAttribute('bgcolor', newColor, 0);
			} // end for
		}
		// 5.2 ... with other browsers
		else {
			for (c = 0; c < rowCellsCnt; c++) {
				theCells[c].style.backgroundColor = newColor;
			}
		}
	} // end 5

	return true;
} // end of the 'setPointer()' function

var issFrame = new Object();

issFrame.submitForm = function(form,paramName,paramValue){
	oF = findObj(form);

	if(oF.tagName=='FORM'){
		if(paramName){
			oTag = document.createElement('input');
			oF.appendChild(oTag);
			oTag.name = paramName;
			oTag.value = paramValue;
			oF.submit();
			oF.removeChild(oTag);
		}else{
			oF.submit();
		}
	}else{

	}
}

issFrame.getBackGroudIframe = function(){
	if(oIframe = window.frames["__backgroud__"]){
		return oIframe;
	}else{
		if(BrowserInfo.IsIE){
			oIframe = document.createElement("<iframe name='__backgroud__'>");
		}else{
			oIframe = document.createElement("iframe");
			oIframe.name = "__backgroud__";
		}
		document.body.appendChild(oIframe);
		oIframe.width = '0px';
		oIframe.height = '0px';
		oIframe.frameBorder = 0;
		oIframe.src = 'about:blank';
		return oIframe;
	}
}

issFrame.submitForm_background = function(formName,param){
	oIframe = issFrame.getBackGroudIframe();
	if(document.attachEvent)
	oIframe.attachEvent("onload",this.onLoadBackgroudSubmit);
	if(document.addEventListener)
	oIframe.addEventListener("load",this.onLoadBackgroudSubmit,false);

	oF = findObj(formName);
	target = oF.target;
	oF.target = oIframe.name;
	oTag = document.createElement('input');
	oF.appendChild(oTag);
	oTag.name = "__backgroud_tag_";
	oTag.value = "";
	//oTag.type = "hidden";
	oF.submit();
	oF.removeChild(oTag);
	oF.target = target;
}

issFrame.onLoadBackgroudSubmit = function(){
	var oF = window.frames["__backgroud__"];
	if(BrowserInfo.IsIE){
		oF.detachEvent("onload",issFrame.onLoadBackgroudSubmit);
		alert(oF.document.body.innerHTML);
	}else{
		try{
			oF.removeEventListener("load",this.onLoadBackgroudSubmit,false);
		}finally{
			alert(oF.document.body.innerHTML);
		}
	}
}

issFrame.showOrHidden = function(sObjectID,show){
	obj = findObj(sObjectID);
	if(obj){
		if(show){
			obj.style.display = "";
		}else{
		    obj.style.display = "none";
		}
	}
}

issFrame.CheckAll = function(sAttributeName,bChecked){
	oCols = document.getElementsByTagName('input');
	for(i=0;i<oCols.length;i++){
		if(oCols[i].type == 'checkbox' && oCols[i].getAttribute(sAttributeName)){
			try{
				oCols[i].checked = bChecked;
			}catch(e){
			}
		}
	}
}

issFrame.findObj = function(n, d) { //v4.01
	var p,i,x;
	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++)
	x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++)
	x=findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n);
	return x;
}

issFrame.autoScroll_objs = new Object();

issFrame.autoScroll_contrl = function(oName){
	os = issFrame.autoScroll_objs[oName];
	if(issFrame.autoScroll_objs[oName].Block.issScrollPause){
		return;
	}
	if(os.Block.scrollLeft + os.Block.offsetWidth>=os.Block.scrollWidth ){
		issFrame.autoScroll_objs[oName].Block.scrollLeft = 0;
	}else if(issFrame.autoScroll_objs[oName].Content2.offsetWidth-issFrame.autoScroll_objs[oName].Block.scrollLeft<=0)
		issFrame.autoScroll_objs[oName].Block.scrollLeft-=issFrame.autoScroll_objs[oName].Content1.offsetWidth
	else{
		issFrame.autoScroll_objs[oName].Block.scrollLeft++
	}
	
}

issFrame.autoScroll = function(oName,iSpeed){
	issFrame.autoScroll_objs[oName] = new Object();
	issFrame.autoScroll_objs[oName].Block = issFrame.findObj(oName);
	issFrame.autoScroll_objs[oName].Block.issScrollPause = false;
	issFrame.autoScroll_objs[oName].Content1 = issFrame.findObj(oName+'_1');
	issFrame.autoScroll_objs[oName].Content2 = issFrame.findObj(oName+'_2');
	issFrame.autoScroll_objs[oName].Content2.innerHTML = 	issFrame.autoScroll_objs[oName].Content1.innerHTML;
	setInterval("issFrame.autoScroll_contrl('"+oName+"')",iSpeed);
	issFrame.autoScroll_objs[oName].Block.onmouseover=function(){	issFrame.autoScroll_objs[oName].Block.issScrollPause = true;}
	issFrame.autoScroll_objs[oName].Block.onmouseout=function() {	issFrame.autoScroll_objs[oName].Block.issScrollPause = false;}
}