function display_div(id){
	var target=document.getElementById(id);
	if(target.style.display==''){
			target.style.display='none';
	}else{
			target.style.display='';
	}
	return false;
}


function myfunction()
{
	alert("Coming Soon");
}
function validate_register(rform){

	var fname =document.getElementById("NewFirst").value;
	var lname =document.getElementById("NewLast").value;
	var email =document.getElementById("username1").value;
	var pass =document.getElementById("NewPassword").value;
	var confpass =document.getElementById("ConfNewPassword").value;
	//var dob =document.getElementById("d_BirthDate").value;
		
	if(fname==""){
		alert("Please enter your First Name!");
		return false;
	}
	if(lname==""){
		alert("Please enter your Last Name!");
		return false;
	}
	if(!CheckValidEmail(rform)){
		return false;
	}
	if(pass==""){
		alert("Please enter a Password!");
		return false;
	}	
	if(confpass==""){
			alert("Please enter a Confirmation Password!");
		return false;
	}
	if(pass!=confpass){
		alert("Password is not confirmed correctly please");
		return false;
	}
	
	return true;
}
function validate_register1(rform){

	var fname =document.getElementById("NewFirst").value;
	var lname =document.getElementById("NewLast").value;
	var pass =document.getElementById("Password").value;
	var confpass =document.getElementById("ConfPassword").value;
	
	
	if(fname==""){
		alert("Please enter your First Name!");
		return false;
	}
	if(lname==""){
		alert("Please enter your Last Name!");
		return false;
	}
	if((pass!="")&&(confpass=="")){
		alert("Please enter a Confirmation Password!");
		return false;
	}

	if(pass!=confpass){
		alert("Password not confirmed correctly.");
		return false;
	}
	return true;
}

function validate_password(rform){
	var passnew = rform.newpass.value;
	var passconf = rform.confpass.value;
	if(passnew.length==0){
		alert("Please enter a new password!");
		return false;
	}
	if(passconf.length==0){
		alert("Please confirm your new password!");
		return false;
	}
	if(passnew != passconf){
		alert("Password not confirmed correctly.");
		return false;
	}
	return true;
}

function validate_contactUs(cform){
	var fname=cform.fname.value;
	var comment= cform.comment.value;
	
	if(fname==""){
		alert("Please enter your First Name'!");
		return false;
	}

	if(!CheckValidEmail(cform)){
		return false;
	}
		
	if(comment==""){
		alert("Please write a comment!");
		cform.comment.focus();
		return false;
	}
	
	if(document.getElementById("code").value==""){
		alert("Please type in the characters!");
		document.getElementById("code").focus();
		return false;
	}

	return true;
	
}

function author(){
	document.getElementById("description").style.display="none";
	document.getElementById("author").style.display="";
	}
				
function overview(){
	document.getElementById("author").style.display="none";
	document.getElementById("description").style.display="";
}

