var todoJS;
function loadjscssfile(filename, filetype){
	if (filetype=="js"){ //if filename is a external JavaScript file
		var fileref=document.createElement('script')
		fileref.setAttribute("type","text/javascript")
		fileref.setAttribute("src", filename)
	}
	else if (filetype=="css"){ //if filename is an external CSS file
		var fileref=document.createElement("link")
		fileref.setAttribute("rel", "stylesheet")
		fileref.setAttribute("type", "text/css")
		fileref.setAttribute("href", filename)
	}
	if (typeof fileref!="undefined")
	document.getElementsByTagName("head")[0].appendChild(fileref)
}

function makeHP()
{
	this.style.behavior='url(#default#homepage)';
	this.setHomePage(location.href);
	return false;
}

function HideContent(d, action) {
	if(action != 'validate')
	{
		var ttt = screen.height/2;
		if(d.length < 1) { return; }
		document.getElementById(d).style.display = "none";
		document.getElementById('blockUI').style.display = "block";
		document.getElementById('sheep').style.display = "block";
	}
	else
	{
		checkfileType('form_file_chooser', ".gif.jpg.png.jpeg.JPG");
	}
}


function getfileextension(inputId)
{
	var fileinput = document.getElementById(inputId);
	if(!fileinput ) return "";
	var filename = fileinput.value;
	if( filename.length == 0 ) return "";
	var dot = filename.lastIndexOf(".");
	if( dot == -1 ) return "";
	var extension = filename.substr(dot,filename.length);
	return extension;
}

function checkfileType(inputId,allowedExt)
{
	var ext = getfileextension(inputId);

	if( allowedExt.indexOf(ext) != -1)
	{
		document.getElementById('upload_form').submit();
		document.getElementById('widget').style.display = "none";
		document.getElementById('blockUI').style.display = "block";
		document.getElementById('sheep').style.display = "block";
	}
	else
	{
		document.getElementById('ftype').innerHTML = "<font color='Red'>invalid file type</font>";
		return false;
	}
}

function HideContent2() {

	document.getElementById('blockUI').style.display = "none";
	document.getElementById('widget').style.display = "none";
	document.getElementById('widget').innerHTML = "";
	document.getElementById('sheep').style.display = "none";
}
function EmbedData(method, url, element_id)
{
	var req = null;
	if (window.XMLHttpRequest)
	{
		try
		{
			req = new XMLHttpRequest();
		}
		catch(e) {}
	}
	else if (window.ActiveXObject)
	{
		try
		{
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e) {}
		if (!req)
		{
			try
			{
				req = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {}
		}
	}
	if (req)
	{
		req.open(method, url, true, null, null);
		req.setRequestHeader('Content-Type', 'application/octet-stream');
		req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
		req.send(null);
		req.onreadystatechange = function()
		{
			if (req.readyState == 4)
			{
				if(url.indexOf('todojs') == -1)
				{
					document.getElementById('widget').innerHTML = req.responseText;
				}
				else
				{
					loadjscssfile("http://youstyle.org/js/lp_utils_all_cookie.js", "js");

				}
			}
		};
	}

}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();

		date.setTime(date.getTime()+(days*24*60*60*1000));

		var expires = "; expires="+date.toGMTString();

	}

	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}




function hideTip(element, tip)
{
	if(tip == 'drag_tip')
	{
		document.getElementById('draggable').onmouseover = '';
	}
	var el = document.getElementById(element);
	if(el)
	{
		el.style.display = 'none';
		createCookie(tip, 'closed', 1000);
	}
}


function embedStats(url)
{
	var req = null;
	if (window.XMLHttpRequest)
	{
		try
		{
			req = new XMLHttpRequest();
		}
		catch(e) {}
	}
	else if (window.ActiveXObject)
	{
		try
		{
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e) {}
		if (!req)
		{
			try
			{
				req = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {}
		}
	}
	if (req)
	{
		req.open("GET", url, true, null, null);
		req.setRequestHeader('Content-Type', 'application/octet-stream');
		req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
		req.send(null);
		req.onreadystatechange = function()
		{
			if (req.readyState == 4)
			{
				
			}
		};
	}

}

function tipTrigger()
{
	var cook = document.cookie;
	if(cook.indexOf('drag_tip') == -1)
	{
		{
			document.getElementById('draggable').onmouseover =
			function onmouseover(event)
			{
				document.getElementById('tip_dragable').style.display = 'block';
			}
			document.getElementById('draggable').onmouseout =
			function onmouseover(event)
			{
				document.getElementById('tip_dragable').style.display = 'none';
			}
		}
	}
}



function ShowContent(d,url) {

	if(url.indexOf('help') != -1)
	{
		if(document.getElementById('home_tip'))
		{
			hideTip('tip_homepage', 'home_tip');
		}

		var cook = document.cookie;
		if(cook.indexOf('drag_tip') == -1)
		{
			document.getElementById('draggable').onmouseover =
			function onmouseover(event)
			{
				document.getElementById('tip_dragable').style.display = 'block';
			}
			document.getElementById('draggable').onmouseout =
			function onmouseover(event)
			{
				document.getElementById('tip_dragable').style.display = 'none';
			}
		}
	}
	if(url.indexOf('upload') != -1 && document.getElementById('right_arrow'))
	{
		
		document.getElementById('right_arrow').style.background = '';
		document.getElementById('left_arrow').style.background = '';
	}
	var objBody = document.getElementsByTagName('body').item(0);
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var objOverlay = document.getElementById('blockUI');
	if (isIE6()) {
		objOverlay.style.position = 'absolute';
	}
	objOverlay.style.display = 'block';
	objOverlay.style.height = arrayPageSize[1]+'px';
	document.getElementById(d).style.left = (arrayPageSize[0]/2 -250)+'px';
	document.getElementById('widget').style.display = "block";
	if(url.indexOf('todo') != -1)
	{
		EmbedData('GET', url, 'widget');
		EmbedData('GET', url+'js', 'widget');



	}
	else
	{
		EmbedData('GET', url, 'widget');
	}
}

function ReverseContentDisplay(d) {
	if(d.length < 1) { return; }
	if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
	else { document.getElementById(d).style.display = "none"; }
}

function reloadCaptcha()
{
	var rand = Math.round(Math.random() * 495643295);
	document.getElementById('kcaptcha').src = '/kcaptcha/index.php?'+rand+'='+rand;
}

// fade box position
function isIE6() {
	if (navigator.userAgent.indexOf("MSIE 6") > -1) {
		return true;
	}
	else {
		return false;
	}
}

function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){      // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}

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;
	}
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}
function formfocus() {
	document.getElementById('search_box').focus();
}
window.onload = formfocus;