// JavaScript Document
function checkLogin(){
	$("txtUserName").className = 'right-field login_control';
	$("txtPassword").className = 'right-field login_control';
	if(''==trim($("txtUserName").value))
	{
		alert("Please enter email for login.");
		$("txtUserName").className = 'login_control errored-field ';
		$("txtUserName").focus(); 
		return false;
	}
	else if(''==trim($("txtPassword").value))
	{
		alert("Please enter password to login.");
		$("txtPassword").className = 'login_control errored-field ';
		$("txtPassword").focus();
		return false;
	}
	else{
		return true;
	}
}

function show_forgot_password(){
	if($('forgot_password').style.display=='none'){
		$('forgot_password').appear();
	}else{
		$('forgot_password').fade();
	}
}

function follow(name, ele, chcaption) {
	if(chcaption=='org')
	{
		if(!confirm('Do you really want to Unfollow?')){
		 return;
		}
	}
	if(ele.type == 'button'){
		ele.disable = true;
	}
	if(ele.value) { 
		ele.value = 'Unfollow';
	}else if(ele.firstChild.data){
		ele.firstChild.data = 'Unfollow';
	}else{
		ele.innerHTML = 'Unfollow';
	}
	var oOptions = {
		method: "post",
		parameters: { user: name },
		onFailure: function (oXHR, oJson) {
			//alert("An error occurred: " + oXHR.status);
		},
		   onSuccess: function(transport){
		   var response = transport.responseText;
		 //	alert(response);
		   if(chcaption=='org')
			{
				$(ele).innerHTML='';
			}
			 if(ele.type == 'button'){
				ele.disable = false;
			}
			if(chcaption==true)
			{
				if(trim(response)==1) {
					if(ele.value) { 
						ele.value = 'Unfollow';
					}else if(ele.firstChild.data){
						ele.firstChild.data = 'Unfollow';
					}else{
						ele.innerHTML = 'Unfollow';
					}
				 } else {
					if(ele.value) { 
						ele.value = 'Follow';
					}else if(ele.firstChild.data){
						ele.firstChild.data = 'Follow';
					}else{
						ele.innerHTML = 'Follow';
					}
				}
			}
	   }
	};
	var oRequest = new Ajax.Updater({ 
		//success: "divCustomerInfo"
	}, path+"user/follow_unfollow", oOptions);
}

function org_chart_follow(name, id, type)
{
	var oOptions = {
		method: "post",
		parameters: { 'user': name, 'type': type },
		onFailure: function (oXHR, oJson) {
			//alert("An error occurred: " + oXHR.status);
		},
		onSuccess: function(transport){
		   var response = transport.responseText;
		   $(id).remove();
	   }
	};
	var oRequest = new Ajax.Updater({ 
		//success: "divCustomerInfo"
	}, path+"user/my_follow", oOptions);	
}

function successmessage(transport){
	  var notice = $('divCustomerInfo');
	  notice.update(transport.responseText).setStyle({ background: '#fdd' });
}
/*
* Function for Cehck and Update  User Rights
*/
function checkForgotPassword(){
	if(''==trim($("txtForgotEmail").value))
	{
		alert("Please enter email");
		$("txtForgotEmail").focus();
		return false;
	}
	document.loginform.action=path+'user/forgotpassword/';
	document.loginform.submit();
}
function checkForgotPasswordpop(path){
	if(''==trim($("txtForgotEmail").value))
	{
		alert("Please enter email");
		$("txtForgotEmail").focus();
		return false;
	}
	document.loginformpop.action=path+'user/forgotpassword/';
	document.loginformpop.submit();
}
function checkForgotClientPassword(){
	if(''==trim($("txtForgotEmail").value))
	{
		alert("Please enter email");
		$("txtForgotEmail").focus();
		return false;
	}
	document.logincheckform.action=path+'client/forgotpassword/';
	document.logincheckform.submit();
}
function showInfo(whois){
	if(whois!="user")
	{
			$("collegueDiv").className="msgNone";		
	}
	$("infoDiv").className="msgShow";
	$("messageDiv").className="msgNone";
}
function showMessges(whois){
	if(whois!="user")
	{
			$("collegueDiv").className="msgNone";
	}
	$("infoDiv").className		="msgNone";
	$("messageDiv").className	="msgShow";
}

