// Loader Functions
function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { if (oldonload) { oldonload(); }  func(); }}}

function checkverification(){
	cvalue = GetCookie('vip_accessh');
	if(cvalue == 'Y'){
		changecss('.pblock','display','block');
		changecss('.oblock','display','block');
                changecss('.loginbox','display','none');
	}else{
                changecss('.loginbox','display','block');
        }
	
}
function ExitSplash(){
	DeleteCookie('vip_accessh');
}
addLoadEvent(checkverification);
//window.onbeforeunload = ExitSplash;

// Verification
function verifyme(){
vcode = document.getElementById('loginpwd').value;
$.getJSON("http://site.herbalrack.com/system/verify.php?verify="+vcode+"&callback=?",
        function(data){
	   if(data.status == '1'){
             SetCookie('vip_accessh','Y');
             checkverification();
           }else{
             document.getElementById('err').innerHTML = 'Incorrect. Please Try again or Sign-up!';
           }
        });
}
// Registration
function register(){
	uname = document.getElementById('fldname').value;
	email = document.getElementById('fldEmail').value;
	newsletter = $('#chkoptin').is(':checked') ? 1 : 0;
	if(jQuery.trim(uname).length < 1 ){
			alert("Please enter your first name!");
			return false;
	}
	if(jQuery.trim(uname).length <= 3 ){
			alert("First Name is too short!");
			return false;
	}
	if(!IsValidEmail(email)){
			alert("Please added Proper email address!");
			return false;
	}
	var $currentIFrame = $('#aweber');
	$.getJSON("http://site.herbalrack.com/system/registration.php?username="+escape(uname)+"&email="+escape(email)+"&ns="+newsletter+"&callback=?",
       function(data){
	   if(data.status == '1'){
		   		changecss('.registration','display','none');
				changecss('.welcome','display','block');
           }else{
             document.getElementById('err').innerHTML = 'Due to technical error your account is not registered in our system, please try again!';
           }
        });
	$currentIFrame.contents().find("form input[name=name]").val(uname); 
	$currentIFrame.contents().find("form input[name=email]").val(email);
	$currentIFrame.contents().find("form input[name=submit]").trigger('click');
	$currentIFrame.contents().find("form").submit();
}
// Test Login Status
function checklogin(){
	cvalue = GetCookie('vip_accessh');
	if(cvalue == 'Y'){
		  changecss('.registration','display','none');
		  changecss('.welcome','display','none');
		  changecss('.loged','display','block');
	}
}
// Email Validation
function IsValidEmail(email){
		var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		return filter.test(email);
}
