/****************************************
Title : General JS functions for Donbosco DO
Author : JJS Rajan
Date : --/--/--
Files Included :  --
Read Template  : --
Description : general javascript functions are here. 

Change Log : 
**********
Date : 03 Sep 2008	
Author : JJS Samuel
Description : function ClassificationValid() is included from donbosco main site. this function validate new classification addtion.

******************************************/

LoginOpen = false;

$(document).ready(function() {
	if(!LoginOpen)
		$('#LoginDIV').hide();
	$('a#loginLink').click(function() {
	    $('#LoginDIV').toggle(400);
	    return false;
	  });

	$('a#AdvancedSearch').click(function() {
	    $('#SubNewsSearch').toggle(400);
	    return false;
	  });
	$('a#AdvancedSearchRight').click(function() {
		$('#SubNewsSearch').toggle(400);
	    return false;
	  });
});

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 CategoryValid()
  {  	
  	if(document.addcatefrm.CategoryName.value=="")
  	{
  		alert("Please Enter the User Category");
  		document.addcatefrm.CategoryName.focus();
  		return false;
  	}
  	else
  		document.addcatefrm.submit();
  }
/*** Admin Login validation   ****/

function CheckInvia()
{
 if(
 	  (TestoVuoto(document.frmMailing.First_Name,"First Name")) ||
	  (ErrorString(document.frmMailing.First_Name,"First Name")) ||
	  (TestoVuoto(document.frmMailing.Last_Name,"Last Name"))||
	  (ErrorString(document.frmMailing.Last_Name,"Last Name")) ||
	  (TestoVuoto(document.frmMailing.City,"City")) ||
	  (TestoVuoto(document.frmMailing.Country,"Country")) ||
	  (TestoVuoto(document.frmMailing.Email,"E-mail")) ||
	  (ErrorEmail(document.frmMailing.Email)) ||
	  (TestoVuoto(document.frmMailing.Message,"Message")) 
	)
	 {return false;}
	else
	 {
	     SendMail();
	     return true;
	 }

}

function SendMailSuccess(error)
{
	var aTag = document.createElement('a');
	var ahref = 'contactuscenter.php?error='+error;
	aTag.setAttribute('href',ahref);
	AJAXURLCall(aTag,"innercenterpanel");
}
//password.js

function BoxVuota(mystr,msg)
{ 
	//alert(" String : "+mystr);
	if (mystr.value=='')
    { 
		alert("Please Enter "+msg);
		mystr.focus();
		return false;
    }
	return true;
}

function UserPassValidate()
{
	if(document.frmLogin.txtUsername.value=="")
	{
		alert("Enter the user name");
		document.frmLogin.txtUsername.focus();		
	}
	else if(document.frmLogin.txtPassword.value=="")
	{
		alert("Enter the password");
		document.frmLogin.txtPassword.focus();
	}
	else
		document.frmLogin.submit();
}

function checkInvialogin()
{
if ((BoxVuota(document.frmLogin.txtUsername,"UserName")) &&
	(BoxVuota(document.frmLogin.txtPassword,"Password")) &&
	(BoxVuota(document.frmLogin.txtNewPassword,"New Password")) &&
	(BoxVuota(document.frmLogin.txtConPassword,"Confirm Password"))
   )
{document.frmLogin.submit();}
else
	{return false;}
}


function LoginSuccess(msg,username,password,newpassword,conpassword,res,curpath)
{
	var aTag = document.createElement('a');
	var ahref = curpath + 'ChangePassword.php?message='+msg+'&txtUserName='+username+'&txtPassword='+password+'&txtNewPassword='+newpassword+'&txtConPassword='+conpassword+'&res='+res;
	aTag.setAttribute('href',ahref);
	AJAXURLCall(aTag,"LoginDIV");
}


function ForgotSuccess(msg,username,res,curpath)
{
	var aTag = document.createElement('a');
	var ahref = curpath + 'ForgetPassword.php?message='+msg+'&txtUserName='+username+'&res='+res;
	aTag.setAttribute('href',ahref);
	AJAXURLCall(aTag,"LoginDIV");
}

