function fAddFavorite()
{
	var sTitle,sURL;
	sTitle	= "LeechVideo.com - download videos from youtube,google videos,etc.";
	sURL	= "http://www.leechvideo.com";
	if(document.all)
	{
		window.external.AddFavorite(sURL,sTitle);
	}else{
		window.sidebar.addPanel(sTitle, sURL, "");
	}
}
function getObject(objName)
{
		if(document.getElementById)
		{
			return eval('document.getElementById("' + objName + '")');
		}else if(document.layers){
			return eval("document.layers['" + objName +"']");
		}else{
			return eval('document.all.' + objName);
		}

}
function mysubmit()
{
	var mykeyword	= getObject("keyword").value;
	mykeyword	= mykeyword.replace(/\s+/g,"-")
	if(mykeyword!="")	location.href='/search/'+mykeyword;
}
function isOrbitInstalled()
{
	try {
		var obj = new ActiveXObject("Orbitmxt.Orbit");
		return true;
	} catch(err) {
		return false;
	}
}
function orbitTryDownload(url)
{
	try {
		var dlobj = new ActiveXObject("Orbitmxt.Orbit");
		dlobj.download(url, "", "", "");
		return true;
	} catch(e) {
		return false;
	}
}
function isdownflv(flv)
{
	if(navigator.userAgent.indexOf("MSIE")>=0)
	{
		if(isOrbitInstalled())
		{
			orbitTryDownload(flv);
			//location.href=flv;
		}else{
			alert('I\'m sorry,You can use Orbit to download this video,want to install now?');
			location.href='http://www.orbitdownloader.com/download.htm';
		}
	}else{
		location.href=flv;
	}
}
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function getCookie(cookie_name)
{
	var allcookies = document.cookie;
	var cookie_pos = allcookies.indexOf(cookie_name);

	// 如果找到了索引，就代表cookie存在，
	// 反之，就说明不存在。
	if (cookie_pos != -1)
	{
	// 把cookie_pos放在值的开始，只要给值加1即可。
	cookie_pos += cookie_name.length + 1;
	var cookie_end = allcookies.indexOf(";", cookie_pos);

	if (cookie_end == -1)
	{
		cookie_end = allcookies.length;
	}

	var value = unescape(allcookies.substring(cookie_pos, cookie_end));
	}

	return value;
}

function usergo()
{
	var mycookie = new Date((new Date()).getTime() + 24*60 * 60000);
	document.cookie = "sex=" + escape("permit")+ "; expires =" + mycookie.toGMTString() + "; path=" + "/" + "; _domain=" + "www.leechvideo.com";
	getObject('fade_div').style.display = 'none';
	getObject('sex_box').style.display = 'none';
	getObject('family_filter').innerHTML = "<a href='/SetFamilyFilter.html'>Off</a>";
	return false;
}

function changetest(background_hide)
{
	if(background_hide < 85 )
	{
		background_hide += 20;
		if(background_hide >= 85 ) background_hide = 85;
		getObject('fade_div').style.MozOpacity = "0." + background_hide;
		getObject('fade_div').style.opacity 	= "0." + background_hide;
		getObject('fade_div').style.filter		= "alpha(opacity=" + background_hide + ")";
		window.setTimeout( "changetest("+background_hide+")", 10 );
	}
	else
	{
		try
		{
			getObject('sex_box').style.display = 'block';
		}
		catch (e)
		{
		}
	}
}

function sexyn()
{
	if(getCookie("sex") == "permit")
	{
		try
		{
			getObject('family_filter').innerHTML = "<a href='/SetFamilyFilter.html'>Off</a>";
		}
		catch (e)
		{
		}
	}
	else
	{
		page_size = getPageSize();
		var str;
		str='<div id=\'sex_box\'><font color="#C1D82E">Family filter</font><img src="/img/hx.gif" /><font color="#FFFFFF"><BR />Turning OFF the family filter lists items intended for mature audiences.<br>This content may be offensive.<br>You must be over 18 to turn off the family filter.<BR /></font><BR /><center align="center"><A onclick="usergo(); return false" href="#null"><IMG src="/img/btn_go.gif"></A>&nbsp;&nbsp;&nbsp;&nbsp;<A href="/"><IMG src="/img/btn_cancel.gif"></A></center></div>';
		getObject('fade_div').innerHTML=str;
		getObject('fade_div').style.height = page_size ? page_size[1] + "px" : "100%";
		getObject('fade_div').style.display = 'block';
		var background_hide=0;
		changetest(background_hide);
		getObject('fade_div').focus();
	}
}
function check_family_filter()
{
	if(getCookie("sex") == "permit")
	{
		try
		{
			getObject('family_filter').innerHTML = "<a href='/SetFamilyFilter.html'>Off</a>";
		}
		catch (e)
		{
		}
	}
	else
	{
		try
		{
			getObject('family_filter').innerHTML = "<a href='/SetFamilyFilter.html'>On</a>";
		}
		catch (e)
		{
		}
	}
}
