﻿var b_timer = null;
var b_on = true;
var blnkrs = null;
var stopbanner = "0";


function blink() {
    var tmp = document.getElementsByTagName("span");
    if (tmp) {
        blnkrs = new Array();
        var b_count = 0;
        for (var i = 0; i < tmp.length; ++i) {
            if (tmp[i].className == "blink") {
                blnkrs[b_count] = tmp[i];
                ++b_count;
            }
        }

        blinkTimer(500);
    }
}

function blinkTimer(ival) {
    if (b_timer) {
        window.clearTimeout(b_timer);
        b_timer = null;
    }
    blinkIt();
    b_timer = window.setTimeout('blinkTimer(' + ival + ')', ival);
}

function blinkIt() {
    for (var i = 0; i < blnkrs.length; ++i) {
        if (b_on == true) {
            blnkrs[i].style.visibility = "hidden";
        }
        else {
            blnkrs[i].style.visibility = "visible";
        }
    }
    b_on = !b_on;
}



function MM_swapImgRestore() {
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_preloadImages() {
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_findObj(n, d) {
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && document.getElementById) x = document.getElementById(n); return x;
}

function MM_swapImage() {
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

function ToggleAll(e) {
    if (e.checked) {
        SetChecked(1);
    }
    else {
        SetChecked(0);
    }
}




function SetChecked(val) {
    dml = document.form1;
    len = dml.elements.length;
    var i = 0;
    for (i = 0; i < len; i++) {
        if (dml.elements[i].name == 'checkbox') {
            dml.elements[i].checked = val;
        }
    }
}


function custom_print() {
    if (document.all) {
        if (navigator.appVersion.indexOf("5.0") == -1) {
            var OLECMDID_PRINT = 6;
            var OLECMDEXECOPT_DONTPROMPTUSER = 2;
            var OLECMDEXECOPT_PROMPTUSER = 1;
            var WebBrowser = "<OBJECT ID=\"WebBrowser1\" WIDTH=0 HEIGHT=0 CLASSID=\"CLSID:8856F961-340A-11D0-A96B-00C04FD705A2\"></OBJECT>";
            document.body.insertAdjacentHTML("beforeEnd", WebBrowser);
            WebBrowser1.ExecWB(6, 2);
            WebBrowser1.outerHTML = "";
        } else {
            self.print();
        }
    } else {
        self.print();
    }
}

function SK_reloadPage(init) {
    if (init == true) with (navigator) {
        if ((appName == "Netscape") && (parseInt(appVersion) == 4)) {
            document.SK_pgW = innerWidth; document.SK_pgH = innerHeight; onresize = SK_reloadPage;
        }
    }
    else if (innerWidth != document.SK_pgW || innerHeight != document.SK_pgH) location.reload();
}
SK_reloadPage(true);

function MM_reloadPage(init) {
    if (init == true) with (navigator) {
        if ((appName == "Netscape") && (parseInt(appVersion) == 4)) {
            document.MM_pgW = innerWidth; document.MM_pgH = innerHeight; onresize = MM_reloadPage;
        }
    }
    else if (innerWidth != document.MM_pgW || innerHeight != document.MM_pgH) location.reload();
}

MM_reloadPage(true);


function mk_of() {

    if (window.event.clientY < 0) {
        window.open('mk_of.asp', 'mkofmyl', 'width=1,height=1');
    }

}


function MM_openBrWindow(theURL, winName, features) {
    window.open(theURL, winName, features);
}

function dSM(msgStr) {
    status = msgStr;
}




function MM_findObj(n, d) {
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_validateForm() {
    var i, p, q, nm, test, num, min, max, errors = '', args = MM_validateForm.arguments;
    for (i = 0; i < (args.length - 2); i += 3) {
        test = args[i + 2]; val = MM_findObj(args[i]);
        if (val) {
            nm = val.name; if ((val = val.value) != "") {
                if (test.indexOf('isEmail') != -1) {
                    p = val.indexOf('@');
                    if (p < 1 || p == (val.length - 1)) errors += '- ' + nm + ' must contain an e-mail address.\n';
                } else if (test != 'R') {
                    num = parseFloat(val);
                    if (isNaN(val)) errors += '- ' + nm + ' must contain a number.\n';
                    if (test.indexOf('inRange') != -1) {
                        p = test.indexOf(':');
                        min = test.substring(8, p); max = test.substring(p + 1);
                        if (num < min || max < num) errors += '- ' + nm + ' must contain a number between ' + min + ' and ' + max + '.\n';
                    }
                }
            } else if (test.charAt(0) == 'R') errors += '- ' + nm + ' is required.\n';
        }
    } if (errors) alert('The following error(s) occurred:\n' + errors);
    document.MM_returnValue = (errors == '');
}

function emailvalidation(field, alertbox) {
    var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\.sex)|(\.biz)|(\.aero)|(\.coop)|(\.museum)|(\.name)|(\.pro)|(\..{2,2}))$)\b/gi);
    apos = field.value.indexOf("@");
    dotpos = field.value.lastIndexOf(".");
    lastpos = field.value.length - 1;
    var badEmail = (apos < 1 || dotpos - apos < 2 || lastpos - dotpos < 2)

    if (goodEmail && !badEmail) {
        return true;
    }
    else {
        alert(alertbox);
        field.focus();
        field.select();
        return false;
    }
}
function emptyvalidation(entered, alertbox) {
    with (entered) {
        if (value == null || value == "")
        { if (alertbox != "") { alert(alertbox); } return false; }
        else { return true; }
    }
}
function formvalidation(thisform) {
    with (thisform) {

        if (emailvalidation(email, "Please enter your valid email address") == false) { email.focus(); return false; };

    }

}
function outliner(aEvent) {
    //oMe = window.event.srcElement
    //get child element
    var child; //= document.all[event.srcElement.getAttribute("child",false)];
    var myEvent = aEvent ? aEvent : window.event;


    //document.all[event.currentTarget.getAttribute("child",false)];


    // Internet Explorer

    if (myEvent.srcElement) {
        child = document.getElementById(myEvent.srcElement.getAttribute("child"));
    }

    // W3C DOM
    if (myEvent.currentTarget) {
        //child=document.getElementsByTagName("*")[myEvent.Target.getAttribute("child",false)];
        child = document.getElementById(myEvent.target.getAttribute("child"))
    }




    //if child element exists, expand or collapse it.
    if (null != child) {
        child.className = child.className == "collapsed" ? "expanded" : "collapsed";
    }
}


