

function validateSignUp(){

		var username=trim(document.getElementById('username').value);
		var password=document.getElementById('password').value;
		var re_password=document.getElementById('re_password').value;
		var email=trim(document.getElementById('email').value);
		var user_cardboox=trim(document.getElementById('user_cardboox').value);						
		var agree=$('#agree_chk').is(':checked');
		
		
		if(username=='')
		{
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter username.');
			return false;
		}
		
		if(username=='username')
		{
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('You cannot use this username. Please enter other username.');
			return false;
		}
		
		if(!is_valid_username(username)){
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter valid username.');
			return false;
		}
		
		if(password=='')
		{
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter password.');
			return false;
		}
		
		if(!is_valid_password(password)){
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter valid password.');
			return false;
		}
		
		if(re_password=='')
		{
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please retype password.');
			return false;
		}
		
		if(password!=re_password){
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Password and retype password do not match.');
			return false;
		}
		
		if(email=='')
		{
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter email.');
			return false;
		}
		
		if(!is_valid_email(email)){
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter valid email.');
			return false;
		}
		
		if(user_cardboox=='')
		{
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter cardboox name.');
			return false;
		}
				
		if(user_cardboox!='')
		{
			if(!is_valid_folder_name(user_cardboox)){
				$("#uboox_errDiv").show();
				$("#uboox_errDiv").text('Please enter valid cardboox name.');
				return false;
			}						
		}
		
		if(!agree)
		{
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please confirm terms and conditions.');
			return false;
		}

	$("#uboox_errDiv").hide();
	return true;
			
}

function validateSignIn(){

		var username=trim(document.getElementById('username').value);
		var password=document.getElementById('password').value;		
		
		if(username=='username' || username=='')
		{
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter username.');
			return false;
		}
		
		if(!is_valid_username(username)){
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter valid username.');
			return false;
		}
		
		if(password=='password' || password=='')
		{
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter password.');
			return false;
		}
		
		if(!is_valid_password(password)){
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter valid password.');
			return false;
		}
		
	$("#uboox_errDiv").hide();
	return true;		
}


function validateCardboox(){
	var user_cardboox=trim(document.getElementById('user_cardboox').value);
	
	if(user_cardboox!='')
	{
			if(!is_valid_folder_name(user_cardboox)){
				$("#uboox_errDiv").show();
				$("#uboox_errDiv").text('Please enter valid cardboox name.');
				return false;
			}						
	}
	else{
		return false;
	}
	return true;
}


function fnDelUser(url){
	if(confirm("Are you sure want to delete your cardboox account? All your cards will be deleted if you delete your account.")){
		window.location.href= url;
	}
}

function validateForgotPwd(){

		var email=trim(document.getElementById('email').value);
		
		if(email=='email' || email=='')
		{
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter your email.');
			return false;
		}
		
		if(!is_valid_email(email)){
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter valid email.');
			return false;
		}
		
	$("#uboox_errDiv").hide();
	return true;		
}

function validateResetPwd(){

	var password=document.getElementById('password').value;
	var re_password=document.getElementById('re_password').value;
	
	if(password=='')
		{
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter password.');
			return false;
		}
		
		if(!is_valid_password(password)){
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter valid password.');
			return false;
		}
		
		if(re_password=='')
		{
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please retype password.');
			return false;
		}
		
		if(password!=re_password){
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Password and retype password do not match.');
			return false;
		}
	$("#uboox_errDiv").hide();
	return true;

}

function validateChangePwd(){

	var old_password=document.getElementById('old_password').value;
	var password=document.getElementById('password').value;
	var re_password=document.getElementById('re_password').value;
	
		if(old_password=='' && password=='' && re_password=='' )
		{			
			$("#uboox_errDiv").hide();
			return true;			
		}else{
		
			if(old_password=='')
			{
				$("#uboox_errDiv").show();
				$("#uboox_errDiv").text('Please enter old  password.');
				return false;
			}
		
			if(!is_valid_password(old_password)){
				$("#uboox_errDiv").show();
				$("#uboox_errDiv").text('Please enter valid old password.');
				return false;
			}
		
			if(password=='')
			{
				$("#uboox_errDiv").show();
				$("#uboox_errDiv").text('Please enter new password.');
				return false;
			}
		
			if(!is_valid_password(password)){
				$("#uboox_errDiv").show();
				$("#uboox_errDiv").text('Please enter valid new password.');
				return false;
			}
		
			if(re_password=='')
			{
				$("#uboox_errDiv").show();
				$("#uboox_errDiv").text('Please retype password.');
				return false;
			}
		
			if(password!=re_password){
				$("#uboox_errDiv").show();
				$("#uboox_errDiv").text('Password and retype password do not match.');
				return false;
			}
			
			
		}
	$("#uboox_errDiv").hide();
	return true;

}

