

var newWin_doc = null;
var newWin = null;
var returnObj = null;
var returnType = 0;
var demoCode = '';
var wg_size;
var length = 4;
var width = 120;
var height = 600;
var popupWin;

function editshopnowtext() {
    if (getElementById_s('chkDefaultButton').checked) {
        getElementById_s('txtShopNow').innerHTML = "Visit Store";
        getElementById_s('txtShopNow1').innerHTML = "Visit Store";
    }
    else {
        getElementById_s('txtShopNow').innerHTML = getElementById_s('ctl00_ContentPlaceHolder1_bxButtonText').value;
        getElementById_s('txtShopNow1').innerHTML = getElementById_s('txtShopNow').innerHTML;
    }
    getElementById_s('ctl00_ContentPlaceHolder1_txtButtonText').value = getElementById_s('txtShopNow').innerHTML;
}

function defaultcss() {

    if (getElementById_s('chkDefaultCss').checked) {
        getElementById_s('bxExtCss').innerHTML = "";
    }
    else {
        getElementById_s('bxExtCss').innerHTML = getElementById_s('bxExtCss').value;
    }
    build_code();
}
function defaultbuttontext() {
    try {
        if (getElementById_s('chkDefaultButton').checked) {
            getElementById_s('txtShopNow').innerHTML = "Visit Store";
            getElementById_s('txtShopNow1').innerHTML = "Visit Store";
        }
        else {
            if (getElementById_s('ctl00_ContentPlaceHolder1_bxButtonText').value != "") {
                getElementById_s('txtShopNow').innerHTML = getElementById_s('ctl00_ContentPlaceHolder1_bxButtonText').value;
                getElementById_s('txtShopNow1').innerHTML = getElementById_s('ctl00_ContentPlaceHolder1_bxButtonText').value;
            }
            else {
                getElementById_s('txtShopNow').innerHTML = "Visit Store";
                getElementById_s('txtShopNow1').innerHTML = "Visit Store";
            }
        }
        getElementById_s('ctl00_ContentPlaceHolder1_txtButtonText').value = getElementById_s('txtShopNow').innerHTML;
    }
    catch (err) {
    }
}

function defaultheadertext() {
    try {
        var HeaderLink = "What's this?";
        var objWhatThis = getElementById_s('ctl00_ContentPlaceHolder1_txtWhatThis');
        objWhatThis.value = "";
        if (getElementById_s('ic').checked) {
            HeaderLink = "<img src='Images/question_c.gif' border='0' />";
            objWhatThis.value = "1";
        }

        //getElementById_s('ctl00_ContentPlaceHolder1_txtHeaderText').value = "";
        if (getElementById_s('chkDefaultHeader').checked) {
            getElementById_s('HeadText').innerHTML = "<b>Compare Our Prices To These Retailers</b> <a href=\"javascript: void(0)\" style=\"cursor: hand pointer; text-decoration: none;	color: #ff6600;	font-family: Times New Roman;	font-style: normal;	font-size: 12px;\" onclick=\"wopen('http://widget.winbuyer.com/w/whatsup.html','Whats Up', 350, 250);return true;\">" + HeaderLink + "</a>";
            getElementById_s('ctl00_ContentPlaceHolder1_txtHeadText').value = "";
        }
        else {
            if (getElementById_s('ctl00_ContentPlaceHolder1_txtHeaderText').value != "") {
                getElementById_s('HeadText').innerHTML = getElementById_s('ctl00_ContentPlaceHolder1_txtHeadText').value + "<a href=\"javascript: void(0)\" style=\"cursor: hand pointer; text-decoration: none;	color: #ff6600;	font-family: Times New Roman;	font-style: normal;	font-size: 12px;\" onclick=\"wopen('http://widget.winbuyer.com/w/whatsup.html','Whats Up', 350, 250);return true;\">" + HeaderLink + "</a>";
                getElementById_s('ctl00_ContentPlaceHolder1_txtHeadText').value = getElementById_s('ctl00_ContentPlaceHolder1_txtHeadText').value;
            }
            else {
                getElementById_s('HeadText').innerHTML = "<b>Compare Our Prices To These Retailers</b> <a href=\"javascript: void(0)\"  style=\"cursor: hand pointer; text-decoration: none;	color: #ff6600;	font-family: Times New Roman;	font-style: normal;	font-size: 12px;\" onclick=\"wopen('http://widget.winbuyer.com/w/whatsup.html','Whats Up', 350, 250);return true;\">" + HeaderLink + "</a>";
                getElementById_s('ctl00_ContentPlaceHolder1_txtHeadText').value = "";
            }
        }
    }
    catch (err) {
    }
}

