
 function alltrim(str) 
 {
      return str.replace(/^\s+|\s+$/g, '');
 }
//------------------------------------------------------------------------
			   //******** Jquery Form  functions ***********
//-----------------------------------------------------------------------
$(document).ready(function() {
		
						   
//----------------------------------------------------------------------------
//This code is Used for Login 
//----------------------------------------------------------------------------
	var options_login = 
	{ 
		beforeSubmit: loginRequest,  // pre-submit callback 
		success:  showResponse_login // post-submit callback 
	}; 

	$('#loginForm').submit(function() 
	{ 
		$(this).ajaxSubmit(options_login); 
		 return false; 
	});

	function loginRequest(formData, jqForm, options) 
	{ 
		var queryString = $.param(formData); 
	 //  alert('About to submit: \n\n' + queryString); 
		return true; 
	} 

	function showResponse_login(responseText)
	{
		//var str_array=responseText.split("_");
		
		
		
		if (alltrim(responseText) == 'yes')
		{
			window.location=RU;
		}else if(alltrim(responseText) == 'yes_pop'){
		  setTimeout( function() { location.reload(); }, 100 );	
	   }else
		{
		    $("#error_div").fadeIn("slow");
		    $("#error_div").html(responseText);
		}
		/*else if(str_array[0] == 'yes')
		{
			$("#popupContact").fadeOut("slow");
			$("#backgroundPopup").fadeIn("slow");
			//location.reload();
			setTimeout( function() { window.location=RU+"Profile/"+str_array[1]; }, 100 );
		}*/
	}
	
	
//----------------------------------------------------------------------------
//This code is Used for Main Login 
//----------------------------------------------------------------------------
	var options_login2 = 
	{ 
		beforeSubmit: loginRequest2,  // pre-submit callback 
		success:  showResponse_login2 // post-submit callback 
	}; 

	$('#loginForm2').submit(function() 
	{ 
		$(this).ajaxSubmit(options_login2); 
		 return false; 
	});

	function loginRequest2(formData, jqForm, options) 
	{ 
		var queryString = $.param(formData); 
	 //  alert('About to submit: \n\n' + queryString); 
		return true; 
	} 

	function showResponse_login2(responseText)
	{
		 
		if (alltrim(responseText) =='yes')
		{
			//window.location=RU;
			 setTimeout( function() { location.reload(); }, 100 );	
		}else if(alltrim(responseText) =='yes_pop'){
		    setTimeout( function() { location.reload(); }, 100 );	
	   }else
		{
		    $("#error_div2").fadeIn("slow");
		    $("#error_div2").html(responseText);
		}
		
	}

 //-------------------------------------------------------------------------------
                 // update profile 
  //------------------------------------------------------------------------------
 
   var options_update_profile = 
	{ 
		beforeSubmit: Request_update_profile,  // pre-submit callback 
		success:  showResponse_update_profile // post-submit callback 
	}; 

	$('#updateProflie').submit(function() 
	{ 
		$(this).ajaxSubmit(options_update_profile); 
		 return false; 
	});

	function Request_update_profile(formData, jqForm, options) 
	{ 
		var queryString = $.param(formData); 
	  // alert('About to submit: \n\n' + queryString); 
		return true; 
	} 

	function showResponse_update_profile(responseText)
	{  
	    $("#res_div").fadeIn("slow");
		//alert(responseText);
	    $('html, body').animate({ scrollTop:$('#res_div').offset('slow').top},100);
		if(responseText == 'yes')
		{   
		    $("#res_div").html("<b> Profile Updated Successfully </b>"); 
	        $("#res_div").fadeOut(5000);
			setTimeout( function() { location.reload(); }, 5000 );
			
		}else 
		{ 
		    $("#res_div").fadeIn("slow");
		    $("#res_div").html(responseText);
		}

		
	}
 
//-------------------------------------------------------------------------------
                 // Change Password  
  //------------------------------------------------------------------------------
 
   var options_change_password = 
	{ 
		beforeSubmit: Request_change_password,  // pre-submit callback 
		success:  showResponse_change_password // post-submit callback 
	}; 

	$('#changePassForm').submit(function() 
	{ 
		$(this).ajaxSubmit(options_change_password); 
		 return false; 
	});

	function Request_change_password(formData, jqForm, options) 
	{ 
		var queryString = $.param(formData); 
	  // alert('About to submit: \n\n' + queryString); 
		return true; 
	} 

	function showResponse_change_password(responseText)
	{  
	    $("#res_div").fadeIn("slow");
	    
		if(responseText == 'yes')
		{   $('#changePassForm').clearForm();
		    $("#res_div").html("<b> Your Password has been changed successfully , an email has been sent to you containing new password.  </b>"); 
	        $("#res_div").fadeOut(19000);
		}else 
		{ 
		    $("#res_div").fadeIn("slow");
		    $("#res_div").html(responseText);
		}

		
	}


  //-------------------------------------------------------------------------------
                 //  Comment Form Add
  //------------------------------------------------------------------------------
 
    var options_addComment = 
	{ 
		beforeSubmit: Request_addComment,  // pre-submit callback 
		success:  showResponse_addComment // post-submit callback 
	}; 

	$('#commentForm').submit(function() 
	{ 
		$(this).ajaxSubmit(options_addComment); 
		 return false; 
	});

	function Request_addComment(formData, jqForm, options) 
	{ 
		var queryString = $.param(formData); 
	   //alert('About to submit: \n\n' + queryString); 
		return true; 
	} 

	function showResponse_addComment(responseText)
	{  
	    $("#res_div").fadeIn("slow");
	    
		if(responseText == 'Comments added Successfully')
		{   
		    $("#res_div").html("<b>Comments added Successfully</b>"); 
			$('#commentForm').clearForm();
	        $("#res_div").fadeOut(3000);
			setTimeout( function() { location.reload(); }, 3000 );
			
		}else 
		{ 
		    $("#res_div").fadeIn("slow");
		    $("#res_div").html(responseText);
		}
       
		
	}
	
	
	 //-------------------------------------------------------------------------------
                 //  Reply Comment 
  //------------------------------------------------------------------------------
 
    var options_repComment = 
	{ 
		beforeSubmit: Request_repComment,  // pre-submit callback 
		success:  showResponse_repComment // post-submit callback 
	}; 

	$('#commentRepForm').submit(function() 
	{ 
		$(this).ajaxSubmit(options_repComment); 
		 return false; 
	});

	function Request_repComment(formData, jqForm, options) 
	{ 
		var queryString = $.param(formData); 
	   // alert('About to submit: \n\n' + queryString); 
		return true; 
	} 

	function showResponse_repComment(responseText)
	{  
	    $("#res_div").fadeIn("slow");
	   // alert(responseText);
		if(responseText == 'yes')
		{   
		    $("#res_div").html("<b>Comments added Successfully</b>"); 
			$('#commentRepForm').clearForm();
	        $("#res_div").fadeOut(3000);
			setTimeout( function() { location.reload(); }, 3000 );
			
		}else 
		{ 
		    $("#res_div").fadeIn("slow");
		    $("#res_div").html(responseText);
		}
       
		
	}
	
	//-------------------------------------------------------------------------------
                 //  Comment Form Update
  //------------------------------------------------------------------------------
 
    var options_editComment = 
	{ 
		beforeSubmit: Request_editComment,  // pre-submit callback 
		success:  showResponse_editComment // post-submit callback 
	}; 

	$('#commenteditForm').submit(function() 
	{ 
		$(this).ajaxSubmit(options_editComment); 
		 return false; 
	});

	function Request_editComment(formData, jqForm, options) 
	{ 
		var queryString = $.param(formData); 
	  //  alert('About to submit: \n\n' + queryString); 
		return true; 
	} 

	function showResponse_editComment(responseText)
	{  
	    $("#res_adddiv1").fadeIn("slow");
	    //$('html, body').animate({ scrollTop:$('#red_header').offset('slow').top},1000);
		if(responseText == 'Comments updated Successfully')
		{   
		    $("#res_adddiv1").html("<b>Comments updated Successfully</b>"); 
			$('#commenteditForm').clearForm();
	        $("#res_adddiv1").fadeOut(3000);
			//$("#res_adddiv1").fadeOut("slow");
			
			setTimeout( function() { location.reload(); }, 3000 );
			
		}else 
		{ 
		    $("#res_adddiv1").fadeIn("slow");
		    $("#res_adddiv1").html(responseText);
		}
       
		
	}
	



});





