// JavaScript Document

    function submitOnEnter(e) {
            var ENTER_KEY = 13;
            var code = "";
      
            if (window.event) // IE
            {
                code = e.keyCode;
            }
            else if (e.which) // Netscape/Firefox/Opera
            {
                code = e.which;
            }
            
            if (code == ENTER_KEY) {
                do_login();
            }
      }




function check_login(response,platform)
{	
		
	$.ajax({
   type: "POST",
   url: "ajax_voting.php",
   data: "vote="+response+"&platform="+platform,
   success: function(msg){
	   arrMsg = msg.split(',');
	   if(arrMsg[0] == 'Y' || arrMsg[0] == 'N')
	      GB_showCenter("","login.php?vote="+arrMsg[0]+"&platform="+arrMsg[1],376,600);
	   if(arrMsg[0] == 'result_page')
	   {
		     if(arrMsg[1] == "W")
		     window.location.href = 'index.php';
			  if(arrMsg[1] == "F")
			  {
		        window.location.reload();
			  }
	   }
				
   }
 });
		
}

function check_login_iphone(response,platform)
{	
		
	$.ajax({
   type: "POST",
   url: "ajax_voting.php",
   data: "vote="+response+"&platform="+platform,
   success: function(msg){
	   arrMsg = msg.split(',');
	   if(arrMsg[0] == 'Y' || arrMsg[0] == 'N')
	    parent.parent.location.href = "http://ruhap.com/login.php?vote="+arrMsg[0]+"&platform="+arrMsg[1],376,600;  
	   if(arrMsg[0] == 'result_page')
	   {
		     if(arrMsg[1] == "W")
		     window.location.href = 'index.php';
			  if(arrMsg[1] == "F")
			  {
		        window.location.reload();
			  }
	   }
				
   }
 });
	
	
}



function hideDiv(div) {
	$(div).fadeOut('slow');
}

function showDiv(div) {
	$(div).fadeIn('slow');
}





function do_login(redirect)
{

	var username = $("#user").val();
	var password = $("#password1").val();
	var remember_user = "";
	//if ($post("remember_user").checked == true) {
	//	var remember_user = $("#remember_user").val();
	//}
	
	if ($('#remember_user').is(':checked')) { 
		
		remember_user = 'remember';
		
	} 
	

	
	
	do_login_second(username,password,remember_user,redirect);
}


function do_login_first(username,password,data)
{
	$("#login-email-address").val(username);
	$("#login-password").val(password);
	$("#securityToken").val(data);
	document.login.submit();
	
}
function do_login_second(username,password,remember_user,redirect)
{
	$.ajax({
   type: "POST",
   url: "ajax_login.php",
   data: "username="+username+"&password="+password+"&remember_user="+remember_user,
   beforeSend: function(){
				$("#error").html('<img src="../images/loading.gif" />');
			},
   success: function(msg){
	   arrMsg = msg.split(',');
	   if(arrMsg[0] == 'already_voted' || arrMsg[0] == 'show_result' || arrMsg[0] == 'go_to_index')
	   {
		 if (false) {
		 parent.parent.location.href = 'zen-bridge/zen_login.php?username='+username+'&password='+password+'&redirect='+redirect;
		}
		else {
		  if(arrMsg[1] != 'W' && arrMsg[1] != 'F')
			parent.parent.location.href = 'zen-bridge/zen_login.php?username='+username+'&password='+password+'&redirect='+redirect;
		  if(arrMsg[1] == "W")
	        parent.parent.location.href = 'zen-bridge/zen_login.php?username='+username+'&password='+password;
		  if(arrMsg[1] == "F")
		  {
		    parent.parent.location.href = 'zen-bridge/zen_login.php?username='+username+'&password='+password;
			//parent.parent.location.reload();
		  }
		}
	   }
	
		if(arrMsg[0] == 'invalid')
		$("#error").html('Invalid Email or Password.');
		if(arrMsg[0] == 'confirm')
		$("#error").html('Before logging into ruHap you must verify your account information. Please look in your email inbox for a message from ruHap - and you will quickly be on your way to greater Happiness!');
		if(arrMsg[0] == 'newuser')
		$("#error").html('Please <a href="http://www.ruhap.com/register.php" style="color:#00a2e0">click here</a> to join ruHap.');
				
   }
 });
}
function admin_login()
{
	
	var username = $("#username").val();
	var password = $("#password").val();
	 $.ajax({
   type: "POST",
   url: "../ajax_admin_login.php",

   data: "action=admin_login&username="+username+"&password="+password,
   beforeSend: function(){
				$("#error").html('<img src="images/loading.gif" />');
			},
   success: function(msg){
	   if(msg == 'success')
	   {
		   //alert('test');
	     window.location.href = 'dashboard.php';
	   }
	   if(msg == 'fail')
	   {
		$("#error").html('Inavalid Username or Password');
	   }
		
   }
 });
	
	
}


function logout()
{
	
	//document.cookie="user_remembered=";
	
	 $.ajax({
   type: "POST",
   url: "/ajax_logout.php",
    success: function(msg){
		//parent.parent.location.href = 'index.php';	
		//parent.parent.location.href = 'zen-bridge/zen_logout.php';
		parent.parent.location.href = 'http://ruhap.com/zen-bridge/zen_logout.php';
   }
 });
	
	
}

