// JavaScript Document

function Trim(sInString) 
{
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}

function popUp(URL,WinWidth,WinHeight) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=" + WinWidth + ",height=" + WinHeight + ",left = 312,top = 234');");
}

function wordCounter(field, countfield, maxlimit)
{ 
	field = document.getElementById(field);
	countfield = document.getElementById(countfield);
		
	wordcounter=0; 
	for (x=0;x<field.value.length;x++) 
	{ 
		if (field.value.charAt(x) == " " && field.value.charAt(x-1)!= " ") 
		{wordcounter++}
		if (wordcounter > 250) 
		{field.value = field.value.substring(0, x);} 
		else 
		{countfield.value = maxlimit - wordcounter;} 
	} 
} 

function textCounter(field, countfield, maxlimit) 
{ 
	field = document.getElementById(field);
	countfield = document.getElementById(countfield);
	
	if (field.value.length > maxlimit) 
	{
		field.value = field.value.substring(0, maxlimit);
	} 
	else 
	{
		countfield.value = maxlimit - field.value.length;
	} 
} 


function ChangeExternalLink()
{
	document.Frm_Menu.Link.value = document.Frm_Menu.exists.value;	
}

function GoAction(Do)
{
	if(MenuValidate(Frm_Menu)){
		
		if(Do == '1')
			document.Frm_Menu.action = 'menu.php?do=' + Do;	
		else
			document.Frm_Menu.action = 'action/menu.php';	
			
		document.Frm_Menu.submit();	
	}
}

function DeleteMenu()
{
	if(confirm("Are you sure about delete this Item?"))
	{	
		document.getElementById('do').value = "2";
		document.Frm_Menu.action = 'action/menu.php';		
		document.Frm_Menu.submit();	
	}
}

function MenuValidate(frmMenu)
{
	Title = frmMenu.title;
	
	msg1 = 'Please insert the title!';
	
	if (Trim(Title.value) == "")
	{
		alert(msg1) ;
		Title.focus() ;
		return false ;
	}
	else
		return true;
		
}

function CheckSearch()
{
	txtSearch = document.Frmsearch.Search;
	
	if(Trim(txtSearch.value) == ""){
		alert('Please enter the keyword!');
		txtSearch.focus();
		return false;	
	}	
	else
		return true;

}

function Search()
{	
	  txtkey = document.Frmsearch.key;	
	  if(CheckSearch())
	  {
		document.Frmsearch.action = "search.php?Value=0&pages=1&keys="+txtkey.value;
		document.Frmsearch.method = "post";
		document.Frmsearch.submit();
	 }
}

function changeKey()
{
	document.Frmsearch.key.value = document.Frmsearch.Search.value;
}

function changeColor(DIV,ch)
{
	if(ch == "1")
	document.getElementById(DIV).style.background = '#FF9900';		
	else
	document.getElementById(DIV).style.background = '#0189CA';
}

function ajaxpage(url,containerid)
{
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject)
	{
		try 
		{ page_request = new ActiveXObject("Msxml2.XMLHTTP")} 

			catch (e)
			{
				try{ page_request = new ActiveXObject("Microsoft.XMLHTTP")}
				catch (e){}
			}
		}
	else
	return false
	
	page_request.onreadystatechange=function()
	{
		loadpage(page_request, containerid)
	}
	page_request.open('POST', url, true)
	page_request.send(null)

} // End ajaxpage;

function loadpage(page_request, containerid)
{
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
		document.getElementById(containerid).innerHTML=page_request.responseText
	if(page_request.readyState != 4)
		onLoadingAction1(containerid)
} // End loadpage(page_request, containerid);

function onLoadingAction1(divLoading)
{
	document.getElementById(divLoading).innerHTML = '<table width="95%" align="center" class="contents"><tr><td align="center"><img src="../images/loading.gif" align="absbottom"/>&nbsp;<span class="Title">Loading...</span></td></tr></table>';	
}