function validate_book_form(rform){
	var title,isbn,page_number,synopsis;
	
	title=rform.t_bookTitle.value;
	synopsis=rform.synopsis.value;
	
	if(title.length==0){
		rform.t_bookTitle.focus();
		alert("Please enter book title.");
		return false;
	}
	
	if(synopsis.length==0){
		rform.synopsis.focus();
		alert("Please enter a synopsis.");
		return false;
	}
	
	if(isNaN(page_number)){
		rform.i_numberPages.focus();
		alert("Please enter number  of pages not a letter.");
		return false;
	}	
	
	var front_image = document.getElementById("front_image").value;
	var back_image = document.getElementById("back_image").value;
    	
    	if (front_image == ''){
	      alert("Please add a front image.");
	      return false;
	}
	
	if (back_image == ''){
	    //  alert("Please add a back image.");
	   //   return false;
	}
	
	return true;
}
function validate_book_form_add(rform){
	
	
	var title,isbn,page_number,synopsis,catg,langid;
	
	title=rform.t_bookTitle.value;
	synopsis=rform.synopsis.value;
	page_number=rform.i_numberPages.value;
	catg=rform.categoryName.value;
	LangIDv=rform.LangID.value;
	
	if(LangIDv.length==0){
		rform.LangID.focus();
		alert("Please select book language.");
		return false;
	}
	if(document.getElementById("categoryName").value==0){
		alert("Please select a category.");
		return false;
	}
	
	
	if(title.length==0){
		rform.t_bookTitle.focus();
		alert("Please enter book title.");
		return false;
	}
	
	if(synopsis.length==0){
		rform.synopsis.focus();
		alert("Please enter a synopsis.");
		return false;
	}
	
	if(document.getElementById("publisherID").value==0){
		alert("Please select a publisher.");
		return false;
	}
	
	if(document.getElementById("authorID").value==0){
		alert("Please select an author.");
		return false;
	}
	
	
	var front_image = document.getElementById("front_image").value;
	var back_image = document.getElementById("back_image").value;
    	
    	if (front_image == ''){
	      alert("Please add a front image.");
	      return false;
	}
	ar=front_image.split(".");
	ext=ar[ar.length-1].toLowerCase();
	if(ext!='jpg' && ext!='jpeg' && ext!='gif'){
		alert("Invalid File Type allowed: jpg,jpeg and gif");
		return false;
	}
	if (back_image == ''){
	     // alert("Please add a back image.");
	     // return false;
	}else{
		ar=back_image.split(".");
		ext=ar[ar.length-1].toLowerCase();
		if(ext!='jpg' && ext!='jpeg' && ext!='gif'){
			alert("Invalid File Type allowed: jpg,jpeg and gif");
			return false;
		}
	}
	
	var book_pdf = document.getElementById("book_pdf").value;
    if (book_pdf == ''){
	     // alert("Please add a pdf.");
	     // return false;
	}else{
		ar=book_pdf.split(".");
		ext=ar[ar.length-1].toLowerCase();
		if(ext!='pdf'){
			alert("Invalid File Type allowed: pdf");
			return false;
		}
	}	
    
		
	return true;
}
function validate_updatebook_admin(rform){
	var title,isbn,page_number,synopsis,catg,langid;
	
	title=rform.t_bookTitle.value;
	synopsis=rform.synopsis.value;
	page_number=rform.i_numberPages.value;
	catg=rform.categoryName.value;
	LangIDv=rform.LangID.value;
	
	if(LangIDv.length==0){
		rform.LangID.focus();
		alert("Please select book language.");
		return false;
	}
	if(document.getElementById("categoryName").value==0){
		alert("Please select a category.");
		return false;
	}
	
	
	if(title.length==0){
		rform.t_bookTitle.focus();
		alert("Please enter book title.");
		return false;
	}
	
	if(synopsis.length==0){
		rform.synopsis.focus();
		alert("Please enter a synopsis.");
		return false;
	}
	
	if(document.getElementById("publisherID").value==0){
		alert("Please select a publisher.");
		return false;
	}
	
	if(document.getElementById("authorID").value==0){
		alert("Please select an author.");
		return false;
	}
	
	
	var hasfrontimage = document.getElementById("hasfrontimage").value;
	if(hasfrontimage==0){
		var front_image = document.getElementById("front_image").value;
		if (front_image == ''){
		      alert("Please add a front image.");
		      return false;
		}
		ar=front_image.split(".");
		ext=ar[ar.length-1].toLowerCase();
		if(ext!='jpg' && ext!='jpeg' && ext!='gif'){
			alert("Invalid File Type allowed: jpg,jpeg and gif");
			return false;
		}	
	}
	
	var hasbackimage = document.getElementById("hasbackimage").value;
	if(hasbackimage==0){
		var back_image = document.getElementById("back_image").value;
	    	
	    	
		if (back_image == ''){
		      //alert("Please add a back image.");
		     // return false;
		}else{
			
			ar=back_image.split(".");
			ext=ar[ar.length-1].toLowerCase();
			if(ext!='jpg' && ext!='jpeg' && ext!='gif'){
				alert("Invalid File Type allowed: jpg,jpeg and gif");
				return false;
			}
		}
			
	}	
	
	
	var book_pdf = document.getElementById("book_pdf").value;
    if (book_pdf == ''){
	     // alert("Please add a pdf.");
	     // return false;
	}else{
		ar=book_pdf.split(".");
		ext=ar[ar.length-1].toLowerCase();
		if(ext!='pdf'){
			alert("Invalid File Type allowed: pdf");
			return false;
		}
	}	
    
	
	return true;
}
function validate_update_book_form(rform){
	
	if(document.getElementById("categoryName").value==0){
		alert("Please select a category.");
		return false;
	}
	if(document.getElementById("publisherID").value==0){
		alert("Please select a publisher.");
		return false;
	}
	if(document.getElementById("authorID").value==0){
		alert("Please select an author.");
		return false;
	}
	
	var hasfrontimage = document.getElementById("hasfrontimage").value;
	if(hasfrontimage==0){
		var front_image = document.getElementById("front_image").value;
		if (front_image == ''){
		      alert("Please add a front image.");
		      return false;
		}
		ar=front_image.split(".");
		ext=ar[ar.length-1].toLowerCase();
		if(ext!='jpg' && ext!='jpeg' && ext!='gif'){
			alert("Invalid File Type allowed: jpg,jpeg and gif");
			return false;
		}	
	}
	
	var hasbackimage = document.getElementById("hasbackimage").value;
	if(hasbackimage==0){
		var back_image = document.getElementById("back_image").value;
	    	
	    	
		if (back_image == ''){
		      //alert("Please add a back image.");
		      //return false;
		}else{
			
			ar=back_image.split(".");
			ext=ar[ar.length-1].toLowerCase();
			if(ext!='jpg' && ext!='jpeg' && ext!='gif'){
				alert("Invalid File Type allowed: jpg,jpeg and gif");
				return false;
			}
		}
			
	}
	
	var book_pdf = document.getElementById("book_pdf").value;
    if (book_pdf == ''){
	     // alert("Please add a pdf.");
	     // return false;
	}else{
		ar=book_pdf.split(".");
		ext=ar[ar.length-1].toLowerCase();
		if(ext!='pdf'){
			alert("Invalid File Type allowed: pdf");
			return false;
		}
	}	
    
	
	return true;
}
	function changeDisplay()
	{
							document.getElementById('authorimages').style.display="";
							document.getElementById('up').style.display="";
							document.getElementById('upu').style.display="";
							document.getElementById('upi').style.display="none";
							document.getElementById('bt').style.display="none";
	}
		function changeDisplayc()
	{
							document.getElementById('authorimages').style.display="none";
							document.getElementById('up').style.display="none";
							document.getElementById('upu').style.display="none";
							document.getElementById('upi').style.display="";
							document.getElementById('bt').style.display="";
	}