function editheadertext() {
    var HeaderLink = "What's this?";
    if (getElementById_s('ic').checked) {
        HeaderLink = "<img src='Images/question.gif' border='0' />";
    }
    if (!getElementById_s('chkDefaultHeader').checked) {
        getElementById_s('HeadText').innerHTML = getElementById_s('ctl00_ContentPlaceHolder1_txtHeadText').value + "<a href=\"javascript: void(0)\" style=\"cursor: hand pointer; text-decoration: none;	color: #ff6600;	font-family: Times New Roman;	font-style: normal;	font-size: 12px;\" onclick=\"wopen('http://widget.winbuyer.com/w/whatisthis.html?utm_medium=vr&utm_content=wts&utm_source={CAMPAIGNID}','Whats Up', 350, 250);return true;\">" + HeaderLink + "</a>";
        getElementById_s('ctl00_ContentPlaceHolder1_txtHeaderText').value = getElementById_s('ctl00_ContentPlaceHolder1_txtHeadText').value;
    }
    else {
        getElementById_s('HeadText').innerHTML = "<b>Compare to these retailers</b> <a href=\"javascript: void(0)\" style=\"cursor: hand pointer; text-decoration: none;	color: #ff6600;	font-family: Times New Roman;	font-style: normal;	font-size: 12px;\" onclick=\"wopen('http://widget.winbuyer.com/w/whatisthis.html?utm_medium=vr&utm_content=wts&utm_source={CAMPAIGNID}','Whats Up', 350, 250);return true;\">" + HeaderLink + "</a>";
        getElementById_s('ctl00_ContentPlaceHolder1_txtHeaderText').value = "";
    }
}

function trim(strText) {
    while (strText.substring(0, 1) == ' ')
        strText = strText.substring(1, strText.length);
    while (strText.substring(strText.length - 1, strText.length) == ' ')
        strText = strText.substring(0, strText.length - 1);
    return strText;
}

