/**
* MyIntents - Client-Side Scripts
*
* LICENSE: This file belongs to My Intents
*
* @category   JavaScript
* @package    script.js
* @author     Gullam Hussain S (gullam.s@myintents.com)
* @copyright  2007-2008 My Intents
* @version    1.0
* @link       http://myintents.com/js/script.js
* @see        script.js
* @since      File available since Release 1.0.x
* @deprecated File Not yet deprecated
*/
function Ltrim(val)//to remove the white spaces from LEFT that are in the text box
{
var temp=val;
for(var i=0;i< temp.length;i++)
{
if(temp.substr(i,i)==" ")
temp=temp.substr(1,temp.length-1);
else
break;
}

return val;
}


function Rtrim(val)//to remove the white spaces from RIGHT that are in the text box
{

var temp=val;

for(var i=temp.length-1;i<=0;i--)
{
if(temp.substr(i,i)==" ")
temp=temp.substr(0,temp.length-2);
else
break;
}
return val;
}

function trim(val)
{
return Ltrim(Rtrim(val));
}

function addComment(theForm){
	var cont=1;
	if(trim(theForm.description.value)==''){
		alert('Enter comments');
		return false;
	}
	theForm.description.value=theForm.description.value.replace(/\n/g,'<br>');
	var theDiv = 'Comment'+theForm.section_record_id.value;
	var status = AjaxRequest.submit(
		theForm
		,{
			'onSuccess':function(req){ 
				req.responseText=req.responseText.replace(/&lt;/g,"<");
				req.responseText=req.responseText.replace(/&gt;/g,">");
				document.getElementById(theDiv).innerHTML = req.responseText; 
				if(document.getElementById("comment_"+theForm.section_record_id.value).innerHTML == "Add Comments") {
					document.getElementById("comment_"+theForm.section_record_id.value).innerHTML = "Add / Show Comments ("+cont+")";
					document.getElementById("commenth_"+theForm.section_record_id.value).innerHTML = "Hide Comments ("+cont+")";
					
				}
				else {
					 var count=document.getElementById("comment_"+theForm.section_record_id.value).innerHTML;
					 count=count.substring(21,23);
					 cont=parseInt(count)+1;
					 document.getElementById("comment_"+theForm.section_record_id.value).innerHTML = "Add / Show Comments ("+cont+")";
				     document.getElementById("commenth_"+theForm.section_record_id.value).innerHTML = "Hide Comments ("+cont+")";
				}
			}
			,'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
		}
	);
	return false;
}


function setAllSectionAccess(frm,access) {
	if(access == 0)
	for(i=1;i<13;i++) {
		if(frm.elements['access_status_'+i])
		frm.elements['access_status_'+i][0].checked = true;
	}
	if(access == 1) 
	for(i=1;i<13;i++) {
		if(frm.elements['access_status_'+i])
		frm.elements['access_status_'+i][2].checked = true;
	}
	if(access == 2)
	for(i=1;i<13;i++) {
		if(frm.elements['access_status_'+i])
		frm.elements['access_status_'+i][1].checked = true;
	}
}

function hideComments(theDiv,section_record_id){

document.getElementById('links_'+section_record_id).style.display = 'none';
var objDiv = document.getElementById(theDiv);

					if(objDiv.style.display=='block')
						objDiv.style.display='none';

}
function showContent_explore(status, id) {
	//alert(status+'short_'+id);
	//alert(id+'long_'+id);
	if(status == 1) {	// display long content
		document.getElementById('links_'+id).style.display = 'block';
		document.getElementById('short_'+id).style.display = 'none';
		document.getElementById('long_'+id).style.display = 'block';
		//document.getElementById('edit_'+id).style.display = 'none';
	}
	else if(status == 2) {	// display sort content
		document.getElementById('links_'+id).style.display = 'block';
		document.getElementById('short_'+id).style.display = 'block';
		document.getElementById('long_'+id).style.display = 'none';
		//document.getElementById('edit_'+id).style.display = 'none';
	}
	else{}
	//return false;
}

function showComments_old(mode, section_id, section_record_id, theDiv){
	
var qry_str = document.location.href;

if(qry_str.indexOf('comments=1')!=-1)
	var pageURL = "comments.php?section_id="+section_id+"&section_record_id="+section_record_id+"&comments=1";
else
	var pageURL = "comments.php?section_id="+section_id+"&section_record_id="+section_record_id;
//alert(pageURL);
	var status = AjaxRequest.get(
		{
			'url':pageURL
			,'onSuccess':function(req){
					
					var objDiv = document.getElementById(theDiv);

					if(objDiv.style.display=='none')
						objDiv.style.display='block';

					document.getElementById(theDiv).innerHTML = req.responseText;
					if(mode=='add' || qry_str.indexOf('comments=1')!=-1)
						showCommentsForm(section_id, section_record_id, 0, 'CommentForm_'+section_record_id+'_0');

				}
			,'onError':function(req){ alert(req.statusText+'\nContents='+req.responseText); }
		}
	);
	return false;
}

//start of temp func
function showComments(mode,section_id, section_record_id, theDiv,login_id,pfid){
	
document.getElementById('links_'+section_record_id).style.display = 'none';

var qry_str = document.location.href;

if(qry_str.indexOf('comments=1')!=-1)
	var pageURL = "comments.php?section_id="+section_id+"&section_record_id="+section_record_id+"&comments=1&login_id="+login_id+"&pfid="+pfid;
else
	var pageURL = "comments.php?section_id="+section_id+"&section_record_id="+section_record_id+"&login_id="+login_id+"&pfid="+pfid;
//alert(pageURL);
	var status = AjaxRequest.get(
		{
			'url':pageURL
			,'onSuccess':function(req){
				//alert(req.responseText);

				    var objDiv = document.getElementById(theDiv);

					if(objDiv.style.display=='none')
						objDiv.style.display='block';

					req.responseText=req.responseText.replace(/&lt;/g,"<");
					req.responseText=req.responseText.replace(/&gt;/g,">");
					document.getElementById(theDiv).innerHTML = req.responseText;
				//	if((mode=='add' || qry_str.indexOf('comments=1')!=-1) && login_id!="")
					if(login_id!=""){
					showCommentsForm(section_id, section_record_id, 0, 'CommentForm_'+section_record_id+'_0');
					}
					 
				

				}
			,'onError':function(req){ alert(req.statusText+'\nContents='+req.responseText); }
		}
	);
	return false;
}
//End of temp func
function showCommentsForm(section_id, section_record_id, parent_id, theDiv){
//alert(section_id+'sid');alert(section_record_id+'section_record_id');alert(parent_id+'parent_id');alert(theDiv+'theDiv');
	var theFormTxt = "<form id=\"frmComments_" + section_record_id + "_" + parent_id + "\" name=\"frmComments_" + section_record_id + "_" + parent_id + "\" method=\"post\" action=\"comments.php\" onSubmit=\"javascript:return addComment(this);\" >";
	theFormTxt += document.getElementById('FormComments').innerHTML;
	theFormTxt += "</form>";

	document.getElementById(theDiv).innerHTML = theFormTxt;

	
	theForm = document.getElementById("frmComments_" + section_record_id + "_" + parent_id);

	theForm.section_id.value = section_id;
	theForm.section_record_id.value = section_record_id;
	theForm.parent_id.value = parent_id;
	theForm.container_id.value = "CommentForm_"+section_record_id+"_"+parent_id;
}