function checkInviapwd()
{
if (BoxVuota(document.frmLogin.txtUsername,"UserName"))
{document.frmLogin.submit();}
else
	{return false;}

}

/*** end of Login validation ****/  



function loginCheck(LoginCheck,SuccessURL)
{
	if(!LoginCheck)
		LoginCheck = 'logincheck.php';
	if(!SuccessURL)
		SuccessURL = 'forum/login_hid.php';
	returnpath=SuccessURL;
	document.frmLogin.actionurl.value=returnpath;
	pars = "";
	/*if(SuccessURL.indexOf("documentsdownload.php")<0 && SuccessURL.indexOf("resource.php")<0 && SuccessURL.indexOf("resourcedownload.php")<0)
	{
		window.location="#LOGIN";
		showHideContentIndep('LoginDIV');
	}
	else
	{*/
	
	
	 $.ajax({
			   type: "POST", url: LoginCheck,data: pars,
			   success: function(msg)
						{
						
			  if( msg.indexOf("Success") >=0 )
			  {
				  window.location = SuccessURL;
			  }
			  else
			  {
			  		window.location="#LOGIN";
				  //showHideContentIndep('LoginDIV');
				  $('#LoginDIV').show();
			  }
						
			}
			 });

/*
		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 ZoomImg(pno,tit,id)
{
	var mybars='directories=no,location=no,menubar=no,status=no';
	mybars +='titlebar=no,toolbar=no';
	var myOptions='scrollbars=yes,width=425,height=425,resizeable=yes';
	var myFeatures=mybars+','+myOptions;
	var newwin=open('NewsShowImage.php?pname='+pno+'&tit='+tit,'w'+id,myFeatures);
}
function validateformcomment()
{

	if(document.frmcomment.txtfrom.value=="")
	{
	alert("Please Enter the From Emailid ");
	document.frmcomment.txtfrom.focus();
	return false;
	}


	if(!validemailcomment(trimcomment(document.frmcomment.txtfrom.value)))	{
		alert("The From Emailid is not in Valid Format. Please Verify");
		document.frmcomment.txtfrom.focus();
		return false;

	}



	if(document.frmcomment.txtcomments.value=="")
		{
			alert("Please Enter your Comments");
			document.frmcomment.txtcomments.focus();
			return false;
	}
	
	if(document.frmcomment.CaptchaCode.value=="")
	{
			alert("Please Enter Security Code");
			document.frmcomment.CaptchaCode.focus();
			return false;
	}

	AjaxCommentSubmit();

}

function trimcomment(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function validemailcomment(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){

	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){

	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){

	    return false
	 }

	 if (str.indexOf(" ")!=-1){

	    return false
	 }

	 return true
}

function AjaxCommentSubmit()
{
	var aTag = document.createElement('a');
	var lochref=location.href;
	if(lochref.indexOf('bis/')>=0)
	{		
		var ahref = '../comments.php?txtfrom='+document.frmcomment.txtfrom.value+'&txtto='+document.frmcomment.txtto.value+'&txtcomments='+escape(document.frmcomment.txtcomments.value)+'&txttitle='+document.frmcomment.txttitle.value+'&CaptchaCode='+document.frmcomment.CaptchaCode.value+'&IsAjaxCall=1&CommentItem='+document.frmcomment.CommentItem.value;
	}
	else
	{		
		var ahref = 'comments.php?txtfrom='+document.frmcomment.txtfrom.value+'&txtto='+document.frmcomment.txtto.value+'&txtcomments='+escape(document.frmcomment.txtcomments.value)+'&txttitle='+document.frmcomment.txttitle.value+'&CaptchaCode='+document.frmcomment.CaptchaCode.value+'&IsAjaxCall=1&CommentItem='+document.frmcomment.CommentItem.value;
	}
	
	aTag.setAttribute('href',ahref);
	AJAXURLCall(aTag,"DIVComment");
}

	
//sendmail.js

function MailValidate(str)
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	 return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}
	 if (str.indexOf(at,(lat+1))!=-1){
		  return false
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
		 return false
	 }
	 if (str.indexOf(" ")!=-1){
		return false
	 }
	 return true
}

function validatemail()
{
	if(document.sendmailfrm.frommail.value=="")
	{
		alert("Please enter sender mail id");
		document.sendmailfrm.frommail.focus();
	}
	else if(MailValidate(document.sendmailfrm.frommail.value)==false)
	{
		alert("Please enter valid sender mail id");
		document.sendmailfrm.frommail.focus();
	}
	else if(document.sendmailfrm.tomail.value=="")
	{
		alert("Please enter receipiant mail id");
		document.sendmailfrm.frommail.focus();
	}
	else if(MailValidate(document.sendmailfrm.tomail.value)==false)
	{
		alert("Please enter valid receipiant mail id");
		document.sendmailfrm.frommail.focus();
	}
	else if(document.sendmailfrm.subjectmail.value=="")
	{
		alert("Please enter subject of the mail");
		document.sendmailfrm.subjectmail.focus();
	}
	else if(document.sendmailfrm.msgmail.value=="")
	{
		alert("Please enter message of the mail");
		document.sendmailfrm.msgmail.focus();
	}
	else
	{
		var aTag = document.createElement('a');
		var ahref = 'mail.php?officeid='+document.sendmailfrm.officeid.value+'&provinceid='+document.sendmailfrm.provinceid.value+'&groupid='+document.sendmailfrm.groupid.value+'&frommail='+document.sendmailfrm.frommail.value+'&tomail='+document.sendmailfrm.tomail.value+'&subjectmail='+document.sendmailfrm.subjectmail.value+'&bccmail='+document.sendmailfrm.bccmail.value+'&ccmail='+document.sendmailfrm.ccmail.value+'&msgmail='+document.sendmailfrm.msgmail.value;
		aTag.setAttribute('href',ahref);
		AJAXURLCall(aTag,"divCenterPanel");
	}
}

//fontchange.js

function change_class_class(oldClass1,oldClass2,newClass,textid)
{
    var allClass = new Array();
    allClass = getElementsByClassName(document, "*", oldClass1)
    for(var i=0; i<allClass.length; i++){
      allClass[i].className=newClass;
    }
    
    var allClass = new Array();
        allClass = getElementsByClassName(document, "*", oldClass2)
        for(var i=0; i<allClass.length; i++){
          allClass[i].className=newClass;
    }
    nowClass1 = newClass;
    nowClass2 = newClass;
    document.getElementById('ct1').style.textDecoration="none";
    document.getElementById('ct2').style.textDecoration="none";
    document.getElementById('ct3').style.textDecoration="none";
    document.getElementById('ct11').style.textDecoration="none";
    document.getElementById('ct22').style.textDecoration="none";
    document.getElementById('ct33').style.textDecoration="none";
    if(textid=='ct1' || textid=='ct11')
    {
    	document.getElementById('ct1').style.textDecoration="underline";
    	document.getElementById('ct11').style.textDecoration="underline";
    }
    else if(textid=='ct2' || textid=='ct22')
    {
    	document.getElementById('ct2').style.textDecoration="underline";
    	document.getElementById('ct22').style.textDecoration="underline";
    }
    else if(textid=='ct3' || textid=='ct33')
    {
    	document.getElementById('ct3').style.textDecoration="underline";
    	document.getElementById('ct33').style.textDecoration="underline";
    }
}

  
  function getElementsByClassName(oElm, strTagName, strClassName)
  {
      var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
      var arrReturnElements = new Array();
      strClassName = strClassName.replace(/\-/g, "\\-");
      var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
      var oElement;
      for(var i=0; i<arrElements.length; i++){
          oElement = arrElements[i];      
          if(oRegExp.test(oElement.className)){
              arrReturnElements.push(oElement);
          }   
      }
      return (arrReturnElements)
  }

//*** Function for Home top search ****/  
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;
	}
		
	if(document.frmtopsearch.resourcetype.value=="A" )
	{		
		document.frmtopsearch.type.value="all";
		document.frmtopsearch.ntarget.value="head";		
		document.frmtopsearch.action="albumresult.php";		
		document.frmtopsearch.submit();		
	}	
	
	
	//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.submit();	
}

  
// Function for Contactus page 
function ContactUsPageAjax(FirstName,LastName,City,Country,Email,Subject,Message,CaptchaCode)
{
	var aTag = document.createElement('a');	
	var ahref = 'SendContactUsMail.php?action=ContactusPage&FirstName='+escape(FirstName)+'&LastName='+escape(LastName)+'&City='+escape(City)+'&Country='+escape(Country)+'&Email='+escape(Email)+'&Subject='+escape(Subject)+'&Message='+escape(Message)+'&CaptchaCode='+escape(CaptchaCode);
	aTag.setAttribute('href',ahref);
	AJAXURLCall(aTag,"divCenterPanel");
}