function signIn(){

var valid=validateSignIn();
	if(valid){
		var baseUrl=$('#P_SITE_BASE_URL').val();
		var action='user_boox';
						
		var unm=$('#username').val();
		var pwd=$('#password').val();
		var query =	"mod=signin&ajax=1&formsubmit=1&unm="+unm+"&pwd="+pwd;
				
		var actionUrl = baseUrl + action;
		
		$.ajax({
		type: "POST",
		url: actionUrl,
		data: query,
		cache: false,
		success: function(responseMsg){		
			
			var responseObj=eval(responseMsg);
			if(responseObj[0].status==1){								
				  var cbname=responseObj[0].cardboox	
				 reload_page(baseUrl+''+cbname);
				}
			else{
				$("#uboox_errDiv").show();												
				document.getElementById("uboox_errDiv").innerHTML = responseObj[0].err;											
			}							 			 
		
		}
		});
	}
}

function signUp(){

var valid=validateSignUp();
	if(valid){
		
		var baseUrl=$('#P_SITE_BASE_URL').val();
		var action='user_boox';
						
		var unm=$('#username').val();
		var pwd=$('#password').val();
		var eml=$('#email').val();
		var cboox=$('#user_cardboox').val();
		
		var query =	"mod=signup&ajax=1&formsubmit=1&unm="+unm+"&pwd="+pwd+"&eml="+eml+"&cboox="+cboox;
				
		var actionUrl = baseUrl + action; 
		
		$.ajax({
		type: "POST",
		url: actionUrl,
		data: query,
		cache: false,
		success: function(responseMsg){

			var responseObj=eval(responseMsg);
			if(responseObj[0].status==1){
				$("#frmDiv").hide();
			    $("#uboox_errDiv").hide();
				$("#uboox_successDiv").show();
				document.getElementById("uboox_successDiv").innerHTML = responseObj[0].msg;							
				}
			else{
				$("#uboox_errDiv").show();						
				document.getElementById("uboox_errDiv").innerHTML = responseObj[0].msg;																					
			}
										 			 
		}
		});
	}
}


function signin_forgot_pwd(){

	var email=trim($('#email').val());

		if(email!='')
		{
			forgotPwd();
		}
		else{
			signIn();
		}
}

function forgotPwd(){

var valid=validateForgotPwd();

if(valid){
		var baseUrl=$('#P_SITE_BASE_URL').val();
		var action='user_boox';
		
		var eml=$('#email').val();		
		
		var query =	"mod=forgotPwd&ajax=1&formsubmit=1&eml="+eml;
				
		var actionUrl = baseUrl + action;
		
		$.ajax({
		type: "POST",
		url: actionUrl,
		data: query,
		cache: false,
		success: function(responseMsg){				
			var responseObj=eval(responseMsg);
			if(responseObj[0].status==1){
				$("#frmDiv").hide();
			    $("#uboox_errDiv").hide();
				$("#uboox_successDiv").show();
				document.getElementById("uboox_successDiv").innerHTML = responseObj[0].msg;							
				}
			else{
				$("#uboox_errDiv").show();						
				document.getElementById("uboox_errDiv").innerHTML = responseObj[0].msg;																					
			}							 			 
		}
		});
	}



}

function resetPwd(){

var valid=validateResetPwd();

if(valid){
		var baseUrl=$('#P_SITE_BASE_URL').val();
		var action='resetPwd';
		
		var email=$('#email').val();
		var token=$('#token').val();
		var pwd=$('#password').val();		
		
		var query =	"ajax=1&formsubmit=1&email="+email+"&token="+token+"&pwd="+pwd;
				
		var actionUrl = baseUrl + action;
		
		$.ajax({
		type: "POST",
		url: actionUrl,
		data: query,
		cache: false,
		success: function(responseMsg){		
				
			var responseObj=eval(responseMsg);
			if(responseObj[0].status==1){
				$("#frmDiv").hide();
			    $("#uboox_errDiv").hide();
				$("#uboox_successDiv").show();
				document.getElementById("uboox_successDiv").innerHTML = responseObj[0].msg;							
				}
			else{
				$("#uboox_errDiv").show();						
				document.getElementById("uboox_errDiv").innerHTML = responseObj[0].msg;																					
			}							 			 
		}
		});
	}



}