function deleteComment(section_id,section_record_id,CommentId,formid)
{
	//alert(CommentId);
	if(confirm("Are you sure you want to delete this comment?")) {
	var pageURL = "comments.php?func=delete&comment_id="+CommentId+"&section_id="+section_id+"&section_record_id="+section_record_id+"&comments=1";

	//alert(pageURL);
	var status = AjaxRequest.get(
		{
			'url':pageURL
			,'onSuccess':function(req){

					if(req.responseText == 'You cannot delete this comment')
					{
						alert('You cannot delete this comment');
						return false;
					}
					else
					{	
						showComments('view', section_id,section_record_id, 'Comment'+section_record_id);
									
					     var count=document.getElementById("comment_"+theForm.section_record_id.value).innerHTML;
						 count=count.substring(21,23);
						 cont=parseInt(count)-1;
						 if(cont>0){
						 document.getElementById("comment_"+theForm.section_record_id.value).innerHTML = "Add / Show Comments ("+cont+")";
					     document.getElementById("commenth_"+theForm.section_record_id.value).innerHTML = "Hide Comments ("+cont+")";
						 }
						 else{
						 document.getElementById("comment_"+theForm.section_record_id.value).innerHTML = "Add Comments";
					     document.getElementById("commenth_"+theForm.section_record_id.value).innerHTML = "Hide Comments";
						 }
					  	
					}
		}
			,'onError':function(req){ alert(req.statusText+'\nContents='+req.responseText); }
		}
	);
	return false;
}
}

//Function Added by bhavani.G

function addAnswer(theForm){
	var theDiv = 'Answer'+theForm.question_id.value;
	var ans = theForm.description.value;
	if(trim(ans)==''){
		alert('Enter the Answer');
		return false;
	}
	var status = AjaxRequest.submit(
		theForm
		,{
			'onSuccess':function(req){ document.getElementById(theDiv).innerHTML = req.responseText; 
			if(ans!="") { document.getElementById('message').innerHTML="<tr><td width='8' class='Font1Px LeftBorder1'>&nbsp;</td><td align='center'  class='SmallTextRedBold' width='98%'>Answer has been sent for approval.</td><td width='8' class='Font1Px RightBorder1'>&nbsp;</td></tr>";
			}else {document.getElementById('message').innerHTML="";}
			}
			,'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
		}
	);
	return false;
}

//Function Added by bhavani.G
//This function is used to show the answers
function showAnswers(mode, question_id, theDiv,theDiv1, theDiv2){
	var pageURL = "answers.php?question_id="+question_id;
	var status = AjaxRequest.get(
		{
			'url':pageURL
			,'onSuccess':function(req){
				theDiv3 = "showMinus_"+question_id;
				theDiv4 = "showPlus_"+question_id;
					document.getElementById(theDiv).innerHTML = req.responseText;
					document.getElementById(theDiv).style.display = "block";
					document.getElementById(theDiv1).style.display = "none";
					document.getElementById(theDiv2).style.display = "block";
					document.getElementById(theDiv4).style.display = "none";
					document.getElementById(theDiv3).style.display = "block";
					if(mode=='add') showAnswersForm(question_id, 0, 'AnswerForm_'+question_id+'_0');
				}
			,'onError':function(req){ alert(req.statusText+'\nContents='+req.responseText); }
		}
	);
	return false;
}

//Function Added by bhavani.G
//This function is used to show the answers form

function showAnswersForm(question_id, parent_id, theDiv){
	var theFormTxt = "<form id=\"frmAnswers_" + question_id + "_" + parent_id + "\" name=\"frmAnswers_" + question_id + "_" + parent_id + "\" method=\"post\" action=\"answers.php\" onSubmit=\"javascript:return addAnswer(this);\" >";
	theFormTxt += document.getElementById('FormAnswer').innerHTML;
	theFormTxt += "</form>";
	document.getElementById(theDiv).innerHTML = theFormTxt;
	theForm = document.getElementById("frmAnswers_" + question_id + "_" + parent_id);
	theForm.question_id.value = question_id;
	theForm.parent_id.value = parent_id;
	theForm.container_id.value = "AnswerForm_"+question_id+"_"+parent_id;
}


//Function Added by Dhananjay
//This function is used to send the Password to the user

function forgotPwd(theForm){
	
	emailId=theForm.email.value;
	var str=emailId;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
		{
			/*var status = AjaxRequest.submit(
				theForm
				,{
					'onSuccess':function(req){
						alert(req.responseText);
						return false;
						if(req.responseText=='Email Does Not Exist'){
						document.getElementById('forgot').style.display = 'block';
						document.getElementById('login').style.display = 'none';
						alert("Email Does Not Exist");
						theForm.email.focus();
						//alert(req.responseText);
						}
						else{
						document.getElementById('login').style.display = 'block';
						document.getElementById('forgot').style.display = 'none';
						alert("New password has been sent succuessfully to your mail address");
						}
						}
					,'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
				}
			);*/
			return true;
			
		}
		else{
		alert("Please input a valid email address!")
		theForm.email.focus();
		return false;
		}
		//return false;

}


//Function Added by Dhananjay
//This function is used to send the Password to the user

function resendActivationMail(theForm){
	emailId=theForm.email.value;
	var str=emailId;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(str))
		{

			var status = AjaxRequest.submit(
				theForm
				,{
					'onSuccess':function(req){
						if(req.responseText!=''){
						//document.getElementById('resendactivation_mail').style.display = 'block';
						//document.getElementById('login').style.display = 'none';
						alert(req.responseText);
						}
						else{
						document.getElementById('member').style.display = 'block';
						document.getElementById('resendactivation').style.display = 'none';
						alert("Activation mail has been resent succuessfully to your mail address");
						}
						}
					,'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
				}
			);
		}
		else{
		alert("Please input a valid email address!")
		return false;
		}
		return false;

}


//Function Added by Dhananjay
function getDetails(type,section, priority, theDiv, member_id,currCnt,totalCnt,view){
	/*alert(mode);
	alert(question_id);*/
	tempDiv=theDiv+'E';
	//alert(tempDiv)
	commentDiv=theDiv+'C';
	var pageURL = "get_details.php?type="+type+"&section="+section+"&priority="+priority+"&member_id="+member_id+"&currCnt="+currCnt+"&totalCnt="+totalCnt+"&view="+view;
	//alert(pageURL);
	var status = AjaxRequest.get(
		{
			'url':pageURL
			,'onSuccess':function(req){
					arr=req.responseText;
					//alert(arr);
					arr1=arr.split('*');
					//alert(arr1[0]);
					//alert(arr1[1]);
					document.getElementById(theDiv).innerHTML = arr1[0];
					document.getElementById(tempDiv).innerHTML = arr1[1];
//					document.getElementById(commentDiv).innerHTML = arr1[2];
				}
			,'onError':function(req){ alert(req.statusText+'\nContents='+req.responseText); }
		}
	);
	return false;
}

function getGoal(type,priority,member_id,view,currCnt,totalCnt){
	
    
		var pageURL = "get_details.php?from=goals"+"&type="+type+"&priority="+priority+"&profile_id="+member_id+"&view="+view+"&currCnt="+currCnt+"&totalCnt="+totalCnt;
		//alert(pageURL);

	var status = AjaxRequest.get(
		{
			'url':pageURL
			,'onSuccess':function(req){
					document.getElementById('goal').innerHTML = req.responseText;
									}
			,'onError':function(req){ alert(req.statusText+'\nContents='+req.responseText); }
		}
	);
	return false;
}


/*Function Added by Bhavani
Gets and displays the next and previous records
of the logged in favourite members

*/
function getFavouritetest(type, id, member_id){
	
	var pageURL = "get_details.php?type="+type+"&from=favourite&iid="+id+"&member_id="+member_id;
//	alert(pageURL);
	var status = AjaxRequest.get(
		{
			'url':pageURL
			,'onSuccess':function(req){
					arr=req.responseText;
					//alert(arr);
					arr1=arr.split('#');
				
					document.getElementById('uphoto').innerHTML = arr1[2];
					document.getElementById('user').innerHTML = arr1[0];
					document.getElementById('ugender').innerHTML = arr1[4]+" "+arr1[3];
					document.getElementById('ucity').innerHTML = arr1[5]+""+arr1[6];
					document.getElementById('ulinks').innerHTML = arr1[1];
					
				}
			,'onError':function(req){ alert(req.statusText+'\nContents='+req.responseText); }
		}
	);
	return false;
}