// Function forPhotogallery
 function ZoomImgFullPhoto(pno,tit,ptit,des,id,w,h)
 {
 w=w+100;h=h+100;
 w=780;h=600;
 var mybars='location=no,menubar=no,status=no';
 mybars +='toolbar=no';
 var myOptions=' scrollbars=yes,width='+w+',height='+h+',resizable=yes';
 var myFeatures=mybars+','+myOptions;
 var newwin=open('galleryshowimagefull.php?pname='+pno+'&tit='+tit+'&ptit='+ptit+'&des='+des,'w'+id,myFeatures);
}

function ZoomImgPhoto(FromWhere,AlbumId,pno,tit,ptit,des,id,w,h)
{	
	w=w+100;h=h+100;
	w=800;h=700;
	var mybars='location=0,menubar=0,status=no';
	mybars +='toolbar=no';
	var myOptions=' scrollbars=1,width='+w+',height='+h+',resizable=yes';
	var myFeatures=mybars+','+myOptions;
	//var newwin=open('../galleryshowimage.php?pname='+pno+'&tit='+tit+'&ptit='+ptit+'&des='+des,'w'+id,myFeatures);	
	var newwin=open('galleryshowimagefull.php?sshow=1&AlbumId='+AlbumId+'&pname='+pno+'&tit='+tit+'&ptit='+ptit+'&des='+des+'&FromWhere='+FromWhere,'w'+id,myFeatures);
}

