$(document).ready(function() {

        $('#Form').submit(function() {

        //return false;
        var a = PPForm();
        //alert(a);
        return a;
    });


	var ref = $.cookie('Referrer');
	//alert(ref);
	if(!ref || ref == null)
	{
    	ref = document.referrer;
	//alert("1"+ref);
	$.cookie('Referrer', ref, { expires: 7, path: '/' });
	}

	var ad = $.cookie('AdNetwork');
	//alert(ref);
	if(!ad || ad == null)
	{
    	ad = $.query.get('adnetwork');
	//alert("1"+ref);
    	$.cookie('AdNetwork', ad, { expires: 7, path: '/' });
	}
	
	
	$('#dnn_ctr636_DynamicForms_Responses_ac3f1204-418a-4eda-85d2-808ee870d928').attr("value", ref);
	$('#dnn_ctr636_DynamicForms_Responses_d0005769-4fd3-4e9c-8bed-6c76156b5084').attr("value", ad);


	$("#video_button_1").css({ "cursor": "pointer" });
    	$("#video_button_1").click(function() {
        LightBox('/SalesVideo/', 555, 370, "Cbeyond Small Business Expert", "SalesVideo");
    });


});

var LightBox = function(url, width, height, sTitle, aId) {
    var _height = height - 50;
    var _width = width - 40;
    var html = '';
    html += '<div style="overflow:visible; height:555px;width"370px;" id="dialog_' + aId + '" height="' + height + '" width="' + width + '"><iframe frameborder=0 src="' + url + '" height="' + _height + '" width="' + _width + '" scrolling="no" ></iframe></div>';
    $(html).appendTo($("body"));

    $('#dialog_' + aId).dialog({
        title: sTitle,
        height: height,
        width: width,
        minWidth: width,
        minHeight: height,
        modal: true,
        posotion: "center",
        resizable: false,
        close: function(event, ui) {
            $('#dialog_' + aId).remove();
        }
    });
}

var resizeFlash = function(sId, height, width) {
    //    sId = "CBeyondFlashFooter";
    //    height = "230";
    //    width = "280";

    //alert("sId:" + sId + "---height:" + height + "---width:" + width);
    $("#" + sId).css({ "height": height, "width": width });
}

var initVedioPlayer = function(cId,height,width) {
    var flashvars = {
        vidPath: "/Portals/1/Flash/movies/denmark2.flv",
        thumbPath: "/Portals/1/Flash/images/homeflash.png",
        autoPlayVideo: "off"
    };
    var params = {
        menu: "false",
        scale: "noScale",
        allowFullscreen: "true",
        allowScriptAccess: "always",
        bgcolor: "#FFFFFF",
        wmode: "transparent"
    };
    
    var attributes = {
        id: "CbeyondFlashVideoPlayer"
    };
    //swfobject.embedSWF("/Portals/1/Flash/CbeyondFlashVideoPlayer.swf", cId, "320", "240", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
    swfobject.embedSWF("/Portals/1/Flash/CbeyondFlashVideoPlayer.swf", cId, width, height, "9.0.0", "expressInstall.swf", flashvars, params, attributes);
}


/* do not modify this function*/

var PPForm = function() {

    if($('#dnn_ctr636_DynamicForms_tblQuestions') == null) return true;

    var checkboxGroupsId = 'dnn_ctr636_DynamicForms_Responses_22c31da7-026e-41c9-b466-97601005ed38';
    var maximum = 7;

    var hiddenIds = new Array();

    
    //server  'the index of hiddenIds is very important'
    //Don't -- ok
    hiddenIds[0] = 'dnn_ctr636_DynamicForms_Responses_77624b21-2793-4a0a-832b-59477b73c460';

    //CDW -- ok
    hiddenIds[1] = 'dnn_ctr636_DynamicForms_Responses_f173b42d-b1e0-4022-8a0a-c5a43e941b5d';

    //Comstor -- ok
    hiddenIds[2] = 'dnn_ctr636_DynamicForms_Responses_3316141d-ed69-45a8-9af3-0de18acc703b';

    //DH -- ok
    hiddenIds[3] = 'dnn_ctr636_DynamicForms_Responses_4c93b105-7e25-4b27-a9c8-5f76590e928f';

    //Ingram -- ok
    hiddenIds[4] = 'dnn_ctr636_DynamicForms_Responses_35c3b798-02a4-4fad-8db1-60f91662e78a';

    //TEchData -- ok
    hiddenIds[5] = 'dnn_ctr636_DynamicForms_Responses_b6f4d7b9-0eba-4de1-917f-b8ea3b795080';    

    //Trade -- ok
    hiddenIds[6] = 'dnn_ctr636_DynamicForms_Responses_41ccaeb6-425d-4ed6-a392-ddf29199dbd0';

    //Other -- ok
    hiddenIds[7] = 'dnn_ctr636_DynamicForms_Responses_88c1de7f-eb1e-4f76-be33-d398946eac94';

    
    for (var i = 0; i <= maximum; i++) {
        var _d = $('#' + checkboxGroupsId +"_"+i);
        //alert(_d.attr('checked') + "  " +i);
        var val = _d.attr('checked') ? 'Y' : 'N';
        $('#' + hiddenIds[i]).attr('value', val);
    }

    return true;
}


