﻿// Globals.
var couponWorksXmlHttp;

function bookmark_us(siteUrl){
    var url=siteUrl;
    var title = 'Couponn.net - Hot Deals and Coupons';

    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if(window.opera && window.print){ // opera
        var elem = document.createElement('a');
        elem.setAttribute('href',url);
        elem.setAttribute('title',title);
        elem.setAttribute('rel','sidebar');
        elem.click();
    } 
    else if(document.all)// ie
        window.external.AddFavorite(url, title);
}

function createXmlHttp()
{
    var instance;
    
    //
    // Use the right method to create an instance of XMLHTTP object.
    //
    if (window.XMLHttpRequest) { 
        instance = new XMLHttpRequest(); 
    } 
    else if (window.ActiveXObject) { 
        try { 
            instance = new ActiveXObject("Msxml2.XMLHTTP"); 
        } 
        catch (e){ 
            try{ 
                instance = new ActiveXObject("Microsoft.XMLHTTP"); 
            } 
            catch (e){} 
        }     
    }
        
    return instance;
}

function couponWorks(tagName, couponId, worked)
{
    var url = "/couponWorked.aspx?couponid=";
    
    url = url.concat(couponId);
    url = url.concat("&worked=");
    url = url.concat(worked);
    
    couponWorksXmlHttp = createXmlHttp();
    couponWorksXmlHttp.open("POST", url, false);
    couponWorksXmlHttp.send("");

    if (couponWorksXmlHttp.status==200)
    {
        document.getElementById(tagName).innerHTML = couponWorksXmlHttp.responseText;
    }
    else
    {
        document.getElementById(tagName).innerHTML = couponWorksXmlHttp.status;
    }
    
    delete couponWorksXmlHttp;
}

function couponThumbs(tagName, couponId, thumbsUp)
{
    var url = "/couponThumbs.aspx?couponid=";
    
    url = url.concat(couponId);
    url = url.concat("&thumbs=");
    url = url.concat(thumbsUp);
    
    couponWorksXmlHttp = createXmlHttp();
    couponWorksXmlHttp.open("POST", url, false);
    couponWorksXmlHttp.send("");
    
    if (couponWorksXmlHttp.status==200)
    {
        document.getElementById(tagName).innerHTML = couponWorksXmlHttp.responseText;
    }
    
    delete couponWorksXmlHttp;
}

function openHelpWindow()
{
    var helpWindow;

    helpWindow = window.open("/howtouse.aspx","","height=400,width=650,toolbar=0,menubar=0,scrollbars=1,resizable=1");
    
    if (helpWindow.opener==null) { helpWindow.opener=self; }
    if (helpWindow.focus) { helpWindow.focus(); }
}

function openParentUrl(url)
{
    window.opener.location = url;
    window.opener.focus(); 
}

function goDelicious()
{
    var url = 'http://del.icio.us/post?v=2&url=';
    
    url = url.concat(encodeURIComponent(document.location.href));
    url = url.concat('&title=');
    url = url.concat(encodeURIComponent(document.title));
    
    location.href = url;
 }
