/* ************* COMMON FUNCTION  STARTS **************  */

	var email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
	//var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
	//var phone=/(^\d{3}-\d{3}-\d{4}$)/;
	var phone=/^\d(\d|-){7,20}/;
	var dateExp=/(^\d{2}[//]\d{2}[//]\d{4}$)/
	var image=/(\.bmp|\.gif|\.jpg|\.jpeg)$/i
	var csv=/(\.csv|\.CSV|\.xls|\.XLS)$/i
	var currency = /^\d*(?:\.\d{0,2})?$/;

var regex = /^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;



function alphanumeric(alphane)
{
	// onSubmit="return alphanumeric(test.mailf.value)">
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
		else	{
                 //        alert("Your Alpha Numeric Test Failed");
			 return false;
		  }
 		}
// alert("Your Alpha Numeric Test Passed");
 //return true;

}
function alphanumeric_copy(alphane)
{
	// onSubmit="return alphanumeric(test.mailf.value)">
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
		else	{
              alert("Your Alpha Numeric Test Failed");
			 return false;
		  }
 		}
 alert("Your Alpha Numeric Test Passed");
 return true;

}

/*
function SetStatus(message)
{
    window.status=message;
}*/
function ltrim(string){
    string=new String(string);
    var string1=new Array();
    var i,j;
    for(i=0,j=0;i<string.length;i++)
    {
      if(j==0)
      {
        if(string.charAt(i)!=" ")
        {
            string1[j++]=string.charAt(i);
        }
      }
      else
      {
        string1[j++]=string.charAt(i);
      }
        
    }
    string="";
    for(i=0;i<string1.length;i++)
    {
      string+=string1[i];
    } 
    return string;
  }

function rtrim(string)
  {
    string=new String(string);
    var string1=new Array();
    var i,j;
    for(i=string.length;i>=0;i--)
    {
      if(string.charAt(i-1)==" ")
      {
        continue;
      }
      else
      {
        for(j=0;j<i;j++)
        {
          string1[j]=string.charAt(j);
        }
        break;
      }
        
    }
    string="";
    for(i=0;i<string1.length;i++)
    {
      string+=string1[i];
    }
    
    
    return string;
  }
  
  function trim(string)
  {
    string=ltrim(string); // // This function is used to trim the left side of a String
    string=rtrim(string);// This function is used to trim the right side of a String
    return string;
  }

function isDate1(regDate)
{
	if(!dateExp.test(regDate))
	{
		alert("Please enter a valid date in the format(mm/dd/yyyy).");		
		return false;
	}
	else if(parseInt(regDate.substr(0,2))>12)
	{
		alert("Please enter valid month.");		
		return false;
	}
	else if(parseInt(regDate.substr(3,2))>31)
	{	
		alert("Please enter valid day.");		
		return false;
	}
	else if(parseInt(regDate.substr(6,4))<1900 || parseInt(regDate.substr(6,4))>2005)
	{	
		alert("Please enter valid year.");		
		return false;
	}
	else
		return true;
}




// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2005;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}



function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '&pound;' + num + '.' + cents);
}

function showImage(imageName)
{


window.open("showimage.php?image="+imageName,"Image","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,bgcolor=FFFFFF,width=700,height=600");

}



//auto complete starts

function lookup(inputString) {
		if(inputString.length == 0) {
			// Hide the suggestion box.
			$('#suggestions').hide();
		} else {
			$.post("rpc.php", {queryString: ""+inputString+""}, function(data){
				if(data.length >0) {
					$('#suggestions').show();
					$('#autoSuggestionsList').html(data);
				}
			});
		}
	} // lookup
	
	function fill(thisValue) {
		$('#inputString').val(thisValue);
		setTimeout("$('#suggestions').hide();", 200);
	}

//auto complete ends



/* common function ends */




function showPick()
{
	document.getElementById("pick").style.display="block";
	document.getElementById("photo").style.display="none";
}

function showPhoto()
{
	document.getElementById("pick").style.display="none";
	document.getElementById("photo").style.display="block";
}



/* function is used to validate admin login form(login.php)*/
function validateLogin()
{
		if(trim(document.frmLogin.UserName.value) == ""){
		alert("Please enter UserName.");
		document.frmLogin.UserName.focus();
		//return false;
	}
	else if(trim(document.frmLogin.Password.value) == ""){
		alert("Please enter Password.");
		document.frmLogin.Password.focus();
		//return false;
	}
	else{
		pageName= document.frmPageName.pageName.value;
		document.frmLogin.action="logincheck.php?pageName="+pageName;
		document.frmLogin.submit();
		//return true;	
	}
}

function showLogin()
{
	document.getElementById("login").style.display="block";
	document.getElementById("forgetpassword").style.display="none";
	document.getElementById("signup").style.display="none";
	//if(document.getElementById("message") != null))
	document.getElementById("message").style.display="none";
}

