//**** Validate User Signup ***//
function cateloguelogin()
{
	if(document.frmusersign.txtusername.value=="")
	{		
		alert("Enter Username");
		document.frmusersign.txtusername.focus();
		return false;
	}
	if(document.frmusersign.txtpassword.value=="")
	{		
		alert("Enter Password");
		document.frmusersign.txtpassword.focus();
		return false;
	}
	document.frmusersign.submit();
	return true;	
}


//**** Validate New User Registration ***//
function registration()
{
	if(document.frmregis.txtname.value=="")
	{		
		alert("Enter Name");
		document.frmregis.txtname.focus();
		return false;
	}
	if(document.frmregis.txtemail.value=="")
	{		
		alert("Enter Email");
		document.frmregis.txtemail.focus();
		return false;
	}
	if (echeck(document.frmregis.txtemail.value)==false)
	{
		document.frmregis.txtemail.value="";
		document.frmregis.txtemail.focus();				
		return false;
	}
	if(document.frmregis.txtusername.value=="")
	{		
		alert("Enter Username");
		document.frmregis.txtusername.focus();
		return false;
	}
	if(document.frmregis.txtpassword.value=="")
	{		
		alert("Enter Password");
		document.frmregis.txtpassword.focus();
		return false;
	}
	if(document.frmregis.txtconpassword.value=="")
	{		
		alert("Enter Confirm Password");
		document.frmregis.txtconpassword.focus();
		return false;
	}
	var pw1=document.frmregis.txtpassword.value;
	var pw2=document.frmregis.txtconpassword.value;
	if (pw1!=pw2)
	{
		alert("Password Mismatch");
		document.frmregis.txtconpassword.focus();
		return false;
	}
	if(document.frmregis.CaptchaCode.value=="")
	{		
		alert("Enter Security Code");
		document.frmregis.CaptchaCode.focus();
		return false;
	}
		document.frmregis.submit();
		return true;	
}

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 checkemail(str)
{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
	testresults=true;
	else{
	testresults=false;
	}
	return (testresults);
}
//**** Valid Cate Search by Date***//
function ValidSearchDate()
{
	if(document.frmSearDate.optdate.value=="0")
	{		
		alert("Please select Date");
		document.frmSearDate.optdate.focus();
		return false;
	}
		document.frmSearDate.submit();
		return true;	
}
//**** Valid Cate Search ***//
function ValidPublisher()
{
	if(document.frmSearPub.txtausearch.value=="")
	{		
		alert("Please Enter Search Keyword");
		document.frmSearPub.txtausearch.focus();
		return false;
	}
		document.frmSearPub.submit();
		return true;	
}
//**** Valid Cate Search ***//
function ValidCateSeaheader()
{
	if(document.frmSearch.txtsearch.value=="")
	{		
		alert("Please Enter Search Keyword");
		document.frmSearch.txtsearch.focus();
		return false;
	}
		document.frmSearch.submit();
		return true;	
}
function ValidCateSearch()
{
	if(document.frmCateSearch.txtsearch.value=="")
	{		
		alert("Please Enter Search Keyword");
		document.frmCateSearch.txtsearch.focus();
		return false;
	}
		document.frmCateSearch.submit();
		return true;	
}
//**** Valid Search ***//
function ValidCateSea()  
{	
	if(document.frmkeySearch.txtkeysearch.value=="")
	{		
		alert("Please Enter Search Keyword");
		document.frmkeySearch.txtkeysearch.focus();
		return false;
	}
		document.frmkeySearch.submit();
		return true;	
}
//var borrownum=document.frmSeartit.studhidden.value;
function titlesearch()
{
if(borrownum<=2)
	{ 
	var tbody = document.getElementById('idstudent').getElementsByTagName ("tbody")[1];
	k=borrownum;
	var row = document.createElement("TR");
	row.setAttribute("id", "fin"+k);

	var celltdlink = document.createElement("TD");
	celltdlink.setAttribute('colSpan',2);
	//celltdlink.colspan=2;
	celltdlink.setAttribute('align', 'left');
	celltdlink.innerHTML = "<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td  class='frmalign' width=35% style='text-align:left;padding-left:70px;'>Authorized Contact Person:</td><td   width=50% style='text-align:left;'><input type=text size=39 name='txtmanager" + k + "'></td></tr><tr><td     class='frmalign' style='text-align:right;'>Designation:</td><td style='text-align:left;'><input type=text size=39 name='txtdesign" + k + "'></td></tr><tr><td class='frmalign' style='text-align:right;'>E-mail Id:</td><td style='text-align:left;'><input type=text size=39 name='txtmaid" + k + "'></td></tr><tr><td class='frmalign' style='text-align:right;'>Phone Number:</td><td style='text-align:left;'><input type=text size=39 name='txtmaphone" + k + "'><a href=\"javascript:removefinance('fin" + k +"\');\" >Delete</a></td></tr></table>";

	
	row.appendChild(celltdlink);
	tbody.appendChild(row);
	borrownum++;
	ocument.resumeedit.txtmanager.focus();
	return false;
	}
	else
	{
		alert("Only two is allowable.  Cannot add anymore!!!");
	}
	
}

