/* var flashvars = {};
var params = { wmode:'transparent' };
var attributes = {};
swfobject.embedSWF('/images/nonstopplayer.swf', 'playButton', '90', '35', '6.0.0','/javascript/expressInstall.swf', flashvars, params, attributes); function s_gi(){}
*/


$(document).ready(function() {
// get google tick
if($(document).getUrlParam("tick")) {
	tick = $(document).getUrlParam("tick");
} else {
    tick = 0;
}

if(tick == 1) {
    $("#googleTickbox").show();
} else if(tick==9) {
	$("#tick9").html($("#googleTickbox").html());
	$("#googleTickbox").remove();
}

//submitButton click
$("#submitButton").click(validateForm);

//form Submit
$("#frmShopSubmit").submit(validateForm);

$("#no").click(hideAlertBox);

$("#yes").click(acceptTerms);


	$("#jaGaVerder").click(function(){
		$("#agree").attr('checked', true);
		hideBox();
		if (validateNumeric($('#inputBox').val()) && !($('#inputBox').val().length < $('#inputBox').attr("maxlength"))) {
			$("#frmShopSubmit").submit();
		}
		return false;
	});

	$("#neeGaVerder").click(hideBox);
	$("#closeGoogleWarning").click(hideBox);

	$(document).keyup(function(event){
	    if (event.keyCode == 27) {
    	    hideBox();
    	}
	});
});



function validateForm() {

    if (!validateNumeric($('#inputBox').val()) || $('#inputBox').val().length < $('#inputBox').attr("maxlength")) {
        errorMsg();
        return false;
    } else {
        if(tick==1) {
            if(!agreeCheck()) {
                showAlertBox();
                return false;
            } else {
                return true;
            }
        } else if(tick==9) {
            if(!agreeCheck()) {
                showBox();
                return false;
            } else {
                return true;
            }
        } else {
            return true;
        }
    }
}

function validateNumeric(strValue){
	var objRegExp  = /^\d+$/;
	return objRegExp.test(strValue);
}

function showAlertBox(){
	$("#googleAlertBox").fadeIn();
}

function hideAlertBox(){
	$("#googleAlertBox").hide();
	return false;
}

function agreeCheck(){
	return $("#agree").is(":checked");
}

function acceptTerms(){
	$("#agree").attr('checked', true);
	hideAlertBox();
	$("#frmShopSubmit").submit();
	return false;
}

// tick 9 showbox
function showBox() {
        $('body').append($("#googleWarning"));
        $('body').append($("#blackBackground"));
	$("#googleWarning").css({"height":$(window).height()});
	$("#googleWarning").fadeIn();
	$("#blackBackground").css({"opacity":"0.7", "height":$(document).height()});
	$("#blackBackground").fadeIn();
}

// tick 9 hidebox
function hideBox() {
	$("#googleWarning").fadeOut();
	$("#blackBackground").fadeOut();
	}
	
function errorMsg(){
	$("#incorrectPhoneError").fadeIn();
}

function fireGoogle(){
	if(tick==9){
		  if(!agreeCheck()) {
			showBox();
		  }
	}
}