function admin_logout()
{
	 $.ajax({
   type: "POST",
   url: "../ajax_admin_login.php",
   data: "action=admin_logout",
    success: function(msg){
		window.location.href = 'index.php';	
   }
 });
	
	
}


//function call when user register

function register_user()
{
	//alert('dayquote: ' + $("#dayquote").val());
	$.ajax({
   				type: "POST",
			    url: "ajax_register.php",
				data: "first_name="+$("#tbl_first_name").val()+"&last_name="+$("#tbl_last_name").val()+"&email="+$("#tbl_email").val()+"&password="+$("#tbl_password").val()+"&gender="+$("#gender").val()+"&choosingvoting="+$("#voting_option").val()+"&newsletter="+$("#newsletter").val()+"&blog="+$("#blogsubs").val()+"&poll="+$("#poll").val()+"&dayquote="+$("#dayquote").val()+"&mobile_confirm="+$("#mobile_confirm").val(),
				 beforeSend: function(){
					
				$("#error").html('<img src="../images/loading.gif" />');
			},
			    success: function(data)
				{
					
					arrMessage	=	data.split("Error:");
                  // alert(data);
					
					if(arrMessage.length == 2)
					{
						if(arrMessage[1])
							$("#error").html(arrMessage[1]);
							jAlert(arrMessage[1], 'ERROR');
							//alert(arrMessage[1]);
					}
					else
					{
						arrMessage	=	data.split("Success:");
						if(arrMessage[1])
							$("#error").html(arrMessage[1]);
                            $('form :input').val("");
							parent.parent.location.href = 'http://ruhap.com/?userRegistered=1';
							//jAlert(arrMessage[1], 'SUCCESS');
							//alert(arrMessage[1]);
					}
		   		}
 });
	
}


function add_user()
{
	$.ajax({
   				type: "POST",
			    url: "../ajax_admin_login.php",
				data: "action=addUser&first_name="+$("#tbl_first_name").val()+"&last_name="+$("#tbl_last_name").val()+"&email="+$("#tbl_email").val()+"&password="+$("#tbl_password").val()+"&gender="+$("#gender").val()+"&action_type="+$("#submit").val()+"&userid="+$("#userid").val(),
				 beforeSend: function(){
				$("#error").html('<img src="../images/loading.gif" />');
			},
			    success: function(data)
				{	
					arrMessage	=	data.split("Error:");
					
					if(arrMessage.length == 2)
					{
						if(arrMessage[1])
							$("#error").html(arrMessage[1]);
					}
					else
					{
						arrMessage	=	data.split("Success:");
					
						if(arrMessage[1])
							$("#error").html(arrMessage[1]);
					}
					
		   		}
 });
	
}

function update_admin()
{
	$.ajax({
   				type: "POST",
			    url: "../ajax_admin_login.php",
				data: "action=updateAdmin&username="+$("#tbl_username").val()+"&email="+$("#tbl_email").val()+"&password="+$("#tbl_password").val(),
				 beforeSend: function(){
				$("#error").html('<img src="../images/loading.gif" />');
			},
			    success: function(data)
				{	
					arrMessage	=	data.split("Error:");
					
					if(arrMessage.length == 2)
					{
						if(arrMessage[1])
							$("#error").html(arrMessage[1]);
					}
					else
					{
						arrMessage	=	data.split("Success:");
					
						if(arrMessage[1])
							$("#error").html(arrMessage[1]);
					}
					
		   		}
 });
	
}

$(document).ready(function()
{
	
	$('body #mainWrapper #mainInner #contentMainWrapper .verti_links #categoriesContent .category-products').parent().addClass('subCat');
	
	$(".category-subs-selected").parent().parent().addClass('nav_current');
	
	$(".category-subs-selected").parent().parent('.subCat').removeClass('nav_current');
	$(".category-subs-selected").parent().parent('.subCat').addClass('nav_current_sub');
	$(".category-subs-parent").parent().parent().addClass('nav_current');
	
//	$(".category-subs-selected").parent().parent().addClass('nav_current_sub');
//	$(".category-subs-parent").parent().parent().addClass('nav_current');
	
	//$(".nav_current").parent().parent().parent().parent().children().eq(0).children().eq(1).removeClass('products_home');
	$(".nav_current_sub").parent().children('.nav_current').removeClass('nav_current');
	
	if (!$(".category-subs-parent").html() && !$(".category-subs-selected").html()) {
		$('#products_home').addClass('products_home');
	}
	
	
	
	
	
	
	 $("#formsubscribe").validate({
			rules: {
				subscriber_name: {required: true},														
				subscriber_email: {required: true}
				},
		messages: {
				subscriber_name: {required:"Name is required"},
				subscriber_email:{required :"Enter valid Email Address"}
				}			   
		});	
	
			

						
});

function logout_inner()
{
	 $.ajax({
   type: "POST",
   url: "../../../../ajax_logout.php",
    success: function(msg){
		//parent.parent.location.href = 'index.php';	
		parent.parent.location.href = '../../../../zen-bridge/zen_logout.php';
   }
 });
	
	
}


