﻿// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
    var rest = this.slice((to || from) + 1 || this.length);
    this.length = from < 0 ? this.length + from : from;
    return this.push.apply(this, rest);
};

function profileOpen(id) {
    
    var newWindow;
    var opts = 'address=0,width=620,height=600,scrollbars=yes,status=1,resizable=yes';
    var link = '/MemberProfile/ViewMember.aspx?memberid=' + id;
    newWindow = window.open(link, 'profile' + id, opts);

    if (newWindow == null || String(newWindow) == "undefined") {
        alert("Failed to open pop-up window. Please remove any popup blocker programs.");
    }
    else {
        newWindow.focus();
    }
    
    return false;
    
}

function openVideo(vidID) {
    var options = 'width=330,height=350,resizable=no,status=no'
    var new_window = window.open("/MemberVideo/player.aspx?video=" + vidID, "Video", options);

    if (new_window == null) {
        alert("Popup window can not open. Please disable all popup blockers.");
    }
    else {
        new_window.focus();
    }
    return false;
}

function openGallery(id, hdl, all) {
    var newWindow;
    var location = "/MemberPhoto/PhotoBrowes.aspx?public="+all+"&memberid=" + id + "&handle=" + hdl;
    var opts = 'toolbar=no,status=no,width=610,height=750';
    newWindow = window.open(location, 'PrivateGallery'+id, opts);

    if (String(newWindow) != "undefined") {
        newWindow.focus();
    }
    else {
        alert("Picture window failed to open. Please remove any popup blocker programs.");
    }
    return false;
}

function openClub(id) {
    var newWindow;
    var opts = 'toolbar=no,status=no,width=620,height=675, scrollbars=yes';
    var link = '/Club/Club.aspx?';
    newWindow = window.open(link + 'id=' + id, 'ClubDetail' + id, opts);

    if (String(newWindow) != "undefined") {
        newWindow.focus();
    }
    else {
        alert("Picture window failed to open. Please remove any popup blocker programs.");
    }

    return false;
}

function ddlRedir_OnChange(val) {
    window.location.href = val;
}


function getPopupAncestorWindow() {

    var winChild;
    var winParent;
    var win = window;

    winChild = win;
    winParent = getParent(winChild);

    while (winChild != winParent) {
        winChild = winParent;
        winParent = getParent(winChild);
    }
    
    return winParent;

}

function getParent(win) {
    var winParent;

    if (win.opener != null) {
        winParent = win.opener;
    }
    else if (win.parent != null) {
            winParent = win.parent;
    }
    else {
        winParent = win;
    }

    return winParent;
}

function getPopupAncestorWindowWhileClosingChild() {
    
    var winChild;
    var winParent;
    var winArray = new Array();
    var iCount;
    
    winParent = window;
    do{
        winChild = winParent;
        winParent = getParent(winChild);
        winArray.push(winChild);
    }
    while (winChild != winParent)

    for (var i = 0; i < winArray.length; i++) {
        if (winArray[i].bWinIdt) {
            winArray[i].close();
        }
        else {
            winParent = winArray[i];
            break;
        }
        
    }
    return winParent;
}


function redirParentCloseChild(url) {

    var winParent;
    var winGrandParent;

    winParent = getPopupAncestorWindowWhileClosingChild();
    winParent.location.href = url;

}

function setSelfClosePopupWindow() {

    if (window.opener != null) {
        window.close();
    }
    else if (window.parent != null) {
        window.parent.closePopup();
    }
    else {
        //not child window;
    }
}


function DisplayAlertMsg(WindowTitle, ValidationGroup) {

    var ret = Page_ClientValidate(ValidationGroup);
    var urlStr = "";

    if (!ret) {
        if (!Page_IsValid) {
            for (var i = 0; i < Page_Validators.length; i++) {
                if (Page_Validators[i].validationGroup == ValidationGroup && !Page_Validators[i].isvalid) {
                    urlStr += "\n" + Page_Validators[i].errormessage;
                }
            }

            PopupWin(WindowTitle, '/AlertMsg.aspx?Title=Please%20correct&Msg=' + escape(urlStr), 176, 400);
        }
    }
    return ret;
}

function DisplayAlert(Msg) {
    PopupWin('Error!', '/AlertMsg.aspx?Title=Please%20correct&Msg=' + escape(Msg), 176, 400);
}

