$(document).ready(function( ){

	$("div.scrollable").scrollable({
					vertical:true, 
					size: 3
				}).circular().mousewheel().autoscroll({ 
		steps: 1, 
		interval: 3000         
	});
	$("#loginForm").validate();
	$("#registerForm").submit(function(){
		setTimeout ( "waitMsg()", 500 );

	});
	
	$("#termsChk:not(:checked)").click(function(){
		var label = $(this).parent().find('.error');		
		label.attr("style" , "display:none");
		
	});
});


function validateRegisterForm() {
	$("#registerForm").validate({
			rules: {
				reg_pass: {
					minlength: 6
				},
				reg_repass: {
					minlength: 6,
					equalTo: "#reg_pass"
				}
			},
			messages: {
				reg_pass: {
					required: "Password field is mandatory",
					minlength: "Password must be 6 characters or longer."
				},
				reg_repass: {
					required: "Retype Password field is mandatory",
					minlength: "Password must be 6 characters or longer.",
					equalTo: "Passwords do not match."
				}
			}
		});
}
function waitMsg(){
	var err = false;
	$(".error").each(function(){
		if($(this).css("display") != "none")
			err = true;
	});
	if (!err){
	 	$.facebox.settings.opacity = 0.3; 
	 	var html = '<div class="forgotPass" id="login-box-new"><h1>Please Wait...</h1>';
	 	html += '<div id="sendPassForm" name="sendPassForm">';
	 	html += '<font color="grey" font size="2">Please wait while our system process your data.<br/><br/></font>';
	 	html += '</div></div>';
	 		 	
	 	jQuery.facebox(html);
	 }
}
function ipMsg(){
		$.facebox.settings.opacity = 0.3; 
	 	var html = '<div class="forgotPass"><h1>Registration Failed</h1>';
	 	html += '<div id="sendPassForm" name="sendPassForm">';
	 	html += '<font color="grey" font size="2">You have exceeded the amount of free accounts allowed per IP addresses. Please login and upgrade your existing account or contact our support team for help.<br/><br/></font>';
	 	html += '</div></div>';
	 		 	
	 	jQuery.facebox(html);
}
function checkAll(formId, chkBoxId) {
   $('#'+chkBoxId).click(
	   function()  {
		  checked = $('#'+chkBoxId).is(':checked');
		  $("form#" + formId + " INPUT[type='checkbox']").attr('checked', !checked);   
		  $('#'+chkBoxId).attr('checked', checked);
	   }
	)
}

function badEmailMsg(){
               $.facebox.settings.opacity = 0.3;
               var html = '<div class="forgotPass"><h1>Registration Failed</h1>';
                html += '<div id="sendPassForm" name="sendPassForm">';
                html += '<font color="grey" font size="2">Please enter Corporate emails only.<br/><br/></font>';
                html += '</div></div>';

                jQuery.facebox(html);
}
function checkAll(formId, chkBoxId) {
	   $('#'+chkBoxId).click(
			              function()  {
				                        checked = $('#'+chkBoxId).is(':checked');
							                  $("form#" + formId + " INPUT[type='checkbox']").attr('checked', !checked);
									                    $('#'+chkBoxId).attr('checked', checked);
											               }
												               )
}

function validateNoLess(){

	if (window.numchecked + 1 < numcountries){
		alert("you checked out less then " + numcountries + " countries !");
		return false;
	}else return true;
}

function countCheck(formId, numCountry, edition) {
    $("form#" + formId + " INPUT[type='checkbox']").click(
        function(event) {
             var num = numCountry;
	     var pack = edition;
	     var target = $(event.target);
	     var tid = target.attr("id");
	     var terms = $('#termsChk:checked').size();
             if(target.attr("id") == "termsChk") return true;
	     if(target.attr("checked") == true) 
	     {
	        window.numchecked--;
		$("label[for=" + tid + "]").toggleClass("mstOn");

		return true;
	     }
             window.numchecked = checked = $("form#" + formId + " INPUT[type='checkbox']:checked").length - terms;

	     if(checked == numCountry)
	     {
		alert("You can select a maximum of " + num + " countries with GeoSurf " + pack);
		return false;
             }
             if(pack == "free")
             {
                var country = target.attr('name');
                if(country == 'chk[us]' ||
                   country == 'chk[gb]' ||
                   country == 'chk[ca]' ||
                   country == 'chk[fr]' ||
                   country == 'chk[au]' ||
                   country == 'chk[es]' ||
                   country == 'chk[it]' ||
                   country == 'chk[cn]' ||
                   country == 'chk[in]' ||
                   country == 'chk[br]' ||
                   country == 'chk[ar]' ||
                   country == 'chk[de]' ||
                   country == 'chk[nl]' ||
                   country == 'chk[ru]' ||
                   country == 'chk[ae]' ||
                   country == 'chk[id]' ||
                   country == 'chk[hk]' ||
                   country == 'chk[at]' ||
                   country == 'chk[ch]' ||
                   country == 'chk[mx]'
                   
                  )
                {
                        alert("This country is not supported in the FREE edition");
                        return false;
                }
             }
	     $("label[for=" + tid + "]").toggleClass("mstOn");
	     return true;
        }
    )
}

function clientSlides() {
	$('#clientSlides').show();
	$('#clientSlides').cycle({
		fx:     'fade',
		timeout: 1000,
		delay:  -5000
	});
}

function closePopBox() {
	$.facebox.close(); 
	return false;
}
