$(function() {
	//$('form input.help, form textarea.help').formtips({tippedClass: 'tipped'});
	$('#refimage').click(function(){refreshcap();});
	//$('#password').pstrength();
	
	
	$(".sliderr").click(function(){

  	$(this).parent().parent().next().find("table:first").toggle();
  	return false;
	});
	
	$("#navsimpcont ul li a").click(function(){
	
	$(".simptabcont:visible").hide();
	$("#navsimpcont ul li a").removeClass('current');
	$(this).addClass('current');
	
	acontent=$(this).attr('href');
	$(acontent).fadeIn();
	return false;

});  
	
	$("#myform").validate({
	
	success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("valid");
		},

	submitHandler:function(form)
		{ 
			$("#submit").attr("disabled","disabled");
			$.ajax(
				{
					type:'post',
					url:'models/signup.php',
					data:$("#myform").serialize(),
					success:function(data)
					{
					if(data==3){
					    	$.prompt('<label class="error">Wrong Captcha Answer !</label>',{callback:function(){$("#submit").removeAttr("disabled");	}});
                            refreshcap();
					}else if(data==2){
					    	$.prompt('<label class="error">Email already exists !</label>',{callback:function(){$("#submit").removeAttr("disabled");	}});
                            }else if(data==4){
					    	$.prompt('<label class="error">Referrer ID supplied is invalid !</label>',{callback:function(){$("#submit").removeAttr("disabled");	}});
					}else if(data==0){
					   $.prompt('<label class="success">You have been successfully registered.<br>An activation email has been sent to you. Click OK</label>',{callback:function(){$("#submit").removeAttr("disabled");	}});
                       window.location="index.php?a=active";
					}	
					
						
					}
				});
				
		},
		rules:
		{
			fullname:"required",
			emailid:{required:true,email:true},
			confirmemail:{required:true,email:true,equalTo:"#emailid"},	
            	title:{required:true},
  	        lastname:{required:true},
            	address:{required:true},
                	dob:{required:true,date:true},
			password:{required:true},
			confirmpass:{required:true,equalTo:"#password"},
			secques:{required:true},
			secans:{required:true},
			t_code:{required:true,number:true},
			ct_code:{required:true,number:true},
			country:{required:true},
			address:{required:true},
			city:{required:true},
			state:{required:true},
			phone:{required:true},
			captcha:{required:true}
			
		},
		messages:
		{
 			fullname:{required:"This field cannot be left empty"},
			emailid:{required:"This field cannot be left empty",email:"Please enter a valid email address!",remote:"Email exists.Choose another one !"},	
			confirmemail:{required:"This field cannot be left empty",equalTo:"Emails do not match !"},	  
			title:{required:"This field cannot be left empty"},
            lastname:{required:"This field cannot be left empty"},
            address:{required:"This field cannot be left empty"},
            dob:{required:"This field cannot be left empty"},
			password:{required:"This field cannot be left empty"},	
			confirmpass:{required:"This field cannot be left empty",equalTo:"Passwords do not match !"},	  
			secques:{required:"This field cannot be left empty"},
			secans:{required:"This field cannot be left empty"},
			t_code:{required:"This field cannot be left empty",number:"Should be a number"},
			ct_code:{required:"This field cannot be left empty",number:"Should be a number",equalTo:"Transaction Codes should match !"},	
			country:{required:"This field cannot be left empty"},
			address:{required:"This field cannot be left empty"},
			city:{required:"This field cannot be left empty"},
			state:{required:"This field cannot be left empty"},
			phone:{required:"This field cannot be left empty"},
			captcha:{required:"This field cannot be left empty",remote:"Wrong captcha code entered !"},
			agree:{required:"You must agree to the TOS"}
		}
 	});

	$("#logform").validate({
	success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("valid");
		},
	submitHandler:function(form)
		{ 
			$("#login1").attr("disabled","disabled");   	
			$.ajax({
				   url:'models/login.php',
				   type:'POST',
				   data:$('#logform').serialize(),
				   success:function(data)
				   	{
				   	     
					    if(data=="Activation")
						{
				 	location.href="index.php?a=active";  
                    $("#username").val(data);
						}
						else if(data=="Wrong")	
						   {
					$.prompt('<label class="error">Member ID and Password combination are wrong</label>',{callback:function(){$("#login1").removeAttr("disabled");	}}); 		      
						   }else if(data=="Successful") {
						      location.href="account/";
						   }else if(data=="captcha"){
						     $.prompt('<label class="error">Wrong Captcha Answer !</label>',{callback:function(){$("#login1").removeAttr("disabled");	}}); 
                             refreshcap(); 
						   }
	        		
					}
				});
    				  
	
		},
		rules:
		{
			username:{required:true},
			password:{required:true},
			captcha:{required:true}
					
		},
		messages:
		{
 			
			username:{required:"This field cannot be left empty"},
			password:{required:"This field cannot be left empty"},	
			captcha:{required:"This field cannot be left empty",remote:"Wrong captcha code entered !"}
			
		}
 	});


 });