function removefinance(i)
{
	var elm = document.getElementById(i);
	document.getElementById("addnew").removeChild(elm);
	borrownum--;
}

function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != '' ) 
	{
		el.style.display = '';
	}
	else 
	{
		el.style.display = 'none';
	}
}


function confirmeditnews()
{
	var chk1="0123456789";
	var headlinesln=document.addnewsfrm.newsheadlines.value;
	year=document.addnewsfrm.year.value;

	if (year.length==0)
	{
		alert("Enter Year");
		document.addnewsfrm.year.focus();
		return;
	}

	for(var i=0; i<year.length; i++)
	{
		var index=chk1.indexOf(year.charAt(i));

		if(index==-1)
		{
			alert("Only Numbers Are Allowed In Year!");
			document.addnewsfrm.year.focus ();
			return ;
		}

	}

	if(headlinesln.length>2500)
	{
		alert("Brief Summary of News should be less than 2500 chars");
		document.addnewsfrm.newsheadlines.focus();
		return;
	}
	if(confirm("Are you Sure with the details entered ?"))
	{
		document.addnewsfrm.submit();
	}
}
	
/*
	$(document).ready(function() {

     //select all the a tag with name equal to modalwindow
     $('a[name=modalwindow]').click(function(e) {
         //Cancel the link behavior
         e.preventDefault();
         //Get the A tag
         var id = $(this).attr('href');

         //Get the screen height and width
         var hideHeight = $(document).height();
         var hideWidth = $(window).width();

         //Set heigth and width to hide to fill up the whole screen
         $('#hide').css({'width':hideWidth,'height':hideHeight});

         //transition effect
         $('#hide').fadeIn(1000);
         $('#hide').fadeTo("slow",0.8);

         //Get the window height and width
         var winH = $(window).height();
         var winW = $(window).width();

         //Set the popup window to center
         $(id).css('top',  winH/2-$(id).height()/2);
         $(id).css('left', winW/2-$(id).width()/2);

         //transition effect
         $(id).fadeIn(2000);

     }); 

     //if close button is clicked
     $('.window .close').click(function (e) {
         //Cancel the link behavior
         e.preventDefault();
         $('#hide, .window').hide();
     });

     //if hide is clicked
     $('#hide').click(function () {
         $(this).hide();
         $('.window').hide();
     });

 });*/

//**** Div For Search Show / Hide ***//
function showContent(vThis)
{
// http://www.javascriptjunkie.com
// alert(vSibling.className + " " + vDef_Key);
vParent = vThis.parentNode;
vSibling = vParent.nextSibling;
while (vSibling.nodeType==3) { // Fix for Mozilla/FireFox Empty Space becomes a TextNode or Something
vSibling = vSibling.nextSibling;
};
if(vSibling.style.display == "none")
{
vThis.src="images/date.jpg";
vThis.alt = "Hide Div";
vSibling.style.display = "block";
} else {
vSibling.style.display = "none";
vThis.src="images/date.jpg";
vThis.alt = "Show Div";
}
return;
}
function showContent1(vThis)
{
// http://www.javascriptjunkie.com
// alert(vSibling.className + " " + vDef_Key);
vParent = vThis.parentNode;
vSibling = vParent.nextSibling;
while (vSibling.nodeType==3) { // Fix for Mozilla/FireFox Empty Space becomes a TextNode or Something
vSibling = vSibling.nextSibling;
};
if(vSibling.style.display == "none")
{
vThis.src="images/title.jpg";
vThis.alt = "Hide Div";
vSibling.style.display = "block";
} else {
vSibling.style.display = "none";
vThis.src="images/title.jpg";
vThis.alt = "Show Div";
}
return;
}
//**** Div For Search Show / Hide ***//
function showContent(vThis)
{
// http://www.javascriptjunkie.com
// alert(vSibling.className + " " + vDef_Key);
vParent = vThis.parentNode;
vSibling = vParent.nextSibling;
while (vSibling.nodeType==3) { // Fix for Mozilla/FireFox Empty Space becomes a TextNode or Something
vSibling = vSibling.nextSibling;
};
if(vSibling.style.display == "none")
{
vThis.src="images/date.jpg";
vThis.alt = "Hide Div";
vSibling.style.display = "block";
} else {
vSibling.style.display = "none";
vThis.src="images/date.jpg";
vThis.alt = "Show Div";
}
return;
}
function showContent1(vThis)
{
// http://www.javascriptjunkie.com
// alert(vSibling.className + " " + vDef_Key);
vParent = vThis.parentNode;
vSibling = vParent.nextSibling;
while (vSibling.nodeType==3) { // Fix for Mozilla/FireFox Empty Space becomes a TextNode or Something
vSibling = vSibling.nextSibling;
};
if(vSibling.style.display == "none")
{
vThis.src="images/title.jpg";
vThis.alt = "Hide Div";
vSibling.style.display = "block";
} else {
vSibling.style.display = "none";
vThis.src="images/title.jpg";
vThis.alt = "Show Div";
}
return;
}

//**** Update Cart Functionalities  ***//

function UpdateCart()
{	
	document.CartUpdate.submit();
	//return true;
}