var returnpath='';

function loginCheck(LoginCheck,SuccessURL)
{
	if(!LoginCheck)
		LoginCheck = 'logincheck.php';
	if(!SuccessURL)
		SuccessURL = 'forum/login_hid.php';
	returnpath=SuccessURL;
	document.frmLogin.actionurl.value=returnpath;
	/*if(SuccessURL.indexOf("documentsdownload.php")<0 && SuccessURL.indexOf("resource.php")<0 && SuccessURL.indexOf("resourcedownload.php")<0)
	{
		window.location="#LOGIN";
		showHideContentIndep('LoginDIV');
	}
	else
	{*/
		new Ajax.Request(LoginCheck,
		  {
			method:'post',
			onSuccess: function(transport){
			  var response = transport.responseText || "no response text";
			  if( response.indexOf("Success") >=0 )
			  {
				  window.location = SuccessURL;
			  }
			  else
			  {
			  		window.location="#LOGIN";
				  showHideContentIndep('LoginDIV');
			  }
			},
			onFailure: function(){ alert('login URL Failure') }
		  });	
	//}
}


	function BoxVuota(mystr)
	{ if (mystr.value=='')
	     { alert("Invalid data.");
		   mystr.focus();
	       return false;
	     }
	  return true;
	}
	
	
	
	function checkInvia(LocalPath)
	{
	if(!LocalPath) LocalPath ="";
	if(!returnpath) returnpath="memberadmin.php";
	if(returnpath=="") returnpath="memberadmin.php";
	currenturl=document.location.href;
	if(currenturl.indexOf('bis/')>=0 && (returnpath.indexOf('../securityresourcedownload.php')>=0 || returnpath.indexOf('../securitydocumentsdownload.php')>=0 || returnpath.indexOf('../memberadmin.php')>=0 || returnpath.indexOf('../directory/directory.php')>=0)) returnpath=returnpath.substring(3);
	if (BoxVuota(document.frmLogin.txtUsername) && BoxVuota(document.frmLogin.txtPassword))
	{
		return true;
		/*pars="txtUsername="+document.frmLogin.txtUsername.value+"&txtPassword="+document.frmLogin.txtPassword.value;
		 new Ajax.Request(LocalPath + 'loginbosco.php',
		  {
			method:'post',
			postBody:pars,
			onSuccess: function(transport){
			  var response = transport.responseText || "no response text";
			  if( response.indexOf("Success") >=0 )
			  {
				  window.location = LocalPath + returnpath;
			  }
			  else
			  {
			  	if(transport.responseText.indexOf("Welcome ")>=0 && transport.responseText.indexOf("approval")<0 && transport.responseText.indexOf("Deleted")<0 && transport.responseText.indexOf("suspended")<0)
			  	{
			  		window.location = LocalPath + returnpath;
			  	}
			  	else
			  	{
					DIVWrite('LoginFailure',transport.responseText);
					var LoginFailureDIV = document.getElementById('LoginFailure');
					LoginFailureDIV.style.display='block';
				}
			  }
			},
			onFailure: function(){ alert('login URL Failure') }
		  });	
		return false;*/
	}
	else
		{return false;}
	
	}
	
function DIVWrite(DIVID,DIVText)
{
	if(document.layers){
		fredlayer = document.layers[DIVID];
		fredlayer.document.open();
		fredlayer.document.write(DIVText);
		fredlayer.document.close();
			}

	if(document.all){
		fredlayer = document.all[DIVID];
		fredlayer.innerHTML=DIVText;
					 }

		if(document.getElementById){
		fredlayer = document.getElementById(DIVID);
		fredlayer.innerHTML =DIVText;
		 }

}

function AJAXURLCall(aObject,DIVToWrite,Sucessfn)
{	
	document.getElementById(DIVToWrite).innerHTML="<table border='0' width='100%' height='300'><td align=center><img src='http://donboscoindia.com/english/images/loading.gif' alt='loading' border=0></td></tr></table>";
	var URL = aObject.href.split('?');	
	if(URL[1])
		pars = URL[1];
	else
		pars = "";
	if(pars.indexOf("changetxt=Deleted")>=0 || pars.indexOf("delgroupid")>=0 || pars.indexOf("delofficeid")>=0)
	{
		if(!confirm("Are you sure to delete?"))
			return false;
	}
			new Ajax.Request(URL[0],
			  {
				method:'post',
				postBody:pars,
				onSuccess: function(transport){
				var response = transport.responseText || "no response text";
					DIVWrite(DIVToWrite,transport.responseText);
				if(Sucessfn!=null) eval(Sucessfn.replace("<SINGLEQUOTE>","'").replace("<SINGLEQUOTE>","'"));				
				},
				onFailure: function(){ alert('Under Construction');document.getElementById(DIVToWrite).innerHTML=""; }
			  });	
			return false;

}