function showForget()
{
	document.getElementById("login").style.display="none";
	document.getElementById("forgetpassword").style.display="block";
	document.getElementById("signup").style.display="none";
	//if(document.getElementById("message") != null))
	//document.getElementById("message").style.display="none";
}

function showSignUp()
{
	document.getElementById("login").style.display="none";
	document.getElementById("forgetpassword").style.display="none";
	document.getElementById("signup").style.display="block";

	//if(document.getElementById("message") != null))
	//document.getElementById("message").style.display="none";

}


function showEdit()
{
	document.getElementById("editprofile").style.display="block";
	
	//if(document.getElementById("message") != null))
	//document.getElementById("message").style.display="none";
}

// forget password

function validateForgetPassword()
{
	if(trim(document.frmForget.Email.value) == ""){
		alert("Please enter Email.");
		document.frmForget.Email.focus();
		//return false;
	}
	else if(!email.test(document.frmForget.Email.value))
	{
	  	alert("Invalid email address.");
	  	document.frmForget.Email.focus();
	  	// return false;
	}
	else{
		pageName= document.frmPageName.pageName.value;
		document.frmForget.action="forgetpassword.php?pageName="+pageName;
		document.frmForget.submit();
		//return true;	
	}
}




function validateUser()
{
	//alert(alphanumeric(trim(document.frmUser.UserName.value)));
	if(trim(document.frmUser.Name.value) == ""){
		alert("Please enter Name.");
		document.frmUser.Name.focus();
		//return false;
	}
	else if(trim(document.frmUser.UserName.value) == ""){
		alert("Please enter UserName.");
		document.frmUser.UserName.focus();
		//return false;
	}
	else if(alphanumeric(trim(document.frmUser.UserName.value))==false)
	{
		alert("Please enter alphanumeric (a-z) and (0-9) values for UserName.");
		document.frmUser.UserName.focus();
		//	return false;
	
	}
	else if(trim(document.frmUser.Password.value) == ""){
		alert("Please enter Password.");
		document.frmUser.Password.focus();
		//return false;
	}
	else if(trim(document.frmUser.ConfirmPassword.value) == ""){
		alert("Please enter Confirm Password.");
		document.frmUser.ConfirmPassword.focus();
		//return false;
	}
	else if(trim(document.frmUser.Password.value) != trim(document.frmUser.ConfirmPassword.value)){
		alert("Password mismatch.");
		document.frmUser.ConfirmPassword.focus();
		//return false;
	}
	else if(trim(document.frmUser.Email.value) == ""){
		alert("Please enter Email.");
		document.frmUser.Email.focus();
		//return false;
	}
	else if(!email.test(document.frmUser.Email.value))
	{
	  	alert("Invalid email address.");
	  	document.frmUser.Email.focus();
	  	// return false;
	}
	
	else{
		pageName= document.frmPageName.pageName.value;
		document.frmUser.action="adduser.php?pageName="+pageName;
		document.frmUser.submit();
		//return true;	
	}
}




function validateUserEdit()
{
	//alert(alphanumeric(trim(document.frmUser.UserName.value)));
	if(trim(document.frmUser.Name.value) == ""){
		alert("Please enter Name.");
		document.frmUser.Name.focus();
		//return false;
	}
	else if(trim(document.frmUser.UserName.value) == ""){
		alert("Please enter UserName.");
		document.frmUser.UserName.focus();
		//return false;
	}
	else if(alphanumeric(trim(document.frmUser.UserName.value))==false)
	{
		alert("Please enter alphanumeric (a-z) and (0-9) values  for UserName.");
		document.frmUser.UserName.focus();
		//	return false;
	
	}
	else if(trim(document.frmUser.Password.value) != "" && trim(document.frmUser.ConfirmPassword.value) == ""){
		alert("Please enter Confirm Password.");
		document.frmUser.ConfirmPassword.focus();
		//return false;
	}
	else if(trim(document.frmUser.Password.value) != trim(document.frmUser.ConfirmPassword.value)){
		alert("Password mismatch.");
		document.frmUser.ConfirmPassword.focus();
		//return false;
	}
	else if(trim(document.frmUser.Email.value) == ""){
		alert("Please enter Email.");
		document.frmUser.Email.focus();
		//return false;
	}
	else if(!email.test(document.frmUser.Email.value))
	{
	  	alert("Invalid email address.");
	  	document.frmUser.Email.focus();
	  	// return false;
	}
	
	else{
		pageName= document.frmPageName.pageName.value;
		document.frmUser.action="adduser.php?pageName="+pageName;
		document.frmUser.submit();
		//return true;	
	}
}