function show_signin(){

			var baseUrl=$('#P_SITE_BASE_URL').val();

			jQuery.facebox(function() {
			  jQuery.get(baseUrl+'user_boox/mod/signin/ajax/1', function(data) {
			    jQuery.facebox('' + data + '')
			  })
			})


}

function validMenuSettings(){

		var user_cardboox=trim($('#user_cardboox').val());		
		var agree=$('#agree_chk').is(':checked');
		var rows=trim($('#rows').val());
		var url_home=trim($('#url_home').val());
		var url_twitter=trim($('#url_twitter').val());

		if(user_cardboox=='')
		{
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter cardboox name.');
			return false;
		}
				
		if(user_cardboox!='')
		{
			if(!is_valid_folder_name(user_cardboox)){
				$("#uboox_errDiv").show();
				$("#uboox_errDiv").text('Please enter valid cardboox name.');
				return false;
			}						
		}
		
		if(rows==''){
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter number of rows for your cards.');
			return false;
		}

		if(!is_numeric(rows)){
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter numeric value for rows.');
			return false;		
		}
		
		if(rows>20){
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Maximum 20 rows are allowed.');
			return false;		
		}
		
		if(url_home==''){
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter url for your home.');
			return false;
		}
		url_home='http://'+url_home;
		
		if(!is_valid_url(url_home)){
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please enter valid url for home.');
			return false;		
		}
		
		if(url_twitter!=''){
		
			if(!is_valid_folder_name(url_twitter)){
				$("#uboox_errDiv").show();
				$("#uboox_errDiv").text('Please enter valid twitter url.');
				return false;
			}
		}
		
		
		validChangePwd=validateChangePwd();

		if(!validChangePwd)
		{
		return false;
		}

		if(!agree)
		{
			$("#uboox_errDiv").show();
			$("#uboox_errDiv").text('Please confirm terms and conditions.');
			return false;
		}

$("#uboox_errDiv").hide();
return true;
}


function saveMenuSettings(){
 	 
 var valid=validMenuSettings();
 
 if(valid)
 {
	 var cboox=trim($('#user_cardboox').val());
	 var order_by = $("input[@name='order_by']:checked").val();
	 
	 var selectedItems = new Array();
	 $("input[@name='chk_display_option[]']:checked").each(function() {selectedItems.push($(this).val());});
	 
	 var rows=trim($('#rows').val());
	 var bg_colour = $("input[@name='bg_colour']:checked").val();
	 
	 var url_home=trim($('#url_home').val());
	 
	 var open_home_in = $("input[@name='open_home_in']:checked").val();
	 
	 var url_twitter=trim($('#url_twitter').val());
 
 	 var baseUrl=$('#P_SITE_BASE_URL').val();
 	 
		var action='user_boox';
						
		var old_pwd=$('#old_password').val();		
		
		var pwd=$('#password').val();
		
		var query =	"mod=menu&ajax=1&formsubmit=1&old_pwd="+old_pwd+"&pwd="+pwd+"&order_by="+order_by+"&cboox="+cboox+"&rows="+rows+"&bg_colour="+bg_colour+"&url_home="+url_home+"&open_home_in="+open_home_in+"&url_twitter="+url_twitter+"&layout_options="+selectedItems;			
				
		var actionUrl = baseUrl + action; 
		
		$.ajax({
		type: "POST",
		url: actionUrl,
		data: query,
		cache: false,
		success: function(responseMsg){
			var responseObj=eval(responseMsg);			
			
			if(responseObj[0].status==1){
				$("#frmDiv").hide();
			    $("#uboox_errDiv").hide();
				$("#uboox_successDiv").show();
				document.getElementById("uboox_successDiv").innerHTML = responseObj[0].msg;				
				var cbname=responseObj[0].cardboox					 
				
				window.setTimeout('reload_page(\"'+baseUrl+cbname+'\")',3000);							
				}
			else{
				$("#uboox_errDiv").show();						
				document.getElementById("uboox_errDiv").innerHTML = responseObj[0].msg;																					
			}
										 			 
		}
		});
 
 }
 
}

function changeText(chk_name){
var chkd=$('#'+chk_name).is(':checked');
var txt_id='#txt_'+chk_name;

if(chk_name!='navigation'){	 
	 if(chkd)
	 {
	 $(txt_id).text('on');	 
	 }
	 else{
	 $(txt_id).text('off');
	 }
}
else{
	if(chkd)
	 {
	 $(txt_id).text('top');	 
	 }
	 else{
	 $(txt_id).text('bottom');
	 }

}
}
