function gObj(obj) {var theObj;if(document.all){if(typeof obj=="string"){return document.all(obj);}else{return obj.style;}}if(document.getElementById){if(typeof obj=="string"){return document.getElementById(obj);}else{return obj.style;}}return null;}
function trimAll(sString){while (sString.substring(0,1) == ' '){sString = sString.substring(1, sString.length);}while (sString.substring(sString.length-1, sString.length) == ' '){sString = sString.substring(0,sString.length-1);} return sString;}
function isNumber(val){val=val+"";if (val.length<1) return false;if (isNaN(val)){return false;}else{return true;}}
function rsf(){var args = rsf.arguments;var frM = document.hsF;if (args.length>1){if (args[0]=='action'){eval("frM."+args[0]+"=args[1];");}else{eval("frM."+args[0]+".value=args[1];");}if (args.length>3) eval("frM."+args[2]+".value=args[3];");if (args.length>5) eval("frM."+args[4]+".value=args[5];");frM.submit();}}

function uploading(formObj){
	gObj("uploadButton").style.display = 'none';
	gObj("uploadingText").style.display = 'block';
	return true;
}

function vTerm(checkBoxObj){
	if (checkBoxObj == undefined){
		checkBoxObj = document.rF.agreeterm;
	}
	if (checkBoxObj.checked){
		return true;
	}else{
		alert("You must agree!");
		return false;
	}
}

function Set_Cookie(name, value, expires, path, domain, secure ){
	path = "/";
	var today = new Date();
	today.setTime( today.getTime() );

	if (expires){
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}
function inList(previousV, newVal){
	if ((previousV.length) < 1){
		return false;
	}else{
		previousVArray = previousV.split(',');
		for (i=0;i<previousVArray.length;i++){
			if (newVal==previousVArray[i]){
				return true;
			}
		}
		return false;
	}
}
function addV(previousV, newVal){
	if ((previousV.length) < 1){
		return newVal;
	}else{
		if (inList(previousV, newVal)){
			return previousV;
		}else{
			return previousV + "," + newVal;
		}
	}
}
function removeV(previousV, newVal){
	if ((previousV.length) < 1){
		return "";
	}else{
		previousVArray = previousV.split(',');
		newOutPut = "";
		for (i=0;i<previousVArray.length;i++){
			if (newVal!=previousVArray[i]){
				if (newOutPut.length < 1){
					newOutPut += previousVArray[i];
				}else{
					newOutPut += "," + previousVArray[i];
				}
			}
		}
		return newOutPut;
	}
}
function sl(val,oid,type,operation,isCheckOnly){
	var cookieName = "dlist";
	if (type=="question") cookieName="qlist";
	if (type=="guide") cookieName="glist";
	previousValue = Get_Cookie(cookieName);
	if (previousValue == undefined) previousValue="";

	if (isCheckOnly=="1"){
		if (inList(previousValue, val)){
			operation="save";
		}else{
			operation="removed";
		}
	}
	if (operation=="save"){
		Set_Cookie(cookieName, addV(previousValue,val), 365);
		hintText = (isCheckOnly!="1") ? "Saved! Remove It" : "Remove From List";
		gObj(oid).innerHTML = "<a href=\"#\" onClick=\"return sl('"+val+"','"+oid+"','"+type+"','remove');\">"+hintText+"</a>";
	}else{
		Set_Cookie(cookieName, removeV(previousValue,val), 365);
		hintText = (isCheckOnly!="1") ? "Removed! Save It" : "Save to List";
		gObj(oid).innerHTML = "<a href=\"#\" onClick=\"return sl('"+val+"','"+oid+"','"+type+"','save');\">"+hintText+"</a>";
	}

	return false;
}

//REVIEW VOTE
var req;
var outputobj = '';
function loadXMLDoc(url){
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function processReqChange() {
    if (req.readyState == 4) {
        if (req.status == 200) {
		response = req.responseText;
		aOperation(response);
        }
    }
}

function aOperation(response){
	gObj(outputobj).innerHTML = "Thank You!";
}

function reviewvote(rid, op, objid){
	url = "/review/thumb.php?rid=" + rid + "&op=" + op;
	outputobj = objid;
	loadXMLDoc(url)
}

function questionvote(qid, op, objid){
	url = "/q/qthumb.php?qid=" + qid + "&op=" + op;
	outputobj = objid;
	loadXMLDoc(url)
}

function answervote(aid, op, objid){
	url = "/q/athumb.php?aid=" + aid + "&op=" + op;
	outputobj = objid;
	loadXMLDoc(url)
}

/*
function showSubnav(a){
	document.screener.n.value=a;
	if (a==0) {
		for(i=1;i<=4;i++)
			document.getElementById('divSubnav'+i).style.display = 'block';
	}
	else {
		for(i=1;i<=4;i++)
			document.getElementById('divSubnav'+i).style.display = 'none';
		document.getElementById('divSubnav'+a).style.display = 'block';
	}
	
	document.screener.submit();
	return false;
}
*/