//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(){}

var tick = 0;

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

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

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

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

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

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

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

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

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

function validateForm() {
    if (!validateProductOption() ) {
        return false;
    }

    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 validateProductOption() {
    //if there is an operator selection
    if ($("#productoption").val() == '') {
        $("#productoptionProblem").fadeIn();
        return false;
    }else{
        $("#productoptionProblem").fadeOut();
    }
    return true;
}

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

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

function errorMsg(){
	$("#incorrectPhoneError").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() {
	$("#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 fireGoogle(){
    if(tick==9){
        if(!agreeCheck()) {
            showBox();
        }
    }
}