// Refresh Captcha //////////////////////////////////////////////////////////////////////////

function refreshcap()
	{
	$.ajax({url:'models/refreshcap.php',type:'get',
					success:function(data){
				      $("#capcont").html(data)     ;
							 }
		 			 }); return false;
	}

//////////////////////////////////////////////////////////////////////////////////////////////////

	
// Ajax Tab Loader //////////////////////////////////////////////////////////////////////////

function inittabs()
	{
		loadTabContent($(".current").attr("href"));
		$(".navcontainer ul li a").click(function(){	
								
					tabUrl = $(this).attr("href");
					if($('#stype').length!=0){
					tabUrl+="&type="+$('#stype').val();
					}
					if($('#fromdate').length!=0){
					tabUrl+="&fromdate="+$('#fromdate').val();
					}
					if($('#todate').length!=0){
					tabUrl+="&todate="+$('#todate').val();
					}
					
					
	    			$("a.current").removeClass("current");
					$(this).addClass("current");
					loadTabContent(tabUrl);
					return false;
				});
	}

function loadTabContent(tabUrl){
				$("#tabcontent").html("<center><img src='./images/ajax.gif' style='margin:20px 0px 6px 0px'/></center>");
				$.ajax({
					url: tabUrl, 
					cache: false,
					success: function(message) {
						
						$("#tabcontent").html(message);
						
					}
				});
			return false;
			}

///////////////////////////////////////////////////////////////////////////////////////////////////


// My Deposits ///////////////////////////////////////////////////////////////////////////////////

function changecomp(depid1)
	{
		$.prompt('Are you sure you want to change the compound percentage ?',{ buttons: { Yes: true, No: false } ,
		callback:function(v,m,f)
			{
				if(v==true)
				  {
				  	compval1=$('#compval').val();
					page1=$('#page').val();
					url1=$(".navcontainer ul li a.current").attr('href');
					url1+="&page="+page1;
					$.ajax({url:'./index.php',type:'post',data:{chngcomp:1,depid:depid1,compval:compval1},
					success:function(data){
					$.prompt(data,{callback:function(){loadTabContent(url1);}});
							 }
		 			 });	  		
				  }
					else {} 
			
			
			}}
		);
		  	
	}



////////////////////////////////////////////////////////////////////////////////////////////////


// History Area ///////////////////////////////////////////////////////////////////////////////

function cancelwith(id1)
	{
		$.prompt('Are you sure you want to cancel this withdrawal request ?',{ buttons: { Yes: true, No: false } ,
		callback:function(v,m,f)
			{
				if(v==true)
				  {
				  	type1=$('#type').val();
					page1=$('#page').val();
					fromdate1=$('#fromdate').val();
					todate1=$('#todate').val();	
					url1=$('.navcontainer ul li a.current').attr('href');
					url1+="&type="+type1+"&page="+page1+"&fromdate="+fromdate1+"&todate="+todate1;
					$.ajax({url:'./index.php',type:'post',data:{withcancel:1,id:id1},
					success:function(data){
					$.prompt(data,{callback:function(){loadTabContent(url1);
					return false;
					}});
							 }
		 			 });	  		
				  }
					else {} 
			
			
			}}
		);
		  	
	}