function HelpShowMe()
{
	var HelpDIV = document.getElementById("HelpDIV");
	HelpDIV.style.visibility="visible";
	HelpDIV.style.display='';

}
function HelpHideMe()
{
	var HelpDIV = document.getElementById("HelpDIV");
	HelpDIV.style.visibility="hidden";
	HelpDIV.style.display='none';
	HelpDIV.style.top="10px";
	HelpDIV.style.left="250px";
}

function selectitemcategory()	{

	if(document.frmtopsearch.resourcetype.value=="none" ) {

		alert('Please Select The Category to Search For');
		frmtopsearch.resourcetype.focus();
		return false;
	}

	if(document.frmtopsearch.keyword.value=="" ) {

	alert('Please Enter the  Search Keyword ');
	document.frmtopsearch.keyword.focus();
	return false;
	}

	//Reassigning certain variables for some search topics
	if(document.frmtopsearch.resourcetype.value=="E" ) {
		document.frmtopsearch.ntarget.value='head';

	}
	else
		document.frmtopsearch.ntarget.value='any';

	if(document.frmtopsearch.resourcetype.value=="U" ) {
			document.frmtopsearch.cmbprovince.value='0';
			document.frmtopsearch.cmbhouse.value='0';
			document.frmtopsearch.cmbtarget.value='N';
	}


	//document.frmtopsearch.action="newssearch.php";
	document.frmtopsearch.submit();

	//document.frmtopsearch.submit();
}

  function ClassUpdateSuccess(MSG)
  {
	var aTag = document.createElement('a');
	var ahref = 'classifications.php?msg='+MSG;
	aTag.setAttribute('href',ahref);
	AJAXURLCall(aTag,"ra_centerpanel");
  }

  function ClassificationValid()
  {
  	changeallquotes("addclassfrm");
	var ClassName = document.getElementById("ClassificationName");
  	if(ClassName.value=="")
  	{
  		alert("Please Enter the Classification name");
  		ClassName.focus();
  		return false;
  	}
  	else
  		document.addclassfrm.submit();
  }


  function BISNowUpdateSuccess(MSG)
  {
	var aTag = document.createElement('a');
	var ahref = 'bisnow.php?msg='+MSG;
	aTag.setAttribute('href',ahref);
	AJAXURLCall(aTag,"ra_centerpanel");
  }

  function BISNowValid()
  {
  	changeallquotes("addBISNowfrm");
	var BISNowTitle = document.getElementById("BISNowTitle");
	var fromdate = document.getElementById("bisfromdate");
	var frommonth = document.getElementById("bisfrommonth");
	var fromyear = document.getElementById("bisfromyear");
	var todate = document.getElementById("bistodate");
	var tomonth = document.getElementById("bistomonth");
	var toyear = document.getElementById("bistoyear");
	if(BISNowTitle.value=="")
  	{
  		alert("Please Enter the Title");
  		BISNowTitle.focus();
  		return false;
  	}
	else if (bisfromdatevalid(fromdate.options[fromdate.options.selectedIndex].value,frommonth.options[frommonth.options.selectedIndex].value,fromyear.value)=="false")
	{
		alert("Enter the Valid From Date of Publish");
		fromdate.focus();
		return (true);
	}
	else if (bistodatevalid(todate.options[todate.options.selectedIndex].value,tomonth.options[tomonth.options.selectedIndex].value,toyear.value)=="false")
	{
		alert("Enter the Valid To Date of Publish");
		todate.focus();
		return (true);
	}
  	else
  		document.addBISNowfrm.submit();
  }
  
  
  function bisfromdatevalid(dt,mn,yr)
{
	var cdt=0,datt;
	if (mn=="Feb")

	if (isnewsleap(yr)=="true")
	cdt=29;

	else
	cdt=28;
	else
	if (mn=="Apr" || mn=="Jun" || mn=="Sep" || mn=="Nov" )
	cdt=30;
	else
	cdt=31;

	if(dt>cdt)
		return("false");
	else if(yr=="")
		return("false");
	else
	{
		datt=dt+"-"+mn+"-"+yr;
		document.getElementById("bisfromday").value=datt;
	}

}


function bistodatevalid(dt,mn,yr)
{
	var cdt=0,datt;
	if (mn=="Feb")

	if (isnewsleap(yr)=="true")
	cdt=29;

	else
	cdt=28;
	else
	if (mn=="Apr" || mn=="Jun" || mn=="Sep" || mn=="Nov" )
	cdt=30;
	else
	cdt=31;

	if(dt>cdt)
		return("false");
	else if(yr=="")
		return("false");
	else
	{
		datt=dt+"-"+mn+"-"+yr;
		document.getElementById("bistoday").value=datt;
	}

}