/**
* IlA for save order of the features box while draging it
*/
function sectionOrders() {
	sections = document.getElementById('sectionorder').value;
	var pageURL = "ordersection.php?section="+sections;
	//alert(pageURL);
	var status = AjaxRequest.get(
		{
			'url':pageURL
			,'onSuccess':function(req){
					arr=req.responseText;
					//alert(arr);
				}
			,'onError':function(req){ alert('error...'); }
		}
	);
	return false;
}

/**
/**
* IlA for message / comments
*/
function sendMessage(theForm) {
	
	rid = document.getElementById('rid').value;
	message = document.getElementById('comment').value;
	
	if(message.length < 1 || message == 'Say HI !!!') {
		alert('Enter message');
		theForm.comment.focus();
		theForm.comment.select();
		return false;
	}


		var status = AjaxRequest.submit (
			theForm
			,{
				'onSuccess':function(req) {
					response = req.responseText;
					document.getElementById('comments').innerHTML = response;
					document.getElementById('comment').value = '';
				}
				,'onError':function(req) {
					document.getElementById('comment').innerHTML = "<b>There is a problem to send your message.</b>";
				}
			}
		);
	theForm.comment.focus();
	return false;
}


/**
* IlA for Tell a Friend
*/
function functionTellAFriend(obj, disp, article_id) {
	document.getElementById('links_'+article_id).style.display = 'none';
	
	if(article_id!="")
	theDiv = obj+"_"+article_id;
	else
	theDiv=obj;

	document.getElementById(theDiv).style.display = disp;
	return false;
}