function ZoomImgPhotoSearch(str,pno,tit,id,width,height)
{
var mybars='directories=no,location=no,menubar=no,status=no';
mybars +='titlebar=no,toolbar=no';
var myOptions='scrollbars=yes,width='+width+',height='+height+',resizeable=yes';
var myFeatures=mybars+','+myOptions;
var newwin=open(str+'photoshowimage.php?pname='+pno+'&tit='+tit,'w'+id,myFeatures);
}
//Show Main Photo when click the Thumbnail Icon Param=photoid,albumlocaton,photoname
function ShowMainPhoto(intid,intalbumlocation,chrphotoname)
{
	var aTag = document.createElement('a');
	var ahref = 'ShowMainPhoto.php?PhotoId='+intid+'&PathLocation='+intalbumlocation+'&PhotoName='+chrphotoname;
	
	aTag.setAttribute('href',ahref);
	AJAXURLCall(aTag,"ShowMainPhoto");
}

//*** Open Search Div -- bottom right of the banner ****//
function OpensearchDiv()
{	
	document.getElementById("SearchDiv").style.display='';	
	document.getElementById("SearchImgDiv").style.display='none';
	//document.frmtopsearch.keyword.value="";
	document.frmtopsearch.keyword.focus();
}
function CloseSearchDiv()
{
	document.getElementById("SearchDiv").style.display='none';	
	document.getElementById("SearchImgDiv").style.display='';
}
//***  Ends of Search div  ****//