﻿var WIN_OPTIONS = "width=622,height=560,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0";
var VERIZON_OPTIONS = "width=840,height=560,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=1";
var popup;
var timer;
var furl;

//an open window object.
var popWin = null;

//force ie caching of bg images
try { document.execCommand("BackgroundImageCache", false, true); } catch (err) { }

//a trim function extension for strings
String.prototype.trim = function() { return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, '$1'); };

function closeWindow() {
    if (popWin) {
        popWin.close();
    }
}

function openWindow(name, url) {
    closeWindow();
    popWin = window.open(url, name, WIN_OPTIONS);
}

function openVerizonWindow(name, url) {
    closeWindow();
    popWin = window.open(url, name, VERIZON_OPTIONS);
}

//ensure that the thanks window is closed (if already open)
function CloseThanksWindow() {
    try {
        var modalPopup = $find(_popupButtonID);
        if (modalPopup != null) {
            modalPopup.hide();
            return true;
        }
        return false;
    }
    catch (ex) {
        return false;
    }
}

function GetMail(mail, url, forwardurl) {
    var doMail = true;
    if (mail == 'GMAIL' || mail == 'YAHOO' || mail == 'WINDOWSLIVE' || mail == 'AOL') {
        $('.buttons').attr("disabled", true);
    }
    else {
        doMail = false;
    }
    furl = forwardurl;

    if (doMail == true) {
        var popup_height = '600';
        var popup_width = '900';

        popup = window.open(url + "?type=" + mail, "_popupWindow", 'height=' + popup_height + ',width=' + popup_width + ',location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no');
        timer = window.setInterval(LoadContacts, 1000);
        popup.focus();
    }
}

function LoadContacts() {
    if (popup.closed) {
        window.clearInterval(timer);
        window.location = furl;
    }
}

function CheckWindowStatus() {
    try {
        var val = popup.window;
        if (val == null)
            return false;
        else
            return true;
    }
    catch (ex) {
        return false;
    }
}

function CheckAll(inputclass) {
    $(inputclass).attr('checked', true);
}

function UncheckAll(inputclass) {
    $(inputclass).attr('checked', false);
}

function HideScroll() {
    document.body.style.overflow = 'hidden'; 
}