function redirectToUpgrade(mID) {
    /*var win = getPopupAncestorWindowWhileClosingChild();
    if (win.parent != null) {
        win.parent.location.href = "/PayMemberships/";
    }
    else {
        win.location.href = "/PayMemberships/";
    }*/
    //redirParentCloseChild('/PayMemberships/');
    
    if (window.opener == null) {
        window.location.href = "../PayMemberships/";
    }
    else if (window.opener.parent == null) {
        window.opener.location.href = "../PayMemberships/";
        window.close();
    }
    else {
        window.opener.parent.location.href = "../PayMemberships/";
        window.close();
    }
}

function stripHTML(oldString) {

    var newstring = oldString.replace(/<.*?>/g, "");
    newstring = newstring.replace(/&nbsp;/g, '');
    newstring = newstring.replace(/\\n/g, '');
    newstring = newstring.replace(/\\r/g, '');
    newstring = unescape(escape(newstring).replace(/%20/g, ''));
    newstring = unescape(escape(newstring).replace(/%0D%0A/g, ''));
    return newstring;
}

function SetUniqueRadioButton(nameregex, current) {
    re = new RegExp(nameregex);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio') {
            if (re.test(elm.name)) {
                elm.checked = false;
            }
        }
    }
    current.checked = true;
}

function RadioButtonRepeater_Validation(nameregex) {
    var retVal;
    var re = new RegExp(nameregex);
    retVal = false;
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio') {
            if (re.test(elm.name)) {
                if (elm.checked) {
                    retVal = true;
                    break;
                }
            }
        }
    }
    return retVal;
}

function CheckBoxRepeater_Validation(nameregex) {
    var retVal;
    var re = new RegExp(nameregex);
    retVal = false;
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type.toLowerCase() == 'checkbox') {
            if (re.test(elm.name)) {
                if (elm.checked) {
                    retVal = true;
                    break;
                }
            }
        }
    }
    return retVal;
}

function CheckBoxRepeaterItem_Click(nameregex, checkAllId) {
    var re = new RegExp(nameregex);
    var checkAll = true;
    //var uncheckAll = true;
    var chkAllObj = document.getElementById(checkAllId);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type.toLowerCase() == 'checkbox') {
            if (re.test(elm.name)) {
                if (elm.checked) {
                    //uncheckAll = false;
                }
                else {
                    checkAll = false;
                }
            }
        }
    }

    if (checkAll) { chkAllObj.checked = true; }
    else { chkAllObj.checked = false; }
    //if (uncheckAll) { chkAllObj.checked = false; }

}

function CheckBoxRepeaterCheckAll_Click(nameregex, checkAllId) {
    var re = new RegExp(nameregex);
    var chkAllObj = document.getElementById(checkAllId);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type.toLowerCase() == 'checkbox') {
            if (re.test(elm.name)) {
                elm.checked = chkAllObj.checked;
            }
        }
    }
}

function isDate(year, month, day) {
	// month argument must be in the range 1 - 12
	month = month - 1; // javascript month range : 0- 11
	var tempDate = new Date(year,month,day);
	if ( ((tempDate.getFullYear()) == year) && (month == tempDate.getMonth()) && (day == tempDate.getDate()) ){
		return true;
	}
	else {
		return false;
	}
}

function dateValid(year, month, day, hour, minute) {
    // month argument must be in the range 1 - 12
    month = month - 1; // javascript month range : 0- 11
    var tempDate = new Date(year, month, day, hour, minute, 0, 0);
    var nowDate = new Date();
    if (tempDate >= nowDate) {
        return true;
    }
    else {
        return false;
    }
}

function SetTxtValueState(val, txt) {

    if (txt.value == val) {
        txt.value = '';
    }
    else if (txt.value == '') {
        txt.value = val;
    }
    else {

    }
}

function SetPwdOnBlur(id, idShadow) {

    var txt = document.getElementById(id);
    var txtShadow = document.getElementById(idShadow);

    if (txt.value.length == 0) {
        txt.style.visibilty = 'hidden';
        txtShadow.style.visibilty = 'visible';
    }
}

function SetPwdOnFocus(id, idShadow) {
    var txt = document.getElementById(id);
    var txtShadow = document.getElementById(idShadow);

    txt.style.visibility = 'visible';
    txt.focus();
    txtShadow.style.visibility = 'hidden';
}


function btnClick_RedirJoinParty() {
    window.location.href = '/Registration/JoinParty.aspx';
    return false;
}