function verifycolor() {
    string = newWin_doc.getElementById('ColorHex').value;
    if (string == "") { alert("Invalid color!!!"); return null; };

    string = string.replace(/#/, "");
    string = trim(string);
    if (string.length != 6) { alert("Invalid color!!!"); return null; };
    stdstr = '0123456789abcdefABCDEF';

    for (i = 0; i < string.length; i++) {
        chr = string.charAt(i);
        if (stdstr.indexOf(chr) == -1) { alert("Invalid color!!!"); return null; };
    }
    return string;
}

function customcolor() {
    str = verifycolor();
    if (str != null) { preview(str) };
}

function preview(color) {
    newWin_doc.getElementById('ColorPreview').style.backgroundColor = '#' + color;
    newWin_doc.getElementById('ColorHex').value = '#' + color;
}

function returncolor() {
    color = verifycolor();
    returnObjbutton = returnObj + 'button';
    if (color == null) { alert("Invalid color!!!"); }
    else {
        if (returnType == 0) {
            getElementById_s(returnObj).value = '' + color.toUpperCase();
        } else if (returnType == 1) {
            getElementById_s(returnObj).style.backgroundColor = '' + color.toUpperCase();
            getElementById_s(returnObjbutton).style.backgroundColor = '#' + color.toUpperCase();
        } else {
            getElementById_s(returnObj).value = '' + color.toUpperCase();
            getElementById_s(returnObj).style.backgroundColor = '' + color.toUpperCase();
            getElementById_s(returnObjbutton).style.backgroundColor = '#' + color.toUpperCase();
        }
        getElementById_s(returnObj).focus();
        newWin.close();
    }
    //create_code();
}

function init() {
    var count = 0;
    var rbg = new Array("00", "33", "66", "99", "cc", "ff");
    var color = "000000";
    newWin_doc.write("<table class=\"mytable\"><tr>");
    for (var i = 0; i < rbg.length; i++) {
        for (var j = 0; j < 3; j++) {
            for (var k = 0; k < rbg.length; k++) {
                color = rbg[j] + rbg[k] + rbg[i];
                newWin_doc.write("<td onmouseover=\"window.opener.preview('" + color + "');\" onclick=\"window.opener.returncolor();\" width=8 height=11 bgcolor=" + color + "> </td>");
                count++;
                if ((count % 18) == 0) {
                    newWin_doc.write("</tr><tr>");
                }
            }
        }
    }
    for (var i = 0; i < rbg.length; i++) {
        for (var j = 3; j < rbg.length; j++) {
            for (var k = 0; k < rbg.length; k++) {
                color = rbg[j] + rbg[k] + rbg[i];
                newWin_doc.write("<td onmouseover=\"window.opener.preview('" + color + "');\" onclick=\"window.opener.returncolor();\" width=8 height=11 bgcolor=" + color + "> </td>");
                count++;
                if ((count % 18) == 0) {
                    newWin_doc.write("</tr><tr>");
                }
            }
        }
    }
    newWin_doc.write("</tr></table>");
}

function show_color_dialog(returnVar, type) {
    returnType = 0;
    newWin = window.open("", "ColorPicker", "width=251,height=215,status=no,resizable=no, scrollbars=no,top=200,left=300");
    newWin.opener = self;
    newWin_doc = newWin.document;
    returnObj = returnVar;
    if (type) { returnType = type; }

    newWin_doc.writeln('<html>');
    newWin_doc.writeln('<head>');
    newWin_doc.writeln('<title>Select Color</title>');
    newWin_doc.writeln('<style type="text/css"><!--');
    newWin_doc.writeln('.mytable     {border: 0px solid buttonface; margin: 0; padding: 0; spacing: 1px;};');
    newWin_doc.writeln('--></style>');
    newWin_doc.writeln('</head>');

    newWin_doc.writeln('<body bgcolor="#000000" style="margin: 3px;">');
    newWin_doc.writeln('<table border=0 cellspacing=0 cellpadding=4 width=100%>');
    newWin_doc.writeln('<tr>');
    newWin_doc.writeln('<td style="background-color: buttonface;" valign=center><div style="background-color: #000000; padding: 1; height: 21px; width: 50px"><div id="ColorPreview" style="height: 100%; width: 100%"></div></div></td>');
    newWin_doc.writeln('<td style="background-color: buttonface;" valign=center><input type="text" id="ColorHex" value="#000000" size=9 style="font-size: 11px"></td>');
    newWin_doc.writeln('<td style="background-color: buttonface;" valign=center><button onclick="window.opener.customcolor();">View</button></td>');
    newWin_doc.writeln('<td style="background-color: buttonface;" valign=center><button onclick="window.opener.returncolor();">OK</button></td>');
    newWin_doc.writeln(' <td style="background-color: buttonface;" width=100%></td>');
    newWin_doc.writeln('</tr>');
    newWin_doc.writeln('</table>');

    newWin_doc.writeln('<table><tr>');
    newWin_doc.writeln('<td>');
    newWin_doc.writeln('<table>');
    newWin_doc.writeln('<tr><td onmouseover="window.opener.preview(\'000000\');" onclick="window.opener.returncolor();" width=8 height=11 bgcolor="#000000"> </td></tr>');
    newWin_doc.writeln('<tr><td onmouseover="window.opener.preview(\'333333\');" onclick="window.opener.returncolor();" width=8 height=11 bgcolor="#333333"> </td></tr>');
    newWin_doc.writeln('<tr><td onmouseover="window.opener.preview(\'666666\');" onclick="window.opener.returncolor();" width=8 height=11 bgcolor="#666666"> </td></tr>');
    newWin_doc.writeln('<tr><td onmouseover="window.opener.preview(\'999999\');" onclick="window.opener.returncolor();" width=8 height=11 bgcolor="#999999"> </td></tr>');
    newWin_doc.writeln('<tr><td onmouseover="window.opener.preview(\'cccccc\');" onclick="window.opener.returncolor();" width=8 height=11 bgcolor="#cccccc"> </td></tr>');
    newWin_doc.writeln('<tr><td onmouseover="window.opener.preview(\'ffffff\');" onclick="window.opener.returncolor();" width=8 height=11 bgcolor="#ffffff"> </td></tr>');
    newWin_doc.writeln('<tr><td onmouseover="window.opener.preview(\'ff0000\');" onclick="window.opener.returncolor();" width=8 height=11 bgcolor="#ff0000"> </td></tr>');
    newWin_doc.writeln('<tr><td onmouseover="window.opener.preview(\'00ff00\');" onclick="window.opener.returncolor();" width=8 height=11 bgcolor="#00ff00"> </td></tr>');
    newWin_doc.writeln('<tr><td onmouseover="window.opener.preview(\'0000ff\');" onclick="window.opener.returncolor();" width=8 height=11 bgcolor="#0000ff"> </td></tr>');
    newWin_doc.writeln('<tr><td onmouseover="window.opener.preview(\'ff00ff\');" onclick="window.opener.returncolor();" width=8 height=11 bgcolor="#ff00ff"> </td></tr>');
    newWin_doc.writeln('<tr><td onmouseover="window.opener.preview(\'ffff00\');" onclick="window.opener.returncolor();" width=8 height=11 bgcolor="#ffff00"> </td></tr>');
    newWin_doc.writeln('<tr><td onmouseover="window.opener.preview(\'00ffff\');" onclick="window.opener.returncolor();" width=8 height=11 bgcolor="#00ffff"> </td></tr>');
    newWin_doc.writeln('</table>');
    newWin_doc.writeln('</td>');
    newWin_doc.writeln('<td>');


    init();


    newWin_doc.writeln('</td>');
    newWin_doc.writeln('</tr></table>');

    //newWin_doc.writeln('<div align="right"><font size="-2" face="Verdana"><a target="_blank" href="http://www.akwebtools.com"><font color="#ffffff">AK ColorPicker V1.0</font></a>&nbsp;&nbsp;</font></div>');
    newWin_doc.writeln('</body>');
    newWin_doc.writeln('</html>');

    if (navigator.appName != "Microsoft Internet Explorer") {
        newWin_doc.close();
    }
}

// getElementById Special to handle quirky browsers
// most will use getElementById()
function getElementById_s(id) {
    var obj = null;
    if (document.getElementById) {
        /* Prefer the widely supported W3C DOM method, if
        available:-
        */
        obj = document.getElementById(id);
    } else if (document.all) {
        /* Branch to use document.all on document.all only
        browsers. Requires that IDs are unique to the page
        and do not coincide with NAME attributes on other
        elements:-
        */
        obj = document.all[id];
    }
    /* If no appropriate element retrieval mechanism exists on
    this browser this function always returns null:-
    */
    return obj;
}

function radiobysize() {
    var szwobj = getElementById_s("wsz");
    var szhobj = getElementById_s("hsz");
    var sizeTypeobj = getElementById_s("sizeType");
    var lstnumoffersobj = getElementById_s("lstnumoffers");
    //szhobj.disabled = false;
    try {

        lstnumoffersobj.style.display = 'none';
        szhobj.style.display = 'inline';
        sizeTypeobj.checked = true;
        build_code();
    }
    catch (er) {
    }
}

function radiobyoffersnum() {
    var szwobj = "600";
    var szhobj = "400";
    var lstnumoffersobj = "5";
    try {
        szwobj = getElementById_s("wsz");
    }
    catch (er) {
    }
    try {
        szhobj = getElementById_s("hsz");
        szhobj.style.display = 'none';
    }
    catch (er) {
    }

    try {
        lstnumoffersobj = getElementById_s("lstnumoffers");
        lstnumoffersobj.style.display = 'inline';
    }
    catch (er) {
    }
    var sizeType2obj = getElementById_s("sizeType2");
    try {
        sizeType2obj.checked = true;
    }
    catch (er) {
    }
    build_code();
}

function getSelectedItem(objSelect) {
    for (i = 0; i < objSelect.length; i++) {
        if (objSelect[i].selected) {
            return objSelect[i].value;
        }
    }
    return "";
}


function setDomainValue() {
    var wgdomain = getElementById_s("wgdomain");
    try {
        var lstdomains = getElementById_s("ctl00_ContentPlaceHolder1_DropDownListDomains");
        if (lstdomains) {
            wgdomain.value = getSelectedItem(lstdomains);
        }
    }
    catch (err) {
        wgdomain.value = "";
    }
    if (wgdomain.value == "" || wgdomain.value == "undefined") {
        var wgdom = getElementById_s("ctl00_ContentPlaceHolder1_lblDomain");
        if (wgdom) {
            wgdomain.value = getText(wgdom);
        }
    }

}
function build_code() {

    var objChkWOPictures = "";
    var bxExtCss = "";
    var DefCss = "";
    try {
        DefCss = getElementById_s("chkDefaultCss");
        if (!DefCss.checked)
            bxExtCss = getElementById_s("bxExtCss").value;
        else
            bxExtCss = "";

    }
    catch (err) {
    }


    try {
        objChkWOPictures = getElementById_s("chkWOPictures");
    }
    catch (err) {

    }

   
    
    var bordercolor = getElementById_s("bordercolor");
    var fontcolor = getElementById_s("fontcolor");
    var linkcolor = getElementById_s("linkcolor");
    var adformat = getElementById_s("adformat");
    var wsz = getElementById_s("wsz");
    var hsz = getElementById_s("hsz");
    var noncore = getElementById_s("CheckBoxCore");
    var wgCode = getElementById_s("wgCode");
    var wgpreview = getElementById_s("wgpreview");
    var wgid = getElementById_s("wgid");
    var wgaid = getElementById_s("wgaid");
    var wgdefaultcategory = getElementById_s("_ctl0_ContentPlaceHolder1_DefaultCategory_ListBox1");
    var lstnumoffersobj = getElementById_s("lstnumoffers");
    var fontfamily = getElementById_s("fontFamily").value;
    var fontstyle = getElementById_s("fontStyle").value;
    document.aspnetForm.wgCode.style.background = "#ffffff";
    document.aspnetForm.wgCode.style.color = "#000000";


    // default category        
    var wg_category = '';
    try {
        if (wgdefaultcategory.value != "")
            wg_category = "wg_category='" + wgdefaultcategory.value + "';\n";
    }
    catch (err) {

    }

    //getElementById_s("wgpreview").innerHTML = "Your Widget Preview Will Show Here";
    // border color
    var wg_border_color = 'E5E5E5';
    if (bordercolor.value != "")
        wg_border_color = bordercolor.value;

    // text color        
    var wg_text_color = '000000';
    if (fontcolor.value != "")
        wg_text_color = fontcolor.value;

    // link color        
    var wg_link_color = 'FF6600';
    if (linkcolor.value != "")
        wg_link_color = linkcolor.value;

//    var ad_format = "";
//    try {
//        ad_format = adformat.value;
//    }
//    catch (err) {
//        try {
//            ad_format = "";
//            if (wsz.value != "")
//                ad_format += wsz.value;
//            if (hsz.value != "")
//                ad_format += "x" + hsz.value;
//            else
//                ad_format = "";
//        }
//        catch (err) {
//            ad_format = "";
//        }
//    }

//    if (ad_format == "") {
//        //alert("Please select an ad size/format");
//        wgCode.value = "Please choose an ad size/format first";
//        //getElementById_s("wgpreview").innerHTML = "Please choose an ad size/format first";
//        return false;
//    }

//    var format = ad_format.split('x');
//    if (format.length != 2 || format[0] == "" || format[1] == "") {
//        //document.aspnetForm.wgCode.value = "Please choose an ad size/format first";
//        //getElementById_s("wgpreview").innerHTML = "Please choose an ad size/format first";
//        return false;
//    }

    //var wg_type = 'b';
    //if(document.aspnetForm.wgtype.value!="")
    //    wg_type = document.aspnetForm.wgtype.value;

    var wg_id = '';
    try {
        if (wgid.value != "")
            wg_id = wgid.value;
    }
    catch (er) {
    }

    var wg_aid = '';
    try {
        if (wgaid.value != "")
            wg_aid = wgaid.value;
    }
    catch (er) {
    }
    //        wg_aid = "&aid="+wgaid.value;

    try {
        //if (hsz.style.display == 'none')
            length = lstnumoffersobj.value;
    }
    catch (er) {
        length = 5;
    }

    try {
        width = wsz.value;
    }
    catch (er) {
        width = 600;
    }

    if (length == 0 || width == 0) {
                wgCode.value = "Please choose an ad size/format first";
                return false;
    }
    var wg_noncore = '';
    if (noncore.checked)
        wg_noncore = "wg_noncore = '1';\n";

    var wg_font_family = '';
    if (fontfamily != "" && fontfamily != "undefined")
        wg_font_family = "wg_font_family='" + fontfamily + "';\n";

    var wg_font_style = '';
    if (fontstyle != "" && fontstyle != "undefined")
        wg_font_style = "wg_font_style='" + fontstyle + "';\n";

    var wg_extendedcss = '';
    if (bxExtCss != "" && bxExtCss != "undefined")
        wg_extendedcss = "wg_extendedcss='" + bxExtCss + "';\n";

    var wg_mimage = '';
    try {
        if (objChkWOPictures.checked)
            wg_mimage = "wg_nomimage='1';\n";
    }
    catch (err) {
    }



    //    var wg_font_size = '';
    //    if(fontsize!="" && fontsize != "undefined")
    //    {
    //        alert(fontsize);
    //        wg_font_size = "wg_font_size='"+fontsize+"';\n";
    //    }
    //        
    //    var wg_font_weight = '';
    //    if(fontweight!="" && fontweight!="undefined")
    //        wg_font_weight = "wg_font_weight='"+fontweight+"';\n";
    //    
    //    

    var WidgetCode = "<script type=\"text/javascript\">\n<!--\n";
    WidgetCode += "wg_client_id = '" + wg_id + "';\n";
    var zero = '';
    if (wg_aid != '') {
        for (y = 0; y < (7 - wg_aid.length); y++) {
            zero += "0";
        }
        WidgetCode += "wg_client_aid = '" + zero + wg_aid + "';\n";
    }

    try {
        //if (hsz.style.display == 'none')
            WidgetCode += "wg_length = '" + length + "';\n";
        //else
        //    WidgetCode += "wg_height = '" + height + "';\n";

    }
    catch (er) {
        WidgetCode += "wg_length = '5';\n";
        //WidgetCode += "wg_height = '" + height + "';\n";
    }

    WidgetCode += "wg_width = '" + width + "';\n";
    //WidgetCode += "wg_num = '"+ length +"';\n"; 
    if (wg_extendedcss == "") {
        WidgetCode += "wg_text_color = '" + wg_text_color + "';\n";
        WidgetCode += "wg_link_color = '" + wg_link_color + "';\n";
        WidgetCode += "wg_border_color = '" + wg_border_color + "';\n";
        WidgetCode += wg_font_family;
        WidgetCode += wg_font_style;
    }
    else
        WidgetCode += wg_extendedcss;
    WidgetCode += wg_category;
    WidgetCode += wg_noncore;
    WidgetCode += wg_mimage;
    WidgetCode += "wg_ts = new Date().getTime();\n";
    //WidgetCode += "var scr = '<sc'+'ript src=http://localhost/w/show_widget.aspx?ts='+wg_ts+'></sc'+'ript>';\n"; 
    WidgetCode += "var scr = '<sc'+'ript src=http://widget.winbuyer.com/w/show_widget.aspx?ts='+wg_ts+'></sc'+'ript>';\n";
    WidgetCode += "document.write(scr);\n";
    WidgetCode += "-->\n</script>\n";

    if (width != "")
        szw = "&szw=" + width;
    if (height != "")
        szh = "&szh=" + height;
    if (wgCode.value != WidgetCode) {
        wgCode.value = "";
        wgCode.value = WidgetCode;
    }


    getElementById_s("ctl00_ContentPlaceHolder1_fontcolorVal").value = wg_text_color;
    getElementById_s("ctl00_ContentPlaceHolder1_linkcolorVal").value = wg_link_color;
    getElementById_s("ctl00_ContentPlaceHolder1_bordercolorVal").value = wg_border_color;
    getElementById_s("ctl00_ContentPlaceHolder1_wszVal").value = width;
    getElementById_s("ctl00_ContentPlaceHolder1_lstnumoffersVal").value = length;

    if (fontfamily != "" && fontfamily != "undefined")
        getElementById_s("ctl00_ContentPlaceHolder1_fontFamilyVal").value = fontfamily;
    if (fontstyle != "" && fontstyle != "undefined")
        getElementById_s("ctl00_ContentPlaceHolder1_fontStyleVal").value = fontstyle;


    if (noncore.checked)
        getElementById_s("ctl00_ContentPlaceHolder1_CheckBoxCoreVal").value = "1";
    else
        getElementById_s("ctl00_ContentPlaceHolder1_CheckBoxCoreVal").value = "0";

    if (bxExtCss != "" && bxExtCss != "undefined")
        getElementById_s("ctl00_ContentPlaceHolder1_bxExtCssVal").value = bxExtCss;
    else
        getElementById_s("ctl00_ContentPlaceHolder1_bxExtCssVal").value = bxExtCss;


}

function shDemo(site) {
    var width = 500;
    var height = 500;
    setDomainValue();
    //set domain for demo          
    var wgdomain = getElementById_s("wgdomain").value;
    var wg_domain = '';
    if (wgdomain != "")
        wg_domain = "wg_domain='" + wgdomain + "';";
    var text = document.aspnetForm.wgCode.value;
    text = text.replace('<!--', '<!--\n ' + wg_domain);
    try {
        if (getElementById_s("chkWOPictures").checked)
            var wg_m = "1";
        text = text.replace('<!--', '<!--\n wg_tpltype=\'3\';');
    }
    catch (err) {
    }

    try {
        if (getElementById_s("ctl00_ContentPlaceHolder1_Panel4"))
            text = text.replace('<!--', '<!--\n wg_tpltype=\'3\';');
    }
    catch (err) {
    }
    text = text.replace('show_widget.aspx?ts=', 'show_widget.aspx?&ts=');
    text = text.replace('></', '&u=' + site + '&wg_type=json></');
    var name = 'window' + width + '' + height;
    var attrib = 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1';
    po = window.open('', name, attrib);
    po.document.open();
    po.document.write("<HTML><HEAD><TITLE>Show widget</TITLE>\n");
    po.document.write("</HEAD><BODY BGCOLOR=FFFFFF><CENTER>\n");
    po.document.write(text);
    po.document.write("\n<BR><A HREF=\"javascript\:self.close\(\)\">Close Window</A>\n");
    po.document.write("</CENTER></BODY></HTML>");



}

function show_code() {
    build_code();
    var lCode = getElementById_s("lCode");
    var lstnumoffers = getElementById_s("lstnumoffers");
    var lstdomains = null;
    lstdomains = getElementById_s("ctl00_ContentPlaceHolder1_DropDownListDomains");


    var lSourceCode = getElementById_s("lSourceCode");
    if (document.aspnetForm.wgCode.value == '') {
        alert("Please choose an ad size/format first");
        return false;
    }

    if (lCode.style.display == 'none') {
        center(lCode);
        scroll(0, 0);
        lCode.style.display = 'block';
        lCode.style.width = screen.width;
        lCode.style.height = screen.height;
        lSourceCode.style.display = 'block';
        try {
            lstnumoffers.style.display = 'none';
            if (lstdomains != null)
                lstdomains.style.display = 'none';
        }
        catch (err) { }
    }
    else {
        lCode.style.display = 'none';
        lSourceCode.style.display = 'none';
        try {
            lstnumoffers.style.display = '';
            if (lstdomains != null)
                lstdomains.style.display = '';
        }
        catch (err) { }
    }


}

function show_demo() {
    build_code();
    shDemo('demo');
    return;
    if (document.aspnetForm.wgCode.value == '') {
        alert("Please choose an ad size/format first");
        return false;
    }

}

function GetCodeOnBlur() {
    document.aspnetForm.wgCode.style.background = "#ffffff";
    document.aspnetForm.wgCode.style.color = "#000000";
}

function copyToClipboard(meintext) {
    if (window.clipboardData) {

        // the IE-way
        window.clipboardData.setData("Text", meintext);

        // Probabely not the best way to detect netscape/mozilla.
        // I am unsure from what version this is supported
    }
    else if (window.netscape) {
        try {
            // This is importent but it's not noted anywhere
            netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
        }
        catch (err) {
            return false;
        }
        // create interface to the clipboard
        var clip = Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
        if (!clip) return;

        // create a transferable
        var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable);
        if (!trans) return;

        // specify the data we wish to handle. Plaintext in this case.
        trans.addDataFlavor('text/unicode');

        // To get the data from the transferable we need two new objects
        var str = new Object();
        var len = new Object();

        var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString);

        var copytext = meintext;

        str.data = copytext;

        trans.setTransferData("text/unicode", str, copytext.length * [[[[2]]]]);

        var clipid = Components.interfaces.nsIClipboard;

        if (!clip) return false;

        clip.setData(trans, null, clipid.kGlobalClipboard);

    }
    document.aspnetForm.wgCode.style.background = "#000000";
    document.aspnetForm.wgCode.style.color = "#ffffff";
    return false;
}