function cleardate()
	{
		$('#fromdate,#todate').val('');
	}

function showtype()
	{
		tabUrl = $(".navcontainer ul li a").first().attr('href');
		
		if($('#stype').length!=0){
		tabUrl+="&type="+$('#stype').val();
		}
		if($('#fromdate').length!=0){
		tabUrl+="&fromdate="+$('#fromdate').val();
		}
		if($('#todate').length!=0){
		tabUrl+="&todate="+$('#todate').val();
		}
		loadTabContent(tabUrl);
		$('.navcontainer ul li a.current').removeClass('current');
		$('.navcontainer ul li a').first().addClass('current');
		
	}
	
function showpage()
	{
		tabUrl = $(".navcontainer ul li a").first().attr('href');
		
		if($('#stype').length!=0){
		tabUrl+="&type="+$('#stype').val();
		}
		if($('#fromdate').length!=0){
		tabUrl+="&fromdate="+$('#fromdate').val();
		}
		if($('#todate').length!=0){
		tabUrl+="&todate="+$('#todate').val();
		}
		
		if($('#page').length!=0){
		tabUrl+="&page="+$('#page').val();
		}
		
		loadTabContent(tabUrl);
		
	}
	
function showrange()
	{
		tabUrl = $(".navcontainer ul li a").first().attr('href');
		
		if($('#stype').length!=0){
		tabUrl+="&type="+$('#stype').val();
		}
		if($('#fromdate').length!=0){
		tabUrl+="&fromdate="+$('#fromdate').val();
		}
		if($('#todate').length!=0){
		tabUrl+="&todate="+$('#todate').val();
		}
		
		
		loadTabContent(tabUrl);	
	}
	
/////////////////////////////////////////////////////////////////////////////////////////////

// Exchange Area //////////////////////////////////////////////////////////////////////////

function procex() {
	
     $("#exchangebtn").attr("disabled","disabled");
	 $.ajax({
			type:'post',
			url:'index.php',
			data:$("#exform").serialize(),
			success:function(data){
			$.prompt(data,{callback:function(){
				 $("#exchangebtn").removeAttr("disabled");
				 $("#exfromcont,#extocont").html("<img src='images/ajax.gif' />");
				 $('#exfromcont').load('./index.php?getexdetails=1&exfrom=1');
			 	 $('#extocont').load('./index.php?getexdetails=1&exto=1');
				}});
		   }
					
		});
	 return false;
	 }


function updtolist(ppid1)
	{
		 $("#extocont").html("<img src='images/ajax.gif' />");
		 $.ajax({
			type:'post',
			url:'index.php',
			data:{updtolist:1,ppid:ppid1},
			success:function(data){
			$('#extocont').html(data);	
		  	getramount();
		   }	
		});
	
	}

function getramount()
	{
		exto1=$("#exto").val();
		exfrom1=$("#exfrom").val();
		amount1=$("#amount").val();
		curr1=$("#curr").val();
		
		$.ajax({
			type:'post',
			url:'index.php',
			data:{exto:exto1,exfrom:exfrom1,amount:amount1,curr:curr1,resex:1},
			success:function(data){
			$('#ramount').html(data);	
		  	
		   }	
		});
	}	

//////////////////////////////////////////////////////////////////////////////////////////////

// New Deposit Area //////////////////////////////////////////////////////////////////////////


function showaccounts(type)
	{
		if(type=='accbal')$("#accounts").removeAttr("disabled");
		else $("#accounts").attr("disabled","disabled");
		
	}