function changeDisplayf()
	{
							document.getElementById('front_image').style.display="";
							document.getElementById('up').style.display="";
							document.getElementById('upu').style.display="";
							document.getElementById('upi').style.display="none";
							document.getElementById('bt').style.display="none";
	}
		function changeDisplayfc()
	{
							document.getElementById('front_image').style.display="none";
							document.getElementById('up').style.display="none";
							document.getElementById('upu').style.display="none";
							document.getElementById('upi').style.display="";
							document.getElementById('bt').style.display="";
	}
function changeDisplayfb()
	{
							document.getElementById('back_image').style.display="";
							document.getElementById('upb').style.display="";
							document.getElementById('upub').style.display="";
							document.getElementById('upib').style.display="none";
							document.getElementById('btt').style.display="none";
	}
		function changeDisplayfbc()
	{
							document.getElementById('back_image').style.display="none";
							document.getElementById('upb').style.display="none";
							document.getElementById('upub').style.display="none";
							document.getElementById('upib').style.display="";
							document.getElementById('btt').style.display="";
	}
	function handler_num1(key){
 if ((key > 36 && key < 41) || key == 9 || key == 8 || key == 13 || key == 46 || key == 110 || key == 190 || (key > 47 && key < 58) || (key > 95 && key < 106))
  return true; 
 else
  return false;
}
function findPosY(objid){
	obj=document.getElementById(objid);
  var curtop = 0;
  if(obj.offsetParent)
      while(1)
      {
        curtop += obj.offsetTop;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.y)
      curtop += obj.y;
  return curtop;
}

function findPosX(obj)
{
   var curleft = 0;
   if(obj.offsetParent)
   while(1) 
   {
      curleft += obj.offsetLeft;
      if(!obj.offsetParent)
         break;
      obj = obj.offsetParent;
   }
   else if(obj.x)
      curleft += obj.x;
   return curleft;
}
function hide_all_selects(){
		var tags=document.getElementsByTagName('select');
		for(tg=0;tg<tags.length;tg++){
			tags[tg].style.display='none';
		}
	}
function show_all_selects(parentz){
	if(parentz!=1)
		var tags=document.getElementsByTagName('select');
	else
		var tags=parent.document.getElementsByTagName('select');
	for(tg=0;tg<tags.length;tg++){
		tags[tg].style.display='';
	}
}
function appendOptionLast(value,text){
  var elOptNew = parent.document.createElement('option');
  elOptNew.text = text;
  elOptNew.value = value;
  var elSel = parent.document.getElementById('authorID');

  try {
    elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    elSel.add(elOptNew); // IE only
  }
  fixOnSubmitparent();
}