function onAffiliateType(strTypeValue) {
    if (strTypeValue == '3') {
        getElementById_s("lblCompanyName").innerHTML = "Company Name*";
        getElementById_s("lblEmail").innerHTML = "Email(Paypal account)*";
    }
    else {
        getElementById_s("lblCompanyName").innerHTML = "Make Check Payable To:*";
        getElementById_s("lblEmail").innerHTML = "Account Email*";
    }
}

function InitForms() {
    radiobysize();
    radiobyoffersnum();
    setDomainValue();
    document.aspnetForm.wgCode.style.background = "#ffffff";
    document.aspnetForm.wgCode.style.color = "#000000";
    var wg_link_color = 'FF6600';
    var wg_text_color = '000000';
    var wg_border_color = 'E5E5E5';
    var width = 600;
    var height = 140;
    var length = 5;
    var fontfamily = "";
    var fontstyle = "";
    var noncore = false;
    var bxExtCss = "";
    var wgdomain = getElementById_s("wgdomain");
    var lblSettingsFor = getElementById_s("ctl00_ContentPlaceHolder1_Label1");

//    try {
//        if (getElementById_s("ctl00_ContentPlaceHolder1_CheckBoxCoreVal").value === '0')
//            getElementById_s("CheckBoxCore").checked = 0;
//        else
//            getElementById_s("CheckBoxCore").checked = 1;
//    }
//    catch (err) {

//    }

    if (getElementById_s("ctl00_ContentPlaceHolder1_fontcolorVal").value != "") {
        wg_text_color = getElementById_s("ctl00_ContentPlaceHolder1_fontcolorVal").value;
    }

    if (getElementById_s("ctl00_ContentPlaceHolder1_linkcolorVal").value != "") {
        wg_link_color = getElementById_s("ctl00_ContentPlaceHolder1_linkcolorVal").value;
    }

    if (getElementById_s("ctl00_ContentPlaceHolder1_linkcolorVal").value != "") {
        wg_border_color = getElementById_s("ctl00_ContentPlaceHolder1_bordercolorVal").value;
    }

    getElementById_s("bordercolorbutton").style.backgroundColor = '#' + wg_border_color;
    getElementById_s("linkcolorbutton").style.backgroundColor = '#' + wg_link_color;
    getElementById_s("fontcolorbutton").style.backgroundColor = '#' + wg_text_color;

    if (getElementById_s("ctl00_ContentPlaceHolder1_wszVal").value != "")
        width = getElementById_s("ctl00_ContentPlaceHolder1_wszVal").value;
    if (getElementById_s("ctl00_ContentPlaceHolder1_lstnumoffersVal").value != "")
        length = getElementById_s("ctl00_ContentPlaceHolder1_lstnumoffersVal").value;

    if (getElementById_s("ctl00_ContentPlaceHolder1_fontFamilyVal").value != "")
        fontfamily = getElementById_s("ctl00_ContentPlaceHolder1_fontFamilyVal").value;
    if (getElementById_s("ctl00_ContentPlaceHolder1_fontStyleVal").value != "")
        fontstyle = getElementById_s("ctl00_ContentPlaceHolder1_fontStyleVal").value;

    if (fontfamily != "")
        getElementById_s("fontFamily").value = fontfamily;
    if (fontstyle != "")
        getElementById_s("fontStyle").value = fontstyle;
    if (fontfamily != "" && fontstyle != "")
        sendvalue();



    try {
        if (getElementById_s("ctl00_ContentPlaceHolder1_CheckBoxCoreVal").value == "1")
            getElementById_s("CheckBoxCore").checked = "checked";



        if (getElementById_s("ctl00_ContentPlaceHolder1_bxExtCssVal").value != "") {
            getElementById_s("bxExtCss").value = getElementById_s("ctl00_ContentPlaceHolder1_bxExtCssVal").value;
            getElementById_s("chkDefaultCss").checked = "";

        }
        if (getElementById_s("ctl00_ContentPlaceHolder1_txtButtonText").value != "" && getElementById_s("ctl00_ContentPlaceHolder1_txtButtonText").value != "Visit Store") {
            getElementById_s("ctl00_ContentPlaceHolder1_bxButtonText").value = getElementById_s("ctl00_ContentPlaceHolder1_txtButtonText").value;
            getElementById_s("chkDefaultButton").checked = "";

        }
        else {
            getElementById_s("ctl00_ContentPlaceHolder1_bxButtonText").value = "";
            getElementById_s("chkDefaultButton").checked = "checked";
        }

        if (getElementById_s("ctl00_ContentPlaceHolder1_txtHeaderText").value != "") {
            getElementById_s("ctl00_ContentPlaceHolder1_txtHeadText").value = getElementById_s("ctl00_ContentPlaceHolder1_txtHeaderText").value;
            getElementById_s("chkDefaultHeader").checked = "";

        }

        if (getElementById_s("ctl00_ContentPlaceHolder1_txtWhatThis").value == "1") {
            getElementById_s("wt").checked = "";
            getElementById_s("ic").checked = "checked";

        }
    }
    catch (err) {
    }

    try {
        if (getElementById_s("ctl00_ContentPlaceHolder1_lstnumoffersVal").value != "") {
            lstnumoffersobj = getElementById_s("lstnumoffers");
            for (z = 0; z < (lstnumoffersobj.length - 1); z++) {
                if (lstnumoffersobj[z].value == getElementById_s("ctl00_ContentPlaceHolder1_lstnumoffersVal").value) {
                    lstnumoffersobj[z].selected = "1";
                    break;
                }
            }
        }
    }
    catch (err) {
    }

    defaultheadertext();
    defaultbuttontext();

    try {
        document.aspnetForm.adformat.options[0].selected = "selected";
    }
    catch (err) {
        try {
            document.aspnetForm.wsz.value = width;
            document.aspnetForm.hsz.value = height;
        }
        catch (er) {
        }
    }
    try {
        document.aspnetForm.wgaid.value = "";
    }
    catch (er) {
    }
    document.aspnetForm.wgCode.value = "";
    //getElementById_s("wgpreview").innerHTML = "Your Widget Preview Will Show Here";
    document.aspnetForm.bordercolor.value = wg_border_color;
    document.aspnetForm.fontcolor.value = wg_text_color;
    document.aspnetForm.linkcolor.value = wg_link_color;
    build_code();



    try {
        if (wgdomain.value == "") {
            lblSettingsFor.style.display = "none";
        }

    }
    catch (err) {
    }
    //Hide copy button for non IE browser
    if (navigator.userAgent.indexOf("MSIE") == -1) {
        var btnCopy = getElementById_s("btnCopy");
        btnCopy.style.display = "none";

    }
}

function wopen(url, name, w, h) {
    // Fudge factors for window decoration space.
    // In my tests these work well on all platforms & browsers.
    w += 32;
    h += 96;
    var win = window.open(url,
  name,
  'width=' + w + ', height=' + h + ', ' +
  'location=no, menubar=no, ' +
  'status=no, toolbar=no, scrollbars=no, resizable=no');
    win.resizeTo(w, h);
    win.focus();
}

function center(object) {
    object.style.marginLeft = "-" + parseInt(object.offsetWidth / 2) + "px";
    object.style.marginTop = "-" + parseInt(object.offsetHeight / 2) + "px";
}
function getText(n) {
    if ('textContent' in n) {
        return n.textContent;
    } else if ('innerText' in n) {
        return n.innerText;
    } else {
        return "";
    }
}