function initall()
	{
		$("#ctermsarea,#percentarea,#durarea,#compoundarea,#plansarea,#accarea").html("<img src='images/ajax.gif' />");
		
		$("#plansarea").load('index.php?getallplans=1&allplans=1');
		amount1=$("#amount").val();
		$("#ctermsarea").load('./index.php?getplandetails=1&planid=1&plancterm=1&planamount='+amount1);
		$("#percentarea").load('./index.php?getplandetails=1&planid=1&planpercent=1&planamount='+amount1);
		$("#durarea").load('./index.php?getplandetails=1&planid=1&plandur=1&planamount='+amount1);
		$("#compoundarea").load('./index.php?getplandetails=1&planid=1&plancompound=1&planamount='+amount1);
		depto1=$("#depto").val();
		$("#fromarea").load('./index.php?getaccdetails=1&planid=1&planfrom=1&depto='+depto1+'&planamount='+amount1);
		$("#accarea").load('./index.php?getaccdetails=1&planid=1&accfrom=1&depto='+depto1+'&planamount='+amount1);	
		$("#ratearea").html('<img src="images/icons/small/application_next.png" onclick="showrate(1)" title="Show Plan Rates" />');	
		$("#calcarea").html('<img src="images/icons/small/calculator.png" onclick="showcalc(1)" title="Show Calculator" />');	
	}

function changeplan()
	{
		$("#ctermsarea,#percentarea,#durarea,#compoundarea").html("<img src='images/ajax.gif' />");
		amount1=$("#amount").val();
		planid1=$("#selplan").val();
		$("#ctermsarea").load('./index.php?getplandetails=1&planid='+planid1+'&plancterm=1&planamount='+amount1);
		$("#percentarea").load('./index.php?getplandetails=1&planid='+planid1+'&planpercent=1&planamount='+amount1);
		$("#durarea").load('./index.php?getplandetails=1&planid='+planid1+'&plandur=1&planamount='+amount1);
		$("#compoundarea").load('./index.php?getplandetails=1&planid='+planid1+'&plancompound=1&planamount='+amount1);
		$("#ratearea").html('<img src="images/icons/small/application_next.png" onclick="showrate('+planid1+')"  title="Show Plan Rates"/>');	
		$("#calcarea").html('<img src="images/icons/small/calculator.png" onclick="showcalc('+planid1+')" title="Show Calculator" />');			
	}

function cdepto(value1)
 {
 	if(value1=="deptoacc")
	 {$("#ctermsarea,#percentarea,#durarea,#compoundarea,#plansarea,#accarea").html("<font color=red>N/A</font>");
	 	$("select#depfrom option[value='accbal']").remove();
	  $("#ratearea").html('');	
	  $("#calcarea").html('');			
	 }
	else
	initall(); 
	
	 	 
			
 }
function showrate(planid1)
 {
	$.ajax({
	url:'./index.php?getplandetails=1&planid='+planid1+'&planrate=1',
	method:'get',
	success:function(data)
		{
			$.prompt(data);
		}
	});
 }
 function showcalc(planid1)
 {
	if($.browser.msie)height1=390;
	else height1=350;
	txt="<iframe src='extras/calc.php?id="+planid1+"' frameborder=0 width='340' height='"+height1+"' ></iframe>";
	$.prompt(txt);
	
 }

///////////////////////////////////////////////////////////////////////////////////////////////

 function activ(){
     if($("#actcode").val()=="" ){
        	$.prompt('<label class="error">Please enter your activation code.</label>',{callback:function(){$("#submit").removeAttr("disabled");	}}); 
        }else{
        $("#submit").attr("disabled","disabled");
         actcode=$("#actcode").val();
		
		
		$.ajax({
			type:'post',
			url:'models/activation.php',
			data:{actcode:actcode},
			success:function(data){
			if(data==0){
				$.prompt('<label class="error">Activation Code Supplied is wrong</label>',{callback:function(){$("#submit").removeAttr("disabled");	}}); 
			}else if(data ==1){
			 	$.prompt('<label class="error">Sorry! The Activation code has expired !</label>',{callback:function(){$("#submit").removeAttr("disabled");	}});
			}else if(data==2){
			  	$.prompt('<label class="success">Hey! Your account has been successfully activated.</label>',{callback:function(){$("#submit").removeAttr("disabled");	}});
                window.location='account/';
			}
		  	
		   }	
		});
        }
 }
