function SearchMedia(form,URL)
{
	var ctr=eval("document."+form);
	if(ctr.searchmedia.value=="")
	{
		alert("Please enter search string.");
		ctr.searchmedia.focus();
		return false;
	}
	if(ctr.mediatype.value=="")
	{
		var s=spaceTrim(ctr.searchmedia.value);
		var searchURL=URL+"search/"+s.replace(/\s+/g,'-');
	}
	else
	{
		var s=spaceTrim(ctr.searchmedia.value);
		var searchURL=URL+ctr.mediatype.value+"/search/"+s.replace(/\s+/g,'-');
	}
	ctr.action=searchURL;
}
function SafeSearch(val)
{
	var v=getWindowWidth();
	v=v/2;
	v=v-200;
	if(val=="on")
	{
		window.document.getElementById('safesearchOn').style.display='inline';
		window.document.getElementById('safesearchOn').style.left=v+'px';
	}

	else
	{
		window.document.getElementById('safesearchOff').style.left=v+'px';
		window.document.getElementById('safesearchOff').style.display='inline';
	}
}
function CloseSafeSearch(val)
{
	window.document.getElementById('safesearchOff').style.display='none';
}
function CloseViewSafeSearch(val)
{
	window.document.getElementById('safesearchViewOff').style.display='none';
}

function getWindowWidth() {
var ww = 0;
if (self.innerWidth)
	ww = self.innerWidth;
else if (document.documentElement && document.documentElement.clientWidth)
	ww = document.documentElement.clientWidth;
else if (document.body)
	ww = document.body.clientWidth;
return ww;
}//getWindowWidth()

function SafeSearchAction(val,fname,URL)
{
	if(val=="yes")
	{set_cookie ("nsfwval","OFF","15/02/2190 00:00:00");}
	if(val=="no")
	{delete_cookie ("nsfwval");}
	if(fname=="index.php")
	{
		window.location.href=URL+fname+"?f=y";
	}
	else if(fname=="index.php?f=y")
	{
		window.location.href=URL+"index.php?f=y";
	}
	else
	{
		window.location.href=URL+fname+"&f=y";
	}	
}
function set_cookie ( name, value, exp_y)
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    cookie_string += "; expires=" + exp_y;
  }

  document.cookie = cookie_string;
}
function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}
function showInline (elName) {
var theElemenet = document.getElementById(elName);
if (theElemenet) {
	theElemenet.style.display = "inline";
}
}
function hideInline (elName) {
var theElemenet = document.getElementById(elName);
if (theElemenet) {
	theElemenet.style.display = "none";
}
}
function submitPagging(form,actionVal){
var ctr=eval("document."+form);
ctr.action=actionVal;
ctr.submit();
}
function MediaShowView(form,val)
{
var ctr=eval("document."+form);
ctr.mediashowview.value=val;
ctr.submit();
}
function LikeMedia(form,val,URL,ucount,dcount,mediaId)
{
	var ctr=eval("document."+form);
	ctr.mode.value="addotherrating";
	ctr.target="target_action";
	ctr.action=URL+"actions.php?mediaId="+mediaId+"&rateval="+val+"&ucount="+ucount+"&dcount="+dcount;
	ctr.submit();
}
function SortByMedia(form){
	var ctr=eval("document."+form);
	ctr.submit();
}

function spaceTrim(TRIM_VALUE)
{
	if(TRIM_VALUE.length < 1)
	{
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE=="")
	{
		return "";
	}
	else
	{
		return TRIM_VALUE;
	}
} //End Function


function RTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0)
	{
		return"";
	}
	var iTemp = v_length -1;
	while(iTemp > -1)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	} //End While
	return strTemp;
} //End Function

function LTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
	{
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	var iTemp = 0;
	while(iTemp < v_length)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function