function changepic() {
    uMe = window.event.srcElement;
    var check = uMe.src.toLowerCase();
    if (check.lastIndexOf("plus.gif") != -1) {
        uMe.src = "images/Minus.gif"
    }
    else {
        uMe.src = "images/Plus.gif"
    }
}

//jQuery(function($) {
 //  $("img").pngfix();
//});


function uuid() {
    var chars = '0123456789abcdef'.split('');

    var uuid = [], rnd = Math.random, r;
    uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
    uuid[14] = '4'; // version 4

    for (var i = 0; i < 36; i++) {
        if (!uuid[i]) {
            r = 0 | rnd() * 16;

            uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r & 0xf];
        }
    }

    return uuid.join('');
}



function PageMethod(fn, paramArray, successFn, errorFn) {
  

    var paramList = '';
    if (paramArray.length > 0) {
        for (var i = 0; i < paramArray.length; i += 2) {
            if (paramList.length > 0) paramList += ',';
            paramList += '"' + paramArray[i] + '":"' + paramArray[i + 1] + '"';
        }
    }
    paramList = '{' + paramList + '}';

    $.ajax({
        type: "POST",
        url: fn,
        contentType: "application/json; charset=utf-8",
        data: paramList,
        dataType: "json",
        success: successFn,
        error: errorFn
    });

}

function AjaxFailed(XMLHttpRequest, textStatus, errorThrown) {
    // alert(XMLHttpRequest + '\n' + textStatus + '\n' + errorThrown);
}
var $dialog




    function OpenSignUpDlg() {

        stopbanner = "1";
        $dialog = null;
        $dialog = $('<div id="signupdialog"></div>').load('RegisterUserAjax.html?uid=' + uuid() ).dialog({
            title: 'signup',
            autoOpen: false,
            width: 750,
            height: 610,
            modal: true,
            resizable: false,
            autoResize: false,
            draggable: false
        });


        $(".ui-dialog-titlebar-close").hide();
        $dialog.dialog('open');

        try {
            $("#username").focus();
        } catch (err) { }

    }

$(function () {

    $('#Signup').click(function (e) {
        e.preventDefault();
                var $this = $(this);
        OpenSignUpDlg();
    });

    
});



    function GetislandList() {
        PageMethod("functions/Ajaxfunctions.aspx/GetislandList", [], GetislandList_s, AjaxFailed);
    }

    function GetislandList_s(r) {
       
        var myObject = jQuery.parseJSON(r.d);
        var isl = myObject.islands;

         $("#ddlisland").append($('<option></option>').val('').html('-- Select --').attr("selected", "selected"));

         for (var i = 0; i <= isl.length - 1; i++) {
            $("#ddlisland").append($('<option></option>').val(isl[i].islandvalue).html(isl[i].islandname));
          
        }

    }


    var LoadCountries_id;
    var LoadStates_id;
    function LoadCountries(ID) {
        LoadCountries_id = ID;
        PageMethod("functions/Ajaxfunctions.aspx/GetCountryList", [], LoadCountries_s, AjaxFailed);              
    }

    function LoadCountries_s(r) {
        var myObject = eval(r.d);
        $("#ddlcountry").append($('<option></option>').val('').html('-- Select --'));
        for (var i = 0; i <= myObject.length - 1; i++) {
            $("#ddlcountry").append($('<option></option>').val(myObject[i].ID).html(myObject[i].CountryName));
            if (LoadCountries_id == myObject[i].ID) {
                $("#ddlcountry option[value = '" + LoadCountries_id + "']").attr("selected", "selected");
            }
        }

        $("#ddlstates").append($('<option></option>').val('').html('-- Select --'));
    }


    function LoadStates(CID, SID) {
        LoadStates_id = SID;
        $("#ddlstates>option").remove();
        PageMethod("functions/Ajaxfunctions.aspx/GetStates", ["CountryID",  CID ], LoadStates_s, AjaxFailed);   


    }

    function LoadStates_s(r) {

        var myObject = eval(r.d);
        $("#ddlstates").append($('<option></option>').val('').html('-- Select --'));
        for (var i = 0; i <= myObject.length - 1; i++) {
            $("#ddlstates").append($('<option></option>').val(myObject[i].ID).html(myObject[i].StateName));
            if (LoadStates_id == myObject[i].ID) {
                $("#ddlstates option[value = '" + LoadStates_id + "']").attr("selected", "selected");
            }
        }
    }



