//homepage.js

function echeck(str) 
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail ID");
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID");
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid E-mail ID");
	    return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid E-mail ID");
	    return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid E-mail ID");
	    return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid E-mail ID")
	    return false;
	 }

	 if (str.indexOf(" ")!=-1){
	    alert("Invalid E-mail ID")
	    return false;
	 }

	 return true					
}

function ValidateFormSendToEditor()
{
	var emailID=document.frmtoeditor.uemail;
	
	if (emailID.value.length>0) 
	{	
		if (echeck(emailID.value)==false)
		{
			emailID.value="";
			emailID.focus();
			return false;
		}
	}

	if(document.frmtoeditor.udetail.value.length==0) 
	{
		alert("Please enter Details");
		document.frmtoeditor.udetail.focus();
		return false;
	} 
	return true;
 }


function validateAdvanceSearch () 
{
	var iAtleastOneChecked=0;

	//
	if (document.getElementById('searchfor').value.length >0) 
	{
		iAtleastOneChecked=1;	
	}

	if (document.getElementById('ch_author').checked=='true' && document.getElementById('author').value.length >0) 
	{
		iAtleastOneChecked=1;	
	}
	/*	
	if (document.getElementById('ch_articletype').checked=='true' && document.getElementById('articletype').value.length >0) 
	{
		iAtleastOneChecked=1;	
	}
	*/
	if (document.getElementById('ch_channel').checked=='true' && document.getElementById('channel').value.length >0) 
	{
		iAtleastOneChecked=1;	
	}



	if (document.getElementById('ch_date').checked=='true') 
	{
		iAtleastOneChecked=1;	
	}
	
	if (iAtleastOneChecked ==1) 
	{
		return true;
	}else 
	{
		alert("Please select atleast one option for search.");
		return false;
	} 

	
}

function makeReadOnLy(oElement) 
{
	var iId = oElement.id.substr(3,oElement.id.length);

	var iSelect=0;
	if (iId =='articletype' || iId =='channel') iSelect=1;

	if(oElement.checked==true) 
	{
		document.getElementById(iId).value="";

		if (iSelect==0) 
		{ 
			document.getElementById(iId).readOnly="";	
		}else {
			document.getElementById(iId).disabled="";	
		}
	}else 
	{
		document.getElementById(iId).value="";
		if (iSelect==0) 
		{ 
			document.getElementById(iId).readOnly="true";	
		}else {
			document.getElementById(iId).disabled="true";	
		}


	}
}

function sSearch() 
{
	var search = document.form1.search.value;
	window.location="searchresult.php?query=" + search;
}

function showHideDateBlock(sFlag) 
{
	if (sFlag ==0)
	{
		document.getElementById('from').style.visibility='hidden';
		document.getElementById('to').style.visibility='hidden';
		document.getElementById('datetext').style.visibility='hidden';

		
	}else {
	
		document.getElementById('from').style.visibility='';
		document.getElementById('to').style.visibility='';
		document.getElementById('datetext').style.visibility='';

	}


}