function profile_tabs(ele){
	var tab_active = 'tab_'+ele;
	for(var i=1; i<=8; i++){
		if($('tab_'+i)) {
			$('tab_'+i).removeClassName('current');
		}
		if($('navigation_childs_'+i)) $('navigation_childs_'+i).style.display = 'none';
	}
	$(tab_active).addClassName('current');
	$('navigation_childs_'+ele).style.display = 'block';
	change_template_height();
}

function home_tabs(ele){
	var tab_active = 'tab_'+ele;
	for(var i=1; i<=5; i++){
		if($('tab_'+i)) $('tab_'+i).removeClassName('current');
		if($('navigation_childs_'+i)) $('navigation_childs_'+i).style.display = 'none';
	}
	$(tab_active).addClassName('current');
	$('navigation_childs_'+ele).style.display = 'block';
	change_template_height();
}
function search_tabs(ele){
	var tab_active = 'search_tab'+ele;
	for(var i=1; i<=5; i++){
		$('search_tab'+i).removeClassName('current');
		$('navigation_childs_'+i).style.display = 'none';
	}
	$(tab_active).addClassName('current');
	$('navigation_childs_'+ele).style.display = 'block';
	change_template_height();
}
function manage(name, ele, chcaption) {
	if(chcaption=='manage')
	{
		if(!confirm('Do you really want to Un Manage?')){
		 return;
		}
	}
	var oOptions = {
		method: "post",
		parameters: { user: name },
		onFailure: function (oXHR, oJson) {
			//alert("An error occurred: " + oXHR.status);
		},
		   onSuccess: function(transport){
		   var response = transport.responseText;
		    if(chcaption=='manage')
			{
				$(ele).innerHTML='';
			}
	   }
	};
	var oRequest = new Ajax.Updater({ 
	}, path+"user/manage_unmanage", oOptions);
}
function report(name, ele, chcaption) {
	if(chcaption=='report')
	{
		if(!confirm('Do you really want to Delete Report to?')){
		 return;
		}
	}
	var oOptions = {
		method: "post",
		parameters: { user: name },
		onFailure: function (oXHR, oJson) {
			//alert("An error occurred: " + oXHR.status);
		},
		   onSuccess: function(transport){
		   var response = transport.responseText;
		    if(chcaption=='report')
			{
				$(ele).innerHTML='';
			}
	   }
	};
	var oRequest = new Ajax.Updater({ 
	}, path+"user/report_unreport", oOptions);
}
function checkAndSaveProfile()
{
		if($("txtCurDate").value < $("txtProfileStartDate").value)
		{
			 $("txtProfileStartDate").focus();
			 alert("Profile Start Date Should be less than current Date")
			 return false;
		}
		if($("txtCurDate").value < $("txtBirthDate").value)
		{
			 $("txtBirthDate").focus();
			 alert("Birth Date Should be Less than current date")
			 return false;
		}	
		if($("txtCompanyStart1").value >$("txtCompanyEnd1").value)
		{
			 $("txtCompanyStart1").focus();
			 alert("Comapny Start Year Should Less than End Year")
			 return false;
		}
		if($("txtSchoolStart1").value >$("txtSchoolEnd1").value)
		{
			 $("txtSchoolStart1").focus();
			 alert("School Start Year Should Less than End Year")
			 return false;
		}
		var companystart = document.accountform.elements["txtCompanyStart[]"];
		var companyend = document.accountform.elements["txtCompanyEnd[]"];
		for(i=1;i<companystart.length;i++)
		{
		 if(companystart[i].value > companyend [i].value  )
		 {
			 companystart[i].focus();
			 alert("Comapny Start Year Should Less than End Year")
			 return false;
		 }
		}
		var schoolstart = document.accountform.elements["txtSchoolStart[]"];
		var  schoolend 	 = document.accountform.elements["txtSchoolEnd[]"];
		for(i=1;i<schoolstart.length;i++)
		{
		 if(schoolstart[i].value > schoolend [i].value  )
		 {
			 schoolstart[i].focus();
			 alert("School Start Year Should Less than End Year")
 			 return false;
		 }
		}
		 return true;
}
function getAjaxMembers(paths, id,member_id) {
	var oOptions = {
		method: "post",
		parameters: {'txtMember':member_id },
		onFailure: function (oXHR, oJson) {
			//alert("An error occurred: " + oXHR.status);
		},
		   onSuccess: function(transport){
		   var response = transport.responseText;
		   $(id).innerHTML=response;
	   }
	};
	var oRequest = new Ajax.Updater({ 
	}, path+paths, oOptions);
}
function inviteAgain(id,paths) {
	//alert(id+paths);
	var oOptions = {
		method: "post",
		parameters: {"txtId":id},
		onFailure: function (oXHR, oJson) {
			//alert("An error occurred: " + oXHR.status);
		},
		   onSuccess: function(transport){
		   var response = transport.responseText;
		   	alert('An invitation mail has been sent.');

		  //alert(response);
	   }
	};
	var oRequest = new Ajax.Updater({ 
	}, path+paths, oOptions);
}
function removeInvitation(id) {
	if(!confirm('Do you really want to Remove this invitation?')){
	 return;
	}
	var oOptions = {
		method: "post",
		parameters: {"txtId":id},
		onFailure: function (oXHR, oJson) {
			//alert("An error occurred: " + oXHR.status);
		},
		   onSuccess: function(transport){
		   var response = transport.responseText;
		   if(response==1)
		   {
			 getAjaxMembers('user/ajaxinvitation', 'navigation_childs_4',''); 
		 // 	getAjaxMembers('user/ajaxinvitation')
		   }else{
				alert(response);   
			}
	   }
	};
	var oRequest = new Ajax.Updater({ 
	}, path+"user/removeinvitation", oOptions);
}
function getLinks(paths,type,start) {
	group_id=0;
	if ($("txtGroupId")){
		group_id= $("txtGroupId").value;	
	}
	var oOptions = {
		method: "post",
		parameters: {"txtType":type, "txtStart":start,"txtGroupId":group_id},
		onFailure: function (oXHR, oJson) {
			//alert("An error occurred: " + oXHR.status);
		},
		   onSuccess: function(transport){
		   var response = transport.responseText;
		   if(type=='M')
		   {
			   	$("navigation_childs_2").innerHTML =response;		
		   }else if(type == 'A'){
				$("navigation_childs_1").innerHTML =response;		  
		   }else if(type == 'G'){
			   $("navigation_childs_8").innerHTML =response;
		   }
	   }
	};
	var oRequest = new Ajax.Updater({ 
	}, paths, oOptions);
}
function checkAndSavePayment(){
	if(''==trim($("txtCreditNumber").value))
	{
		alert("Please enter Credit card Number");
		$("txtCreditNumber").focus();
		return false;
	}
	if(''==trim($("txtCvv").value))
	{
		alert("Please enter Cvv Number");
		$("txtCvv").focus();
		return false;
	}
	if(''==trim($("txtFirstName").value))
	{
		alert("Please enter First Name");
		$("txtFirstName").focus();
		return false;
	}
	if(''==trim($("txtLastName").value))
	{
		alert("Please enter Last Name");
		$("txtLastName").focus();
		return false;
	}
	if('0'==trim($("dates").value))
	{
		alert("Please Select Month");
		$("txtLastName").focus();
		return false;
	}
	if('0'==trim($("years").value))
	{
		alert("Please Select Year");
		$("txtLastName").focus();
		return false;
	}
		return true;
}