/**
* IlA for Call Tellafriend.php to send mail to friend
*/
function sendTellAFriend(frm, theDiv) {
	//alert(frm);
	var emailMatch = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
	var stringMatch = /^([a-zA-z0-9\/\-\,\#])+([\sa-zA-z0-9\/\-\,\#]*)$/;

	if(frm.myemail.value.length == 0 || !emailMatch.test(frm.myemail.value)) {
		alert('Enter valid Mail ID');
		frm.myemail.focus();
		frm.myemail.select();
		return false;
	}
	else if(frm.friendemail.value.length == 0 || !emailMatch.test(frm.friendemail.value)) {
		alert('Enter valid Mail ID');
		frm.friendemail.focus();
		frm.friendemail.select();
		return false;
	}
	else if(frm.message.value.length < 5 ) {
		alert('Enter valid Message');
		frm.message.focus();
		frm.message.select();
		return false;
	}

	var status = AjaxRequest.submit (
		frm
		,{
			'onSuccess':function(req) {
				response = req.responseText;
				alert(response);
				frm.myemail.value = '';
				frm.friendemail.value = '';
				frm.message.value = '';
				document.getElementById(theDiv).style.display = 'none';
			}
			,'onError':function(req) {
				alert('There is a problem to send your message.');
				document.getElementById('tellafriend').style.display = 'none';
			}
		}
	);


	return false;
}

/**
* IlA admin add user page validation
*/
function admin_validateuserForm(frm) {

	var emailMatch = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
	var unameMatch = /^[a-zA-Z0-9]+$/;


	if(frm.username.value.length < 3 || !unameMatch.test(frm.username.value)) {
alert('Enter valid User Name (No special Characters)');
		frm.username.focus();
		frm.username.select();
		return false;
	}
	else if(frm.useremail.value.length == 0 || !emailMatch.test(frm.useremail.value)) {
		alert('Enter valid Mail ID');
		frm.useremail.focus();
		frm.useremail.select();
		return false;
	}
	else if(!(frm.userpswd.disabled) && frm.userpswd.value.length < 5) {
		alert('Enter valid Password (Minimum 5 Characters)');
		frm.userpswd.focus();
		frm.userpswd.select();
		return false;
	}

	var status = AjaxRequest.submit (
		frm
		,{
			'onSuccess':function(req) {
				response = req.responseText;
//				alert(response);
				if(response == 0) {
					alert('There is a problem while adding user.');
					frm.username.value = '';
					frm.useremail.value = '';
					frm.userpswd.value = '';
					frm.username.focus();
					return false;
				}
				document.getElementById('userslist').innerHTML = response;
			}
			,'onError':function(req) {
				alert('There is a problem while adding user.');
			}
		}
	);

return false;
}

/**
* admin add package page validation
*/
function admin_validatePackageForm(frm) {
	var numberMatch = /^[0-9]+$/;
	var priceMatch = /^([0-9])+(\.){0,1}([0-9])*$/;
	if(frm.pname.value.length == 0 ) {
		alert('Enter valid Package Name');
		frm.pname.focus();
		frm.pname.select();
		return false;
	}
	else if(frm.amount.value.length == 0 || !priceMatch.test(frm.amount.value)) {
		alert('Enter valid Price');
		frm.amount.focus();
		frm.amount.select();
		return false;
	}
	else if(frm.members.value.length == 0 || !numberMatch.test(frm.members.value)) {
		alert('Enter valid Number of Members');
		frm.members.focus();
		frm.members.select();
		return false;
	}
}

/**
*	Ila open popup to report a user
*/
function open_popup(){
//alert(arVendor);
	var iPopup = document.getElementById('popup');
	var imgBlock = document.getElementById('imgBlock');
	if(iPopup.style.display == 'none'){
		hideSelects();
		iPopup.style.display = 'block';
		iPopup.style.left ="35%";
		iPopup.style.top = "25%";
		if(imgBlock){
			imgBlock.style.width = document.body.scrollWidth-5;
			imgBlock.style.height = document.body.scrollHeight;
			imgBlock.style.display = 'block';
		}
	}
	else{
		showSelects();
		iPopup.style.display = 'none';
		if(imgBlock){
			imgBlock.style.display = 'none';
			imgBlock.style.width = "1px";
			imgBlock.style.height =  "1px";
		}
	}
}

/**
*	Ila report this user form validation
*/
function validateReportThisUser(frm) {
	if(frm.popup_reasion.value.length < 5) {
		alert('Enter valid Reason');
		frm.popup_reasion.focus();
		frm.popup_reasion.select();
		return false;
	}

	var status = AjaxRequest.submit (
		frm
		,{
			'onSuccess':function(req) {
				response = req.responseText;
				alert(response);
				open_popup('popup');
			}
			,'onError':function(req) {
				 alert(req.statusText+'\nContents='+req.responseText);
				alert('There is a problem to process your request.');
				open_popup('popup');
			}
		}
	);
	return false;
}

/**
* IlA block user
*/
function blockUser(mail_status, obj, id) {
  //alert(document.getElementById('uid').value);
   if(confirm("Are you sure you want to block this user?")) {
  url="check_mails.php?profile_id="+document.getElementById(obj).value+"&status="+mail_status+"&mailid="+id;
  //alert(url);

  var status = AjaxRequest.get(
    {
      'url':url
      ,'onSuccess':function(req) {
          arr=req.responseText;
          alert(arr);
         // alert(mail_status);
          if(mail_status == '2')
          	document.location = 'check_mails.php?st=0';
          else
	          document.location = document.location;
        }
      ,'onError':function(req) {
         alert(req.statusText+'\nContents='+req.responseText);
      }
    }
  );
  return false;
  }
}

/**
* IlA block user
*/
function deleteUser(mail_status, obj, id) {
  //alert(document.getElementById('uid').value);
  if(confirm("Are you sure you want to delete this user?")) {
  url="delete.php?profile_id="+document.getElementById(obj).value+"&status="+mail_status+"&mailid="+id;
  //alert(url);

  var status = AjaxRequest.get(
    {
      'url':url
      ,'onSuccess':function(req) {
          arr=req.responseText;
          //alert(arr);
		  alert("Record deleted successfully");
         // alert(mail_status);
         /* if(mail_status == '2')
          	document.location = 'check_mails.php?st=0';
          else*/
	          document.location = document.location;
        }
      ,'onError':function(req) {
         //alert(req.statusText+'\nContents='+req.responseText);
		 alert("Error deleting the record");
      }
    }
  );
  return false;
}
}


/**
* IlA Check all checkbox in mentors mebrersearch page
*/
function checkAll(frm, obj, tot) {
	check = obj.checked;
	for(i=1; i<=tot; i++) {
		document.getElementById('members['+i+']').checked = check;
	}
}

/**
* IlA Check top checkbox in mentors mebrersearch page
*/
function checkTop(frm, obj, tot) {
	if(!obj.checked)
		document.getElementById('checkallmembers'). checked = false;
	else {
		flag = true;
		for(i=1; i<=tot; i++) {
			if(!document.getElementById('members['+i+']').checked)
				flag = false;
		}
		document.getElementById('checkallmembers').checked = flag;
	}
}

/**
* IlA Uncheck all checkbox in mentors mebrersearch page
*/
function uncheckAll(tot) {
	document.getElementById('checkallmembers').checked = false;
	for(i=1; i<=tot; i++)
		document.getElementById('members['+i+']').checked = false;
}

/**
* IlA send request to members in mentors mebrersearch page by ajax
*/
function sendRequest(frm, tot) {
	flag = true;
	for(i=1; i<=tot; i++) {
		if(!document.getElementById('members['+i+']').checked)
			flag = false;
		else {
			flag = true;
			break;
		}
	}

	if(!flag) {
		alert('Select atleast one Member from the list');
		document.getElementById('members[1]').focus();
		return false;
	}

	var status = AjaxRequest.submit (
		frm
		,{
			'onSuccess':function(req) {
				response = req.responseText;
//				alert(response);
				alert('Your request has been sent to Member');
				//uncheckAll(tot);
				document.location=document.location;
				document.getElementById('submit').style.display = 'block';
				document.getElementById('text').style.display = 'none';
			}
			,'onLoading':function(req) {
				document.getElementById('submit').style.display = 'none';
				document.getElementById('text').style.display = 'block';
			}
			,'onError':function(req) {
				alert(req.statusText+'\nContents='+req.responseText);
				alert('There is a problem to process your request.');
				uncheckAll(tot);
				document.getElementById('submit').style.display = 'block';
				document.getElementById('text').style.display = 'none';
			}
		}
	);
	return false;
}

/**
* IlA remove sections from user's home page
*/
function removeSection(section) {
	//alert(section);
	url = "removesections.php?section="+section;
	section = section+'s';
	var status = AjaxRequest.get(
    {
      'url':url
      ,'onSuccess':function(req) {
          arr=req.responseText;
          //alert(arr);
//		$(section).hide();
		$(section).remove();
        //  document.getElementById(section).style.display = 'none';
          window.setTimeout("calculteheight();",100);
        }
		,'onError':function(req) {
			alert(req.statusText+'\nContents='+req.responseText);
		}
    }
  );
  return false;
}

/**
* IlA send request to members from explore page by ajax
*/
function sendMentorRequest(pid, mid, div,members,allowed) {
	
	//validate allowed
	if(members<allowed || allowed==0)
	{
	url = 'requestmentorship.php?profile_id='+pid+'&mid='+mid+'&type=mentor';
	//alert(url);
	
	var status = AjaxRequest.get(
    {
      'url':url
      ,'onSuccess':function(req) {
			response = req.responseText;
			//alert(response);
			
			document.location=document.location;
			
			if($('msg')) {
				document.getElementById('msg').style.display='block';
				document.getElementById('msg').innerHTML='<table width=100% border=0>			<TR><TD align=center class=SmallTextRedBold>'+response+'</TD></TR>	  </table>';
			}
			else {
				alert(response);
			}			
			
			if(document.getElementById(div))
				document.getElementById(div).style.display='none';
			
			if(document.getElementById('submit'))
				document.getElementById('submit').style.display = 'block';
			//document.getElementById('text').style.display = 'none';
			
		}
		,'onLoading':function(req) {
			if(document.getElementById('submit'))
			document.getElementById('submit').style.display = 'none';
			//document.getElementById('text').style.display = 'block';
		}
		,'onError':function(req) {
			alert(req.statusText+'\nContents='+req.responseText);
			alert('There is a problem to process your request.');
			if(document.getElementById('submit'))			
			document.getElementById('submit').style.display = 'block';
			//document.getElementById('text').style.display = 'none';
		}
    }
  );
	return false;
	}
	else
	{
		alert('You has reached the maximum level of allowed members.');
	}
}

/**
* IlA send request to members from explore page by ajax
*/
function sendMentorRequestMember(pid,mid,div) {
	
	
	//validate allowed
	//if(members<allowed || allowed==0)
	//{
	url = 'requestmentorship.php?profile_id='+pid+'&mid='+mid+'&type=member';
	//alert(url);
	
	var status = AjaxRequest.get(
    {
      'url':url
      ,'onSuccess':function(req) {
			response = req.responseText;
			//alert(response);
			
			document.location=document.location;
			
		    alert(response);
			
		}
		,'onLoading':function(req) {
			if(document.getElementById('submit'))
			document.getElementById('submit').style.display = 'none';
			//document.getElementById('text').style.display = 'block';
		}
		,'onError':function(req) {
			alert(req.statusText+'\nContents='+req.responseText);
			alert('There is a problem to process your request.');
			if(document.getElementById('submit'))			
			document.getElementById('submit').style.display = 'block';
			//document.getElementById('text').style.display = 'none';
		}
    }
  );
	return false;
	//}
/*	else
	{
		alert('You has reached the maximum level of allowed members.');
	}*/
}


/**
* IlA send request to members from explore page by ajax
*/
function setCommentApproval(pid,cid,approval) {
	url = 'comments.php?func=approval&profile_id='+pid+'&comment_id='+cid+'&approval='+approval;
	//alert(url);
	
	var status = AjaxRequest.get(
    {
      'url':url
      ,'onSuccess':function(req) {
			response = req.responseText;
			//alert(response);
			if(response =='Success') {
				Element.remove('comment_'+cid);
				if($('commentstable').rows.length == 1) {
					$('no_record_div').show();
				}
			}
			else {
				alert(response);
			}							
		}

		,'onLoading':function(req) {
		}

		,'onError':function(req) {
			alert(req.statusText+'\nContents='+req.responseText);
			alert('There is a problem to process your request.');
			if(document.getElementById('submit'))			
			document.getElementById('submit').style.display = 'block';
			//document.getElementById('text').style.display = 'none';
		}
    }
  );
	return false;
}

/**
* IlA accept / reject mentor request from requested mentors page by ajax
*/
function setMentorRequest(pid, mid, status) {
	//alert(status);
	url = 'requestedmentorslist.php?profile_id='+pid+'&mid='+mid+'&status='+status+'&type=mentor';
	//alert(url);
	var status = AjaxRequest.get(
    {
      'url':url
      ,'onSuccess':function(req) {
			response = req.responseText;
			
			//stat = response.split('#');
			
			alert('Your response has been sent to Mentor.');
			
			//if(stat[0]==1 && stat[1]=='a')
				//alert("You have reached the maximum number of members. Please upgrade your package to add more members");
			
			document.location=document.location;
			document.getElementById('submit').style.display = 'block';
			document.getElementById('text').style.display = 'none';
		}
		,'onLoading':function(req) {
			document.getElementById('submit').style.display = 'none';
			document.getElementById('text').style.display = 'block';
		}
		,'onError':function(req) {
			alert(req.statusText+'\nContents='+req.responseText);
			alert('There is a problem to process your request.');
			document.getElementById('submit').style.display = 'block';
			document.getElementById('text').style.display = 'none';
		}
    }
  );
	return false;
}

/**
* IlA accept / reject mentor request from requested mentors page by ajax
*/
function setMemberRequest(pid, mid, status) {
	//alert(status);
	url = 'requestedmentorslist2.php?profile_id='+pid+'&mid='+mid+'&status='+status+'&type=member';
	//alert(url);
	var status = AjaxRequest.get(
    {
      'url':url
      ,'onSuccess':function(req) {
			response = req.responseText;
			
			//stat = response.split('#');
			
			alert('Your response has been sent to Member.');
			
			//if(stat[0]==1 && stat[1]=='a')
				//alert("You have reached the maximum number of members. Please upgrade your package to add more members");
			
			document.location=document.location;
			document.getElementById('submit').style.display = 'block';
			document.getElementById('text').style.display = 'none';
		}
		,'onLoading':function(req) {
			document.getElementById('submit').style.display = 'none';
			document.getElementById('text').style.display = 'block';
		}
		,'onError':function(req) {
			alert(req.statusText+'\nContents='+req.responseText);
			alert('There is a problem to process your request.');
			document.getElementById('submit').style.display = 'block';
			document.getElementById('text').style.display = 'none';
		}
    }
  );
	return false;
}

/**
* IlA accept / reject mentor request from requested mentors page by ajax
*/
function deleteRelationMentor(pid,mid,status) {
	//alert(status);
	
	if(confirm("Are you sure want to delete this mentor?")) {
		
	url = 'mymentors.php?profile_id='+pid+'&mid='+mid+'&status='+status;
	//alert(url);
	var status = AjaxRequest.get(
    {
      'url':url
      ,'onSuccess':function(req) {
			response = req.responseText;
			
			//stat = response.split('#');
				
			//if(stat[0]==1 && stat[1]=='a')
				//alert("You have reached the maximum number of members. Please upgrade your package to add more members");
			
			document.location=document.location;
			document.getElementById('submit').style.display = 'block';
			document.getElementById('text').style.display = 'none';
		}
		,'onLoading':function(req) {
			document.getElementById('submit').style.display = 'none';
			document.getElementById('text').style.display = 'block';
		}
		,'onError':function(req) {
			alert(req.statusText+'\nContents='+req.responseText);
			alert('There is a problem to process your request.');
			document.getElementById('submit').style.display = 'block';
			document.getElementById('text').style.display = 'none';
		}
    }
  );
	return false;
}
	else
		return false;
}

/**
* IlA accept / reject mentor request from requested mentors page by ajax
*/
function deleteRelationMember(mid,pid,status) {
	
	if(confirm("Are you sure want to delete this member?")) {
		
	url = 'mentorsmembers.php?profile_id='+pid+'&mid='+mid+'&status='+status;
	var status = AjaxRequest.get(
    {
      'url':url
      ,'onSuccess':function(req) {
			response = req.responseText;
			
			//stat = response.split('#');
						
			//if(stat[0]==1 && stat[1]=='a')
				//alert("You have reached the maximum number of members. Please upgrade your package to add more members");
			
			document.location=document.location;
			document.getElementById('submit').style.display = 'block';
			document.getElementById('text').style.display = 'none';
		}
		,'onLoading':function(req) {
			document.getElementById('submit').style.display = 'none';
			document.getElementById('text').style.display = 'block';
		}
		,'onError':function(req) {
			alert(req.statusText+'\nContents='+req.responseText);
			alert('There is a problem to process your request.');
			document.getElementById('submit').style.display = 'block';
			document.getElementById('text').style.display = 'none';
		}
    }
  );
	return false;
}
	else
		return false;
}

function addtoFavourite(member_id,profile_id){
			url = "add_to_favourite.php?func=add&member_id="+member_id+"&profile_id="+profile_id;
			//alert(url);
			new Ajax.Request(url, {
				method: 'get',
				onSuccess: function(transport) {
					//alert(transport.responseText);
					responseText = transport.responseText;
					alert(responseText);
				}
			});
		}

//Function Added by Dhananjay
function getMentorMembers(type,section,member_id,start,end){
	/*alert(mode);
	alert(question_id);*/
	tempDiv=section+'E';
	var pageURL = "get_details.php?from=mentor&type="+type+"&section="+section+"&profile_id="+member_id+"&start="+start+"&end="+end;
	//alert(pageURL);
	var status = AjaxRequest.get(
		{
			'url':pageURL
			,'onSuccess':function(req){
					arr=req.responseText;
					//alert(arr);
					arr1=arr.split('#');
					alert(arr1[1]);
					document.getElementById(section).innerHTML = arr1[0];
					document.getElementById(tempDiv).innerHTML = arr1[1];

				}
			,'onError':function(req){ alert(req.statusText+'\nContents='+req.responseText); }
		}
	);
	return false;
}

//Function Added by Dhananjay
function getFavourite(type,member_id,start,end,curCnt,totCnt){
	//alert(type+'mem->'+member_id+'str->'+start+'end->'+end);
	var pageURL = "get_details.php?from=favourite&type="+type+"&profile_id="+member_id+"&start="+start+"&end="+end+"&curCnt="+curCnt+"&totCnt="+totCnt;
	
	var status = AjaxRequest.get(
		{
			'url':pageURL
			,'onSuccess':function(req){
					arr=req.responseText;
				
					arr1=arr.split('#');
					
					document.getElementById('favourite').innerHTML = arr1[0];
					document.getElementById('favouriteE').innerHTML = arr1[1];

				}
			,'onError':function(req){ alert(req.statusText+'\nContents='+req.responseText); }
		}
	);
	return false;
}


/**
*	Bhavani open popup to invite a user
*/
function open_popup_to_invite(){
//alert(arVendor);
	var iPopup = document.getElementById('invite_popup');
	var imgBlock = document.getElementById('imgBlock1');
	if(iPopup.style.display == 'none'){

		iPopup.style.display = 'block';
		iPopup.style.left ="35%";
		iPopup.style.top = "25%";
		hideSelects();
		if(imgBlock){
			imgBlock.style.width = document.body.scrollWidth-5;
			imgBlock.style.height = document.body.scrollHeight;
			imgBlock.style.display = 'block';
		}
	}
	else{
		
		iPopup.style.display = 'none';
		if(imgBlock){
			imgBlock.style.display = 'none';
			imgBlock.style.width = "1px";
			imgBlock.style.height =  "1px";
			showSelects();
		}
	}
}
/**
*	Open popup to add a section
*/
function open_popup_to_add_section(){
//alert(arVendor);
	var iPopup = document.getElementById('section_add_help_main');
	var imgBlock = document.getElementById('imgBlock1');
	if(iPopup.style.display == 'none'){
		//if(document.getElementById('category_main'))
			//document.getElementById('category_main').style.display='none';
		hideSelects();
		iPopup.style.display = 'block';
			document.getElementById('section_add_help').style.display='block';
			document.getElementById('section_add_popup').style.display='none';

		iPopup.style.left ="35%";
		iPopup.style.top = "25%";
		if(imgBlock){
			imgBlock.style.width = document.body.scrollWidth-5;
			imgBlock.style.height = document.body.scrollHeight;
			imgBlock.style.display = 'block';
		}
	}
	else{
		//if(document.getElementById('category_main'))
			//document.getElementById('category_main').style.display='block';
		showSelects();
		iPopup.style.display = 'none';
		if(imgBlock){
			imgBlock.style.display = 'none';
			imgBlock.style.width = "1px";
			imgBlock.style.height =  "1px";
		}
	}
}

/**
*	Open popup to view goals details
*/
function open_popup_to_viewdetails(id){
//alert(arVendor);
	var iPopup = document.getElementById('details_'+id);
	document.getElementById('links_'+id).style.display = 'none';
	var imgBlock = document.getElementById('imgBlock1');
	if(iPopup.style.display == 'none'){
		//if(document.getElementById('category_main'))
			//document.getElementById('category_main').style.display='none';
		hideSelects();
		iPopup.style.display = 'block';
			document.getElementById('details_add').style.display='block';
			document.getElementById('details_popup').style.display='none';

		iPopup.style.left ="35%";
		iPopup.style.top = "24%";
	}
	else{
		//if(document.getElementById('category_main'))
			//document.getElementById('category_main').style.display='block';
		showSelects();
		iPopup.style.display = 'none';
	}
}

/**
*	Open popup to view goals details
*/
function open_popup_to_viewdetails_explore(id){
//alert(arVendor);
	var iPopup = document.getElementById('details_'+id);
	document.getElementById('links_'+id).style.display = 'none';
	var imgBlock = document.getElementById('imgBlock1');
	if(iPopup.style.display == 'none'){
		//if(document.getElementById('category_main'))
			//document.getElementById('category_main').style.display='none';
		hideSelects();
		iPopup.style.display = 'block';
			document.getElementById('details_add').style.display='block';
			document.getElementById('details_popup').style.display='none';

		iPopup.style.left ="35%";
		iPopup.style.top = "24%";
	}
	else{
		//if(document.getElementById('category_main'))
			//document.getElementById('category_main').style.display='block';
		showSelects();
		iPopup.style.display = 'none';
	}
}

/**
*	Open popup to view goals details
*/
function open_popup_to_helpkeywords(){
	var iPopup = document.getElementById('help_keywords');
	
	if(iPopup.style.display == 'none'){
		//if(document.getElementById('category_main'))
			//document.getElementById('category_main').style.display='none';
		hideSelects();
		iPopup.style.display = 'block';
			document.getElementById('keywords_add').style.display='block';
			document.getElementById('keywords_popup').style.display='none';

		iPopup.style.left ="40%";
		iPopup.style.top = "30%";
	}
	else{
		//if(document.getElementById('category_main'))
			//document.getElementById('category_main').style.display='block';
		showSelects();
		iPopup.style.display = 'none';
	}
}


/**
*	Open popup to add a section
*/
function open_popup_to_terms2(){
	var iPopup = document.getElementById('terms_conditions');
	var imgBlock = document.getElementById('imgBlock1');
	if(iPopup.style.display == 'none'){
		//if(document.getElementById('category_main'))
			//document.getElementById('category_main').style.display='none';
		hideSelects();
		iPopup.style.display = 'block';
			document.getElementById('terms_add').style.display='block';
			document.getElementById('terms_popup').style.display='none';

		iPopup.style.left ="35%";
		iPopup.style.top = "25%";
		if(imgBlock){
			imgBlock.style.width = document.body.scrollWidth-5;
			imgBlock.style.height = document.body.scrollHeight;
			imgBlock.style.display = 'block';
		}
	}
	else{
		//if(document.getElementById('category_main'))
			//document.getElementById('category_main').style.display='block';
		showSelects();
		iPopup.style.display = 'none';
		if(imgBlock){
			imgBlock.style.display = 'none';
			imgBlock.style.width = "1px";
			imgBlock.style.height =  "1px";
		}
	}
}


function open_popup_options(id)
{
	var iPopup = document.getElementById('links_'+id);	
	iPopup.style.display = 'block';
}

function close_popup_options(id)
{
	var iPopup = document.getElementById('links_'+id);
 	iPopup.style.display = 'none';
}

function open_popup_mentor_options(id)
{
	var iPopup = document.getElementById('mentor_'+id);	
	iPopup.style.display = 'block';
}

function close_popup_mentor_options(id)
{
	var iPopup = document.getElementById('mentor_'+id);
 	iPopup.style.display = 'none';
}


function close_popup_options_exit(id)
{
	var iPopup = document.getElementById('links_'+id);
	iPopup.style.display = 'none';
}

function open_grabbers_form()
{
	window.open('viral/importer.php','mypopup','height=510, width=800,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no');return false;
}



function validateGoalStep1()
{
	var frm = document.frmPopoupAddSection;
		tinyMCE.triggerSave();
		txtBox = "goal_desc";
		//document.getElementById('goal_desc'+id).value = tinyMCE.getContent();
		currdate='{/literal}{$date}{literal}';
		currarr=currdate.split('-');
		cd=currarr[0];
		cm=currarr[1];
		cy=currarr[2];
		if(frm.startdate.value == '') {
			alert("Please Enter the Start Date");
			return false;
		}
		if(frm.enddate.value == '') {
			alert("Please Enter the End Date");
			return false;
		}
		var startdate=frm.startdate.value;
		var enddate=frm.enddate.value;
		//alert(startdate);
		startarr=startdate.split('/');
		endarr=enddate.split('/');
		sy=startarr[2];sm=startarr[0];sd=startarr[1];
		ey=endarr[2];em=endarr[0];ed=endarr[1];
		/*if(islower(cd,cm,cy,sd,sm,sy)==false) {
			alert("Goal Start Date should Not be less than Today's Date");
			return false;
		}*/
		if(islower(sd,sm,sy,ed,em,ey)==false) {
			alert("Goal End Date should Not be less than Goal Start Date");
			return false;
		}
		if(!$(frm.goal_desc).present()) {
			alert("Please Enter The Description");
			return false;
		}
	document.getElementById('section_add_goal_1').style.display='none';
	document.getElementById('section_add_goal_2').style.display='block';
}
function close_popup_add_section(){
//alert(arVendor);
	open_popup_to_add_section('section_add_help');
	open_popup_to_add_section('section_add_popup');
	showSelects();
	var imgBlock = document.getElementById('imgBlock1');
	document.getElementById('section_add_help').style.display='none';
	document.getElementById('section_add_popup').style.display='none';

			imgBlock.style.width = document.body.scrollWidth-5;
			imgBlock.style.height = document.body.scrollHeight;
			imgBlock.style.display = 'block';
}



/**
*	Invite a friend form validation
*/
function validateInviteFriend(frm) {

	if(frm.friend_email.value =="") {
		alert('Enter friend\'s email address');
		frm.friend_email.focus();
		return false;
	}
	

	if(frm.friend_email.value!="")
	{
		emails = frm.friend_email.value;
		
		all_emails = emails.split(',');
		
		if(all_emails.length>1){
			for(i=0;i<all_emails.length-1;i++){
				var ss = email_check(all_emails[i]);
					if(ss){
						alert(ss);
						return false;
					}
			}
		}
		else{
			var ss = email_check(all_emails[0]);
					if(ss){
						alert(ss);
						return false;
					}
		}

	}


	if(frm.invite_comment.value=="" || frm.invite_comment.value==" ")
	{
		alert('Enter comments');
		return false;
	}





	var status = AjaxRequest.submit (
		frm
		,{
			'onSuccess':function(req) {
				response = req.responseText;
				alert(response);
				open_popup_to_invite('invite_popup');
			}
			,'onError':function(req) {
				 alert(req.statusText+'\nContents='+req.responseText);
				alert('There is a problem to process your request.');
				open_popup_to_invite('invite_popup');
			}
		}
	);
	return false;
}

function open_popup_to_feedback(){
//alert(arVendor);
	var fPopup = document.getElementById('feedback_form');
	var imgBlock = document.getElementById('imgBlock1');
	if(fPopup.style.display == 'none'){
		hideSelects();
		fPopup.style.display = 'block';
		fPopup.style.left ="25%";
		fPopup.style.top = "25%";
		if(imgBlock){
			imgBlock.style.width = document.body.scrollWidth-5;
			imgBlock.style.height = document.body.scrollHeight;
			imgBlock.style.display = 'block';
		}
	}
	else{
		fPopup.style.display = 'none';
		showSelects();
		if(imgBlock){
			imgBlock.style.display = 'none';
			imgBlock.style.width = "1px";
			imgBlock.style.height =  "1px";
		}
	}
}


/**
*	Invite a friend form validation
*/
function validatefeedback(frm) {

	if(frm.fb_email.value =="") {
		alert('Enter your email address');
		frm.fb_email.focus();
		return false;
	}

    if(frm.fb_email.value!="")
	{
		var ss = email_check(frm.fb_email.value);
		if(ss){
			alert(ss);
			return false;
		}

	}
		
    if(frm.fb_subject.value =="") {
		alert('Please enter a subject');
		frm.fb_subject.focus();
		return false;
	}	

	if(trim(frm.fb_comment.value)=="")
	{
		alert('Please enter some comments');
		frm.fb_comment.focus();
		return false;
	}

	if(frm.fb_captcha) {
		if(frm.fb_captcha.value == "") {
			alert('Please complete the word verification code');
			frm.fb_captcha.focus();
			return false;
		}
			
	}
		
	return true;
}

function acceptedTerms() {
	document.getElementById('terms').checked=true;
	open_popup_to_terms('terms_form');
}

function rejectTerms() {
	document.getElementById('terms').checked=false;
	open_popup_to_terms('terms_form');
}

function open_popup_to_terms(){
//alert(arVendor);
	var fPopup = document.getElementById('terms_form');
	var imgBlock = document.getElementById('imgBlock1');
	if(fPopup.style.display == 'none'){
		hideSelects();
		fPopup.style.display = 'block';
		fPopup.style.left ="25%";
		fPopup.style.top = "25%";
		if(imgBlock){
			imgBlock.style.width = document.body.scrollWidth-5;
			imgBlock.style.height = document.body.scrollHeight;
			imgBlock.style.display = 'block';
		}
	}
	else{
		showSelects();
		fPopup.style.display = 'none';
		if(imgBlock){
			imgBlock.style.display = 'none';
			imgBlock.style.width = "1px";
			imgBlock.style.height =  "1px";
		}
	}
}

/* bhavani validate the email id entered for invite a friend*/

function email_check(str) {

		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i

		if(!filter.test(str))
		{
			var check = "Please input a valid email address!";
			return check;

		}
}


function login()
{
	alert("Please login!");
	return false;

}

/**
* IlA member accept / reject mentoring through coaching page
*/
function setCoachingStatus(member, mentor, aid, coaching, section, status, obj) {
	url = 'coaching.php?member_id1='+member+'&mentor_id1='+mentor+'&status='+status+'&aid='+aid+'&coaching='+coaching+'&section='+section+'&obj='+obj;
	iid = obj.split('_');
	obj1 = 'edit_'+iid[1];
	obj2 = 'show_'+iid[1];

	
	var st = AjaxRequest.get(
    	{
     	 'url':url
     	 ,'onSuccess':function(req) {
			response = req.responseText;
				
			document.getElementById(obj1).style.display = 'none';
			document.getElementById(obj2).style.display = 'block';
			
			if(status == 1){
				document.getElementById(obj).innerHTML = "<b>Accepted</b>";
				}
			else{
				document.getElementById(obj).innerHTML = "<b>Rejected</b>";}
	
			
		}
		,'onError':function(req) {
			alert(req.statusText+'\nContents='+req.responseText);
			alert('There is a problem to process your request.');
	
		}
    }
  );
	return false;
}

/**
* IlA Coaching page request to get detailed view to coachingview.php
*/

function coachingView(id,status,section, obj) {
	
	url = "coachingview.php?aid="+id+"&status="+status+"&section="+section+"&object="+obj;
//alert(url);
	var st = AjaxRequest.get(
    {
      'url':url
      ,'onSuccess':function(req) {
			
			 
			document.getElementById(obj).style.display = 'block';
			response = req.responseText;
			document.getElementById(obj).innerHTML = response;
			
			
		}
		
		,'onError':function(req) {
			alert(req.statusText+'\nContents='+req.responseText);
			alert('There is a problem to process your request.');
			document.getElementById(obj).style.display = 'none';

		}
    }
  );
	return false;
}

/**
* IlA delete admin users with confirmation message
*/
function deleteAdminUser(uid) {
	if(confirm("Do you wants to delete this user.")) {
		document.location = 'user_register.php?action=del&id='+uid;
	}
	else {
		return false;
	}
}


function validate(Frm){
	
		if(Frm.searchText.value == ""){
			alert("Please Enter Text to Search");
			Frm.searchText.focus();
			return false;
		}

		secid=Frm.searchcategory.options[Frm.searchcategory.selectedIndex].value;
		/*sec_id=Frm.sec.value;
			
		if(secid!=""){
			section_id=secid;}
		else{
			section_id=sec_id;}
alert(section_id);*/
			Frm.action="my_explore.php?section_id="+secid;
			Frm.submit();
	}



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

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 to close all popups on 'Esc' Key Press - Gullam Dec 09, 2007
function keyPressHandler(e) {
	var kC  = (window.event) ?    // MSIE or Firefox?
		event.keyCode : e.keyCode;
	var Esc = (window.event) ?   
		27 : e.DOM_VK_ESCAPE // MSIE : Firefox
	if(kC==Esc){
		//alert("Esc pressed");
		escape_popups('nothing');
	}
}


/*Function Added by Bhavani
Gets and displays the messages based on the selected options today, yesterday, this week, this month and all
of the logged in member

*/
function getMessages(this_msg){
	
	var pageURL = "messages.php?this_msg="+this_msg;
	//	
	var status = AjaxRequest.get(
		{
			'url':pageURL
			,'onSuccess':function(req){
					response=req.responseText;
					
					msgArray = response.split('##');
					document.getElementById('displayMessages').style.display = 'block';
					document.getElementById('firstDisplay').style.display = 'none';
					document.getElementById('displayMessages').innerHTML = msgArray[0];
					document.getElementById('title').innerHTML = msgArray[1];
					document.getElementById('paging').innerHTML = msgArray[2];
				
					
					
				}
			,'onError':function(req){ alert(req.statusText+'\nContents='+req.responseText); }
		}
	);
	return false;
}



/*Function Added by Bhavani
Gets and displays the notifications based on the selected options today, yesterday, this week, this month and all
of the logged in member

*/
function getNotifications(this_notice){
	//alert(this_notice);
	var pageURL = "notifications.php?this_notice="+this_notice;
	//alert(pageURL);
	var status = AjaxRequest.get(
		{
			'url':pageURL
			,'onSuccess':function(req){
					response=req.responseText;
					//alert(response);
					msgArray = response.split('##');
					document.getElementById('displayNotices').style.display = 'block';
					document.getElementById('firstDisplay').style.display = 'none';
					document.getElementById('displayNotices').innerHTML = msgArray[0];
					document.getElementById('paging').innerHTML = msgArray[1];
				
					
					
				}
			,'onError':function(req){ alert(req.statusText+'\nContents='+req.responseText); }
		}
	);
	return false;
}


/*Function Added by Bhavani
Gets and displays the coaching messages based on the selected options today, yesterday, this week, this month and all
of the logged in member

*/
function getCoachingMessages(this_day){
	//alert(this_day);
	var pageURL = "coaching.php?this_day="+this_day;
	//alert(pageURL);
	var status = AjaxRequest.get(
		{
			'url':pageURL
			,'onSuccess':function(req){
					response=req.responseText;					
					document.getElementById('firstDisplay').innerHTML = response;
					document.getElementById('firstDisplay').style.display = 'block';
				}
			,'onError':function(req){ alert(req.statusText+'\nContents='+req.responseText); }
		}
	);
	return false;
}

// Function to close all the which are all opened - Gullam Dec 09, 2007
function escape_popups(){
	
	var other_popup_ids = new Array();
	for(i=0;i<other_popup_ids.length;i++){
		try{ 
			document.getElementById(other_popup_ids[i]).style.display='none';
		}
		catch(err){
			// window.status
		}
		showSelects();

	}

	if(document.getElementById('invite_popup')){
		var iPopup = document.getElementById('invite_popup');
		if(iPopup.style.display == 'none'){}
		else open_popup_to_invite();
	}
	
	if(document.getElementById('feedback_form')){
		iPopup = document.getElementById('feedback_form');
		if(iPopup.style.display == 'none'){}
		else open_popup_to_feedback();
	}

	if(document.getElementById('section_add_help_main')){
		iPopup = document.getElementById('section_add_help_main');
		if(iPopup.style.display == 'none'){}
		else open_popup_to_add_section();
	}
	if(document.getElementById('popup')){
		iPopup = document.getElementById('popup');
		if(iPopup.style.display == 'none'){}
		else open_popup();
	}
}
function showSelects(){
   var elements = document.getElementsByTagName("select");
   var dont_list = new Array('fb_section','category1234');
   for (i=0;i< elements.length;i++){           
        elements[i].style.visibility='visible';
	}
		for(var j=0; j<dont_list.length; j++){
		if(document.getElementById(dont_list[j])) 
			document.getElementById(dont_list[j]).style.visibility='visible';

	   }
}
 
function hideSelects(){
	var elements = document.getElementsByTagName("select");
	var dont_list = new Array('fb_section','category1234');
	for (i=0;i< elements.length;i++){             
		elements[i].style.visibility='hidden';
	if(document.getElementById("searchable")) 
		document.getElementById("searchable").style.visibility='visible';
	}
	for(var j=0; j<dont_list.length; j++){
		if(document.getElementById(dont_list[j])) 
			document.getElementById(dont_list[j]).style.visibility='visible';
	}
}



// FUNCTION FOR QUESTION / ANSWER - SUPPORT PAGE
function toggleMe(a){
  var e=document.getElementById(a);
  if(!e)return true;
  if(e.style.display=="none"){
    e.style.display="block"
  } else {
    e.style.display="none"
  }
  return true;
}
// END QUESTION / ANSWER


String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

// FUNCTION FOR REMOVE KEYWORDS IN ITEMS
function addItemKeywords(){
		var list=$('keyvalues').value;
	    var list2 = list.split(",");
	    var flag = validateKeywords();//validate list of keywords
		    if(list2!=null && list2!='' && flag!=false)
		    {
			    for(i = 0; i < list2.length; i++){ 	    //add keywords loop			    
					    var div = new Element('div',{'id':list2[i]}).setStyle({'float': 'left'});
						div.wrap($('keydiv'));
						var input= new Element('input',{'type':'checkbox','class':'key','value':list2[i]});
						input.wrap($(list2[i]));
						var text= new Element('label',{'id':'l_'+list2[i]});
						text.wrap($(list2[i]));
						$('l_'+list2[i]).update(list2[i]);
			    	}
			}	
}

// FUNCTION TO VALIDATE LIST OF KEYWORDS IN ITEMS ADD SECTION
function validateKeywords(){
		var validate='';
		var list='';
		var list=$('keyvalues').value;
		var len=list.length;
		len=len+countKeywordsLength();
	    var list2 = list.split(",");
	   // if(len<150){
		    if(list2!=null && list2!='' )
		    {
			    for(i = 0; i < list2.length; i++){ 	    //add keywords loop			    	
			    	if(list2[i].trim()!='')
			    	{
				    	validate=saveKeywords();
				    	if(validate.indexOf(list2[i])!=-1)
				    	{
				    	alert("Not accepted repeating Tags");
						return false;
				    	}
				    	else if(list2[i].length > 30)
					    {
						    alert("Each Tag cannot exceed more than 30 characters");
							return false;	
					    }
			    	}
			    	else
			    	{
			    	alert("Tags can not be blank");
					return false;	
			    	}
				}	
		    }
		    else
		    {
		    alert("Tags can not be blank");	
			return false;
		    }
	   // }
		/*else{
		    alert("Tags cannot exceed more than 150 characters");	
			return false;
		}*/
	}
	   

// FUNCTION FOR ADD KEYWORDS IN ITEMS EDIT SECTION
function addtemKeywordsEdit(id){	
		var list=$('keyvalues_'+id).value;
	    var list2 = list.split(",");
	    var flag = validateKeywordsEdit(id);//validate list of keywords
		    if(list2!=null && list2!='' && flag!=false)
		    {
			    for(i = 0; i < list2.length; i++){//add keywords loop			    	
				    	var div = new Element('div',{'id':list2[i]+'_'+id}).setStyle({'float': 'left'});
						div.wrap($('keydiv_'+id));
						var input= new Element('input',{'type':'checkbox','class':'key_'+id,'value':list2[i]+'_'+id});
						input.wrap($(list2[i]+'_'+id));
						var text= new Element('label',{'id':'l_'+list2[i]+'_'+id});
						text.wrap($(list2[i]+'_'+id));
						$('l_'+list2[i]+'_'+id).update(list2[i]);			
			    }		
		   } 
}


// FUNCTION TO VALIDATE LIST OF KEYWORDS IN ITEMS ADD SECTION
function validateKeywords(){
		var validate='';
		var list=$('keyvalues').value;
		var len=list.length;
		len=len+countKeywordsLength();
	    var list2 = list.split(",");
	   // if(len<150){
		    if(list2!=null && list2!='' )
		    {
			    for(i = 0; i < list2.length; i++){ 	    //add keywords loop			    	
			    	if(list2[i].trim()!='')
			    	{
				    	validate=saveKeywords();
				    	if(validate.indexOf(list2[i])!=-1)
				    	{
					    	alert("Not accepted repeating Tags");
							return false;
				    	}
				    	else if(list2[i].length > 30)
					    {
						    alert("Each Tag cannot exceed more than 30 characters");
							return false;	
					    }
			    	}
			    	else
			    	{
				    	alert("Tags can not be blank");
						return false;	
			    	}
				}	
		    }
		    else
		    {
			    alert("Tags can not be blank");	
				return false;
		    }
	   // }
		/*else{
		    alert("Tags cannot exceed more than 150 characters");	
			return false;
		}*/
	}
	
// FUNCTION TO VALIDATE LIST OF KEYWORDS IN ITEMS EDIT SECTION
function validateKeywordsEdit(id){
		var validate='';
		var list=$('keyvalues_'+id).value;
		//var len=list.length;
		//len=len+countKeywordsLengthEdit(id);
	    var list2 = list.split(",");
	    //if(len<150){
		    if(list2!=null && list2!='' )
		    {
			    for(i = 0; i < list2.length; i++){ 	    //add keywords loop			    	
			    	if(list2[i].trim()!='')
			    	{
				    	validate=saveKeywordsEdit(id);
				    	if(validate.indexOf(list2[i])!=-1)
				    	{
					    	alert("Not accepted repeating Tags");
							return false;
				    	}
				    	else if(list2[i].length > 30)
					    {
						    alert("Each Tag cannot exceed more than 30 characters");
							return false;	
					    }
					    
			    	}
			    	else
			    	{
			    	alert("Tags can not be blank");
					return false;	
			    	}
				}	
		    }
		    else
		    {
			    alert("Tags can not be blank");	
				return false;
		    }
	   /* }
		else{
		    alert("Keywords cannot exceed more than 150 characters");
		    $('keyvalues_'+id).value="";	
			return false;
		}*/
	}
	   

// FUNCTION FOR REMOVE KEYWORDS IN ITEMS
function removeItemKeywordsEdit(id){
	$$('input.key_'+id).each(function(item) {
		if(item.checked)
			$(item.value).remove();
	});	
}
// END REMOVE KEYWORDS



// FUNCTION FOR REMOVE KEYWORDS IN ITEMS
function removeItemKeywords(){
	$$('input.key').each(function(item) {
		if(item.checked)
			$(item.value).remove();
	});	
}
// END REMOVE KEYWORDS

// FUNCTION FOR RELOAD KEYWORDS IN ITEMS
function saveKeywordsEdit(id){
	var list='';
	var list2='';
	var val='';
	$$('input.key_'+id).each(function(item) {
		if(item.value!="")
		{
			val=$('l_'+item.value).innerHTML;
			list=list+val+',';	
		}	
	});
	list2 = list.substring(0, list.length-1);
	return list2;
}


// FUNCTION FOR RELOAD KEYWORDS IN ITEMS
function saveKeywords(){
	var list='';
	var list2='';
	$$('input.key').each(function(item) {
		if(item.value!="")
			list=list+item.value+',';	
	});
	list2 = list.substring(0, list.length-1);
	return list2;
}

// END RELOAD KEYWORDS 


// FUNCTION FOR RELOAD KEYWORDS IN ITEMS
function countKeywordsLength(){
	var list='';
	var list2='';
	var length=0;
	$$('input.key').each(function(item) {
		if(item.value!="")
			list=list+item.value+',';	
	});
	list2 = list.substring(0, list.length-1);
	if (list2!='')
	return list2.length;
	else
	return 0;
}

// END RELOAD KEYWORDS 
// FUNCTION FOR RELOAD KEYWORDS IN ITEMS

function countKeywordsLengthEdit(id){
	var list='';
	var list2='';
	var length=0;
	var val='';
	$$('input.key_'+id).each(function(item) {
		if(item.value!="")
		{
			val=$('l_'+item.value).innerHTML;
			list=list+val+',';	
		}	
	});
	list2 = list.substring(0, list.length-1);
	if (list2!='')
	return list2.length;
	else
	return 0;
}