function appendOptionLast_translator(value,text){
  var elOptNew = parent.document.createElement('option');
  elOptNew.text = text;
  elOptNew.value = value;
  var elSel = parent.document.getElementById('translatorID');

  try {
    elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    elSel.add(elOptNew); // IE only
  }
  fixOnSubmitparent();
}

function fixOnSubmit(){
 var oSelects = document.getElementById("authorID");

  for(var j=0; j<oSelects.options.length; j++){
   oSelects.options.item(j).selected = true;
  }
 return true;
}

function fixOnSubmitparent(){
 var oSelects = parent.document.getElementById("authorID");

  for(var j=0; j<oSelects.options.length; j++){
   oSelects.options.item(j).selected = true;
  }
 return true;
}
///////////////////////////////////////////////////////
function appendOptionLastpub(value,text){
  var elOptNew = parent.document.createElement('option');
  elOptNew.text = text;
  elOptNew.value = value;
  var elSel = parent.document.getElementById('publisherID');

  try {
    elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    elSel.add(elOptNew); // IE only
  }
  fixOnSubmitparentpub();
}
function fixOnSubmitpub(){
 var oSelects = document.getElementById("publisherID");

  for(var j=0; j<oSelects.options.length; j++){
   oSelects.options.item(j).selected = true;
  }
 return true;
}
function fixOnSubmitparentpub(){
 var oSelects = parent.document.getElementById("publisherID");

  for(var j=0; j<oSelects.options.length; j++){
   oSelects.options.item(j).selected = true;
  }
 return true;
}
//////////////////////////
function appendOptionLastCategoryy(value,text){
  var elOptNew = parent.document.createElement('option');
  elOptNew.text = text;
  elOptNew.value = value;
  var elSel = parent.document.getElementById('categoryName');

  try {
    elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    elSel.add(elOptNew); // IE only
  }
  fixOnSubmitparentCategoryy();
}
function fixOnSubmitCategoryy(){
 var oSelects = document.getElementById("categoryName");

  for(var j=0; j<oSelects.options.length; j++){
   oSelects.options.item(j).selected = true;
  }
 return true;
}
function fixOnSubmitparentCategoryy(){
 var oSelects = parent.document.getElementById("categoryName");

  for(var j=0; j<oSelects.options.length; j++){
   oSelects.options.item(j).selected = true;
  }
 return true;
}
//////////////////////////
function appendOptionLastCategory(value,text){
  var elOptNew = parent.document.createElement('option');
  elOptNew.text = text;
  elOptNew.value = value;
  var elSel = parent.document.getElementById('categoryName');

  try {
    elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    elSel.add(elOptNew); // IE only
  }
  fixOnSubmitparentCategory();
}
function fixOnSubmitCategory(){
 var oSelects = document.getElementById("categoryName");

  for(var j=0; j<oSelects.options.length; j++){
   oSelects.options.item(j).selected = true;
  }
 return true;
}
function fixOnSubmitparentCategory(){
 var oSelects = parent.document.getElementById("categoryName");

  for(var j=0; j<oSelects.options.length; j++){
   oSelects.options.item(j).selected = true;
  }
 return true;
}
/////////////////////////////////////////////////////////////////////////
function setCookie(NameOfCookie, value, expiredays){ 
        var ExpireDate = new Date(); 
        ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000)); 
        document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()); 
} 

function getCookie(NameOfCookie){ 
        if(document.cookie.length > 0){ 
                begin = document.cookie.indexOf(NameOfCookie+"="); 
                if(begin != -1){ 
                        begin += NameOfCookie.length+1; 
                        end = document.cookie.indexOf(";", begin); 
                        if (end == -1) end = document.cookie.length; 
                        return unescape(document.cookie.substring(begin, end)); 
                } 
        } 
        return null; 
}

function delCookie(NameOfCookie){ 
	if(getCookie(NameOfCookie)){ 
		document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; 
	} 
}


function checkLoginRemember(){
	var check = getCookie("aras_Login_Remember");
	if ((check==null) || (check==0)){
		return false;
	}else{
		return true;
	}
}

function AutoLogin(MForm){
	var check = checkLoginRemember();
	var uname = getCookie("aras_Login_Username");
	var pass = getCookie("aras_Login_Password");
	if(uname){
		document.getElementById(MForm).Logginusername.value = uname;
	}
	if (check==true && pass){
		document.getElementById(MForm).password.value = pass;
		document.getElementById(MForm).ifRemember.value = "yes";
		document.getElementById(MForm).submit();
	}
}