function validatePost()
{


	 if(trim(document.frmPost.CategoryName.value) == ""){
		alert("Please select category Name");
		document.frmPost.CategoryName.focus();
		//return false;
	}
	
	
	else if(trim(document.frmPost.PostName.value) == ""){
		alert("Please enter Title.");
		document.frmPost.PostName.focus();
		//return false;
	}
		else if(trim(document.getElementById("transliterateTextarea").value) == ""){
		alert("Please enter Post.");
		document.getElementById("transliterateTextarea").focus();
		//return false;
	}
	else{
		//return true;
		document.frmPost.action="addpost.php?type=post";
		document.frmPost.submit();
	}
		
}


function validateDraft()
{


	 if(trim(document.frmPost.CategoryName.value) == ""){
		alert("Please select category Name");
		document.frmPost.CategoryName.focus();
		//return false;
	}
	
	
	else if(trim(document.frmPost.PostName.value) == ""){
		alert("Please enter Title.");
		document.frmPost.PostName.focus();
		//return false;
	}
		else if(trim(document.getElementById("transliterateTextarea").value) == ""){
		alert("Please enter Post.");
		document.getElementById("transliterateTextarea").focus();
		//return false;
	}
	else{
		//return true;
		document.frmPost.action="addpost.php?type=draft";
		document.frmPost.submit();
	}
		
}


function validateComment()
{

 if(trim(document.frmComment.CommentName.value) == ""){
		alert("Please enter Title.");
		document.frmComment.CommentName.focus();
		//return false;
	}
		else if(trim(document.getElementById("transliterateTextarea").value) == ""){
		alert("Please enter Comment.");
		document.getElementById("transliterateTextarea").focus();
		//return false;
	}
	else{
		//return true;
		document.frmComment.action="addcomment.php";
		document.frmComment.submit();
	}
		
}



function validatePhoto()
{
if(trim(document.frmPhoto.file.value) == ""){
		alert("Please select a photo.");
		document.frmPhoto.file.focus();
		//return false;
	}
		
	else{
		//return true;
	//return true;
		document.frmPhoto.action="uploadphoto.php";
		document.frmPhoto.submit();
	}
	
}





function validateMessage()
{


		
	 if(trim(document.frmMessage.MessageName.value) == ""){
		alert("Please enter Message Title.");
		document.frmMessage.MessageName.focus();
		//return false;
	}
		else if(trim(document.getElementById("transliterateTextarea").value) == ""){
		alert("Please enter Message.");
		document.getElementById("transliterateTextarea").focus();
		//return false;
	}
	else{
		//return true;
		document.frmMessage.action="addmessage.php";
		document.frmMessage.submit();
	}
		
}

function showImage(imageName)
{
window.open("showimage.php?image="+imageName,"Image","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,bgcolor=FFFFFF,width=700,height=600");
}

function editPost(Pid,Cid)
{
	document.frmPageName.pid.value=Pid;
	document.frmPageName.cid.value=Cid;
	document.frmPageName.action="submitpost.php";
	document.frmPageName.submit();
}
function deletePost(Pid,Cid)
{
	document.frmPageName.pid.value=Pid;
	document.frmPageName.cid.value=Cid;
	document.frmPageName.action="deletepost.php";
	document.frmPageName.submit();
}


function editComment(Pid,Cid,Cuid)
{
	document.frmPageName.pid.value=Pid;
	document.frmPageName.commentid.value=Cid;
	document.frmPageName.cuid.value=Cuid;

	document.frmPageName.action="submitcomment.php";
	document.frmPageName.submit();
}
function deleteComment(Pid,Cid,Cuid,Catid)
{
	document.frmPageName.pid.value=Pid;
	document.frmPageName.commentid.value=Cid;
	document.frmPageName.cuid.value=Cuid;

	//document.frmPageName.cid.value=Catid;
	
	document.frmPageName.action="deletecomment.php";
	document.frmPageName.submit();
}



function deletePhoto(photoname)
{
	document.frmPageName.photoname.value=photoname;
	document.frmPageName.action="deletphoto.php";
	document.frmPageName.submit();

}


function validateContactus()
{


		
	 if(trim(document.frmContact.Name.value) == ""){
		alert("Please enter Name.");
		document.frmContact.Name.focus();
		//return false;
	}
	else if(trim(document.frmContact.Email.value) == ""){
		alert("Please enter Email.");
		document.frmContact.Email.focus();
		//return false;
	}
	else if(!email.test(document.frmContact.Email.value))
	{
	  	alert("Invalid email address.");
	  	document.frmContact.Email.focus();
	  	// return false;
	}
		else if(trim(document.frmContact.Message.value) == ""){
		alert("Please enter Message.");
		document.frmContact.Message.focus();
		//return false;
	}
	else{
		//return true;
		document.frmContact.action="sendmail.php";
		document.frmContact.submit();
	}
		
}
