﻿
var LightBoxHoldertop = '30%';
var LightBoxHolderleft = '40%';
var wrapperWidth = 960;

function Is() {
    agent = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.ns = ((agent.indexOf('mozilla') != -1) &&
      ((agent.indexOf('spoofer') == -1) && (agent.indexOf('compatible') == -1)));
    this.firefox = (this.ns && (agent.indexOf('firefox') != -1));
    this.ns4 = (this.ns && (this.major == 4));
    this.ns6 = (this.ns && (this.major >= 5));
    this.chrome = (this.ns && (agent.indexOf("chrome") != -1));
    this.ie = (agent.indexOf("msie") != -1);
    this.ie3 = (this.ie && (this.major < 4));
    this.ie4 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.0") == -1));
    this.ie5 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.0") != -1));
    this.ie55 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.5") != -1));
    this.ie6 = (this.ie && (agent.indexOf("msie 6.0") != -1));
    this.ie7 = (this.ie && (agent.indexOf("msie 7.0") != -1));
    this.ie8 = (this.ie && (agent.indexOf("msie 8.0") != -1));
    this.opera = (agent.indexOf("opera") != -1);
    this.safari = (!this.chrome && agent.indexOf("safari") != -1);
    this.Win16 = (navigator.platform == "Win16");
    this.Mac = (navigator.platform == "Mac" || navigator.platform == "MacIntel");
    this.Win32 = (navigator.platform == "Win32");
    this.Win64 = (navigator.platform == "Win64");
    this.OtherOS = (this.Win16 == false && this.Mac == false && this.Win32 == false && this.Win64 == false);

    var d = document.getElementById("AIMcheck");
    this.gotaim = false;
    if (d != null) {
        CheckForAIM(d);
        if (navigator.mimeTypes && navigator.mimeTypes.length) {
            source = 'Mozilla';
            if (navigator.mimeTypes['application/x-aim'])
                this.gotaim = true;
            if (navigator.mimeTypes['application/x-aim+amo']) {
                this.gotaim = true;
                this.gotamo = true;
                this.amoversion = 1;
            }
        }
        else if (!this.gotaim) {
            if (typeof (isaim) == 'object' && typeof (isaim.amo) == 'number') {
                this.gotamo = true;
                this.gotaim = true;
                this.amoversion = isaim.amo;
            }
        }
    }
}

var is = new Is();
var BGDisabled = false;

function isEmailAddr(EMailAddr) {
    var EmailAddressRX = /^(.+)@(.+)\.(.+)$/;  // Check for pattern string.string

    var matches = EMailAddr.match(EmailAddressRX);
    if (matches == null) // IT'S BAD TO THE BONE.
        return false;
    // MORE CHECKING MAY BE REQUIRED -
    return true;
}

function isNumber(val) {
    var invaldChar = /[^0-9]/;  // Check for pattern string.string
    var matches = val.match(invaldChar);
    if (matches != null)
        return false;

    return true;
}
function ValidateAlphaOnly(txb) {
    var isValid = ValidateNoSpaceText(txb)
    var invaldChar = /[0-9]/;  // Check for pattern string.string
    var matches = txb.value.match(invaldChar);
    if (matches != null)
        isValid = false;
    return isValid;
}

function ValidateNoSpaceText(txb) {
    var isValid = true;
    if (txb.value.Trim() != '') {
        if (txb.value.indexOf(' ') > -1) {
            isValid = false;
        }
    }
    else
        isValid = false;
    return isValid;
}
function ValidateName(txb) {
    var isValid = ValidateNoSpaceText(txb)
    var invaldChar = /[0-9]/;  // Check for pattern string.string
    var matches = txb.value.match(invaldChar);
    if (matches != null)
        isValid = false;
    return isValid;
}

function ValidateUniqueSubdomain(txb) {
    var isValid = ValidateNoSpaceText(txb)
    var ValidChara = /[^A-z0-9-_]/;  // Check for pattern string.string
    var matches = txb.value.match(ValidChara);
    if (matches != null) {
        return false;
    }
    var invalidChar = /[\^\[\]]/;
    matches = txb.value.match(invalidChar);
    if (matches != null)
        isValid = false;

    if (isValid)
        ValidateUniquePartnerSubdomain(txb);
    return isValid;
}

function sendRequest(url, callback, postData) {
    var req = createXMLHTTPObject();
    if (!req) return;
    var method = (postData) ? "POST" : "GET";
    req.open(method, url, true);
    req.setRequestHeader('User-Agent', 'XMLHTTP/1.0');
    if (postData)
        req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    req.onreadystatechange = function() {
        if (req.readyState != 4) return;
        if (req.status != 200 && req.status != 304) {
            //			alert('HTTP error ' + req.status);
            return;
        }
        callback(req);
    }
    if (req.readyState == 4) return;
    req.send(postData);
}

var XMLHttpFactories = [
	function() { return new XMLHttpRequest() },
	function() { return new ActiveXObject("Msxml2.XMLHTTP") },
	function() { return new ActiveXObject("Msxml3.XMLHTTP") },
	function() { return new ActiveXObject("Microsoft.XMLHTTP") }
];
function createXMLHTTPObject() {
    var xmlhttp = false;
    for (var i = 0; i < XMLHttpFactories.length; i++) {
        try {
            xmlhttp = XMLHttpFactories[i]();
        }
        catch (e) {
            continue;
        }
        break;
    }
    return xmlhttp;
}
function ActivateBG() {
    var GrayBG = document.getElementById('divDisableMasterPage');
    if (is.firefox) {
        var FireFoxDisableLayer = document.getElementById('divDisableFireFox');
        if (FireFoxDisableLayer != null) {
            GrayBG = FireFoxDisableLayer;
        }
    }
    if (GrayBG != null) {
        GrayBG.style.zIndex = 0;
        GrayBG.style.display = 'none';
        BGDisabled = false;
        if (is.ie6) {
            var formtag = document.getElementById("aspnetForm");
            var Controls = formtag.getElementsByTagName('Select');
            for (var iControlCount = 0; iControlCount < Controls.length; iControlCount++) {
                Controls[iControlCount].style.display = '';
            }
        }
    }
    var UploadImageButton = document.getElementById('UploadImageButtonHolder');
    if (UploadImageButton != null) {
        UploadImageButton.style.display = '';
    }
}

function DisableBG() {
    EndOFPagecoords = findPos(document.getElementById('EndOFPage'));
    if (is.opera) {
        page_width = document.body.clientWidth;
        page_height = document.body.clientHeight;
    }
    else if (is.firefox || is.ns6 || is.safari) {
        page_width = innerWidth;
        page_height = innerHeight;
    }
    else if (is.ie) {
        page_width = document.body.clientWidth;
        page_height = document.body.clientHeight;
        if (is.ie6) {
            var formtag = document.getElementById("aspnetForm");
            var Controls = formtag.getElementsByTagName('Select');
            for (var iControlCount = 0; iControlCount < Controls.length; iControlCount++) {
                if (Controls[iControlCount].id != "ctl00_ContentPlaceHolder1_ddSearchType")
                    Controls[iControlCount].style.display = 'none';
            }
        }
    }
    else {
    }
    if (EndOFPagecoords[1] < page_height) {
        EndOFPagecoords[1] = page_height;
    }
    if (page_width < wrapperWidth) {
        if (is.ie) {
            LightBoxHolderleft = page_width * .25;
        }
        page_width = wrapperWidth;
    }
    layerSetup();

    var UploadImageButton = document.getElementById('UploadImageButtonHolder');
    if (UploadImageButton != null) {
        UploadImageButton.style.display = 'none';
    }
    BGDisabled = true;
}
function findPos(obj) {
    var curleft = curtop = 0;
    if (obj != null) {
        if (obj.offsetParent) {
            curleft = obj.offsetLeft
            curtop = obj.offsetTop
            while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
            }
        }
    }
    return [curleft, curtop];
}
function findRelitivePos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
    }
    return [curleft, curtop];
}

/**
Gets the offset of a tag to its absolute container.
A typical check for offsets requires looping up to the HTML tag for .offsetParent,
and adding up the offsets along the way. (See findPos.)
If you use this method to then position something inside of an absolute container,
the position will be off by the offset outside that absolutely positioned container
as absolute positioning (top and left) is relative to its immediate container, not
the HTML root.

@param tag :HtmlElement		A tag to get the offset to its nearest absolute container
@return	:Array[left, top]
*/
function getAbsoluteOffset(tag) {
	var a = [0, 0];
	do {
		a[0] += tag.offsetLeft;
		a[1] += tag.offsetTop;
		tag = tag.offsetParent;
	} while (tag && $.curCSS(tag, 'position') != 'absolute');

	return a;
}

/**
Loop up the parents until fn succeeds, then return the matching parent
@param tag :HtmlElement		The tag to start with
@param fn :Function(tag)	The condition that causes a parent to be returned
@return :HtmlElement	The matching parent, or null
*/
function getParent(tag, fn) {
	while (tag) {
		if (fn(tag))
			return tag;
		
		tag = tag.parentNode;
	}

	return null;
}

function layerObject(id, position) {
    if (is.ie || is.ns6 || is.firefox || is.opera || is.safari) {
        var obj = document.getElementById(id).style;
        obj.position = position;
        obj.left = 0;
        obj.top = 0;
        obj.height = EndOFPagecoords[1] + 'px';
        obj.display = '';
        obj.width = page_width + 'px';
        obj.zIndex = 3;
    }
    else {
    }
}
function layerSetup() {
    if (is.firefox) {
        var FireFoxDisableLayer = document.getElementById('divDisableFireFox');
        if (FireFoxDisableLayer != null) {
            layerObject('divDisableFireFox', 'absolute');
            return;
        }
    }
    layerObject('divDisableMasterPage', 'absolute');
}
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
function LaunchSearch(e) {
    oEvent = (window.event) ? window.event : e;
    switch (oEvent.keyCode) {
        case 13: //enter
            //call the search function
            //SearchButtonClick();
            oEvent.returnValue = false;
            oEvent.cancel = true;
            return false;
            break;
        default:
            return false;
            break;
    }
}

//convert client side time to utc time and pass to server side.
function CovertToUTCStrFromClient(clientTimeStr) {
    var clientTime = new Date(clientTimeStr);
    var clientMonth = clientTime.getUTCMonth() + 1;
    var utcTimeStr = clientMonth + "/" + clientTime.getUTCDate() + "/" + clientTime.getUTCFullYear() + " " + clientTime.getUTCHours() + ":" + clientTime.getUTCMinutes();
    return utcTimeStr;
    ////    alert(clientTime.toUTCString());
    //    var clientTimeMilliSeconds = clientTime.getTime();
    //    var clientOffset = clientTime.getTimezoneOffset() * 60000;   //60000 milliseconds, 60 seconds or 1 minutes)
    //    var utc = new Date(clientTimeMilliSeconds + clientOffset);
    //    alert(utc.toString());
    //    return utc.toString();
}

function ActivateButton(button, blActive, currentlyActive, mouseover, mouseout, click) {
    if (blActive && !currentlyActive) {
        if (button.addEventListener) {
            if (mouseover != null)
                button.addEventListener("mouseover", mouseover, false);
            if (mouseout != null)
                button.addEventListener("mouseout", mouseout, false);
            if (click != null)
                button.addEventListener("click", click, false);
        }
        else if (button.attachEvent) {
            if (mouseover != null)
                button.attachEvent("onmouseover", mouseover);
            if (mouseout != null)
                button.attachEvent("onmouseout", mouseout);
            if (click != null)
                button.attachEvent("onclick", click);
        }
        else {
            if (mouseover != null)
                button.onmouseover = mouseover;
            if (mouseout != null)
                button.onmouseout = mouseout;
            if (click != null)
                button.onclick = click;
        }
        currentlyActive = true;
        return currentlyActive;
    }
    if (!blActive && currentlyActive) {
        if (button.addEventListener) {
            if (mouseover != null)
                button.removeEventListener("mouseover", mouseover, false);
            if (mouseout != null)
                button.removeEventListener("mouseout", mouseout, false);
            if (click != null)
                button.removeEventListener("click", click, false);
        }
        else if (button.attachEvent) {
            if (mouseover != null)
                button.detachEvent("onmouseover", mouseover);
            if (mouseout != null)
                button.detachEvent("onmouseout", mouseout);
            if (click != null)
                button.detachEvent("onclick", click);
        }
        else {
            button.onmouseover = null;
            button.onmouseout = null;
            button.onclick = null;
        }
        currentlyActive = false;
    }
    return currentlyActive;
}
function goButtonOver(button) {
    if (button.src.indexOf("_hover") > -1 || button.src.indexOf("_inactive") > -1)
        return;
    var startpoint = button.src.lastIndexOf('/');
    button.src = button.src.substring(0, button.src.indexOf('.', startpoint)) + "_hover" + button.src.substring(button.src.indexOf('.', startpoint));
}
function goButtonOut(button) {
    button.src = button.src.replace("_hover", "");
}

var btLogin;
var fn;
var ln;
var em;
var em1;
var ps;
var ps2;
var rc1;
var rc2;
var cba;

function navButtonOver(button) {
    var startpoint = button.src.lastIndexOf('/');
    button.src = button.src.substring(0, button.src.indexOf('.', startpoint)) + "_active" + button.src.substring(button.src.indexOf('.', startpoint));
}
function navButtonOut(button) {
    button.src = button.src.replace("_active", "");
}


function loginButtonOver() {
    goButtonOver(btLogin);
}
function loginButtonOut() {
    goButtonOut(btLogin);
}

function login() {
    //document.getElementById("form1").submit();
}

var emailExists = 0;
var existEmail = "";
function EmailChanged(box) {
    emailExists = 0;
    if (box.value.toLowerCase() == existEmail.toLowerCase())
        emailExists = 1;
    else
        emailExists = 0; 
}

function ValidateEmailAddress(box) {
    var Field = getFieldIndex(box.id);
    if (Field == -1) {
        hideError();
        return;
    }
    if (!Fields[Field].Status)
        return;
    if (box != null) {
        var addr = box.value;
        if (addr != null && addr.length > 0) {
            if (!isEmailAddr(addr)) {
                box.style.color = "red";
                Fields[Field].Status = true;
                Fields[Field].ErrorTitle = "Not a valid email address";
                Fields[Field].ErrorMessage = "We're sorry, this is not the correct format<br> for an email address.";
                getError(box);
            }
            else if (emailExists == 1) {
            Fields[Field].Status = true;
                box.style.color = "red";
                Fields[Field].ErrorTitle = "Error";
                Fields[Field].ErrorMessage = "Account already exists.";
                return;
            }
            else {
                resetError(box);
            }
        }
        else {
            resetError(box);
        }
        if (Fields[Field].ErrorTitle == "")
            if (em1 != null)
            ValidateConfirmEmailAddress(box);
    }
}
function resetError(sender) {
    var Field = getFieldIndex(sender.id);
    if (Field > -1) {
        sender.style.color = "#363636";
        Fields[Field].ErrorTitle = "";
        Fields[Field].ErrorMessage = "";
        RemoveField(sender);
    }
    hideError();
}

function RemoveField(sender) {
    var objIndex = getFieldIndex(sender.id);
    if (objIndex == -1)
        return;
    Fields[objIndex].Status = false;
    hideError();
}
function AddField(obj) {
    var objIndex = getFieldIndex(obj.id);
    if (objIndex != -1) {
        Fields[objIndex].Status = true;
        return;
    }
    var Field = new FieldInfo();
    Field.ID = obj.id;
    Field.Status = true;
    Fields.push(Field);
}
function CheckField(FieldID) {
    var FieldIndex = false;
    for (var iField = 0; iField < Fields.length; iField++) {
        if (FieldID == Fields[iField].ID) {
            FieldIndex = Fields[iField].Status;
            break;
        }
    }
    return FieldIndex;
}
function PageHasError() {
    var hasError = false;
    for (var iField = 0; iField < Fields.length; iField++) {
        if (Fields[iField].ErrorTitle != null && Fields[iField].ErrorTitle != "" && Fields[iField].Status) {
            hasError = true;
            break;
        }
    }
    return hasError;
}
function getFieldIndex(FieldID) {
    var FieldIndex = -1;
    for (var iField = 0; iField < Fields.length; iField++) {
        if (FieldID == Fields[iField].ID) {
            FieldIndex = iField;
            break;
        }
    }
    return FieldIndex;
}
var Fields = [];
function FieldInfo() {
    this.ID;
    this.Status;
    this.ErrorTitle;
    this.ErrorMessage;
}
function ValidateConfirmEmailAddress(box) {
    var FieldID = getFieldIndex(em.id);
    if (FieldID == -1) {
        hideError();
        return;
    }
    if (em1 == null)
        return;
    if (em1.value.length == 0) {
        resetError(em1)
        return;
    }
    if (em.value.toLowerCase() == em1.value.toLowerCase()) {
        resetError(em)
        resetError(em1);
    }
    else {
        Fields[FieldID].Status = true;
        box.style.color = "red";
        Fields[FieldID].ErrorTitle = "Email adresses do not match.";
        Fields[FieldID].ErrorMessage = "Please ensure that your email addresses match.";

        FieldID = getFieldIndex(em1.id);
        if (FieldID == -1) {
            AddField(em1);
            FieldID = getFieldIndex(em1.id);
        }
        Fields[FieldID].Status = true;
        box.style.color = "red";
        Fields[FieldID].ErrorTitle = "Email adresses do not match.";
        Fields[FieldID].ErrorMessage = "Please ensure that your email addresses match.";

        getError(box);

    }
}
function getError(sender) {
    var FieldID = getFieldIndex(sender.id);
    if (FieldID > -1) {
        if (Fields[FieldID].Status) {
            if (Fields[FieldID].ErrorTitle != "" && Fields[FieldID].ErrorMessage != "")
                showError(Fields[FieldID]);
        }
        else {
            hideError();
        }
        return;
    }
    hideError();
}
function showError(Field) {
    if (Field.ErrorTitle != null) {
        var ErrorHolder = document.getElementById("ErrorIndicator");
        var ErrorTitle = document.getElementById("ErrorTitle");
        var ErrorMessage = document.getElementById("ErrorMessage");
        if (ErrorHolder != null) {
            ErrorTitle.innerHTML = Field.ErrorTitle;
            ErrorMessage.innerHTML = Field.ErrorMessage;
            ErrorHolder.className = "ErrorIndicator";
        }
    }
}
function hideError() {
    var ErrorMessage = document.getElementById("ErrorIndicator");
    if (ErrorMessage != null)
        ErrorMessage.className = "HiddenInfo";
}
function EnableLoginButton() {
    if (em != null && em.value.length > 5 && isEmailAddr(em.value) && ps.value.length > 5) {
        return true;
    }
    return false;
}
function EnableSignUpButton() {
    if (em != null && em.value.length > 5 && isEmailAddr(em.value)
        && (em1 != null ? em.value == em1.value : true)
        && ps.value.length > 5 && ps.value == ps2.value
        && fn.value.length > 0 && ln.value.length > 0
        && (GetAgeInFullYears() >= 13)
        && cba.checked == true) {
        if (rc1 == null)
            rc1 = document.getElementById('recaptcha_response_field');
        if (rc1 != null)
            return (rc1.value != "")
        else
            return true;
    }
    return false;
}

function attachRecaptchaListener(tabIndex) {
    if (rc1 == null)
        rc1 = document.getElementById('recaptcha_response_field');
    var RCFocus = function() { ShowNoodle(document.getElementById('recaptcha_div')); };
    if (rc1 != null) {
        if (rc1.addEventListener) {
            rc1.addEventListener("blur", CheckSignUpButton, false);
            rc1.addEventListener("keyup", CheckSignUpButton, false);
            rc1.addEventListener("focus", RCFocus, false);
        }
        else if (rc1.attachEvent) {
            rc1.attachEvent("onblur", CheckSignUpButton);
            rc1.attachEvent("onkeyup", CheckSignUpButton);
            rc1.attachEvent("onfocus", RCFocus);
        }
        else {
            rc1.onblur = CheckSignUpButton;
            rc1.onkeyup = CheckSignUpButton;
            rc1.onfocus = RCFocus;
        }
        rc1.tabIndex = (tabIndex != null ? tabIndex : "8");
    }
}

function ValidatePasswords(sender) {

    var FieldIndex = getFieldIndex(sender.id);
    var blError = false;
    if (FieldIndex > -1) {
        var thisErrorMsg = "HINT: Make your password more secure. - Use letters and numbers - Use special characters (e.g., @) - Mix lower and uppercase";
        if (Fields[FieldIndex].Status || (!Fields[FieldIndex].Status && Fields[FieldIndex].ErrorMessage != thisErrorMsg)) {
            if (SetPWDStrength(sender) == "weak" || SetPWDStrength(sender) == "medium") {
                sender.style.color = "red";
                Fields[FieldIndex].Status = true;
                Fields[FieldIndex].ErrorTitle = "Please check your password.";
                Fields[FieldIndex].ErrorMessage = thisErrorMsg;
                blError = true;
            }
            else {
                if (CheckMatchingPassword(sender)) {
                    resetError(sender);
                }
                else {
                    blError = true;
                }
            }
        }
        getError(sender);
    }
    return !blError;
}
function CheckMatchingPassword(sender) {

    var FieldIndex = getFieldIndex(ps.id);
    var FieldIndex1 = getFieldIndex(ps2.id);
    var blError = false;
    if (ps.value.length == 0)
        resetError(ps);
    if (ps.value.length == 0)
        resetError(ps2);
    if (ps.value == ps2.value && ps.value.length > 5) {
        ps.style.color = "#363636";
        ps2.style.color = "#363636";
        resetError(ps);
        resetError(ps2);
    }
    else {
        if (ps.value != ps2.value) {
            var FieldIndex = getFieldIndex(ps.id);
            var FieldIndex1 = getFieldIndex(ps2.id);
            if (FieldIndex > -1 && FieldIndex1 > -1) {
                sender.style.color = "red";
                Fields[FieldIndex].Status = true;
                Fields[FieldIndex].ErrorTitle = "Please check your password.";
                Fields[FieldIndex].ErrorMessage = "Your passwords do not match. Please try again.";
                FieldIndex = getFieldIndex(ps2);
                Fields[FieldIndex1].Status = true;
                Fields[FieldIndex1].ErrorTitle = "Please check your password.";
                Fields[FieldIndex1].ErrorMessage = "Your passwords do not match. Please try again.";
                blError = true;
                getError(sender);
            }
        }
    }
    return !blError;
}

function GetAgeInFullYears() {
    var age = 0;

    var today = new Date();
    var year = today.getFullYear();
    var month = today.getMonth();
    var day = today.getDate();

    var pyear = parseInt(birthdayYear.value);
    var pmonth = parseInt(birthdayMonth.value) - 1;
    var pday = parseInt(birthdayDay.value);

    if (month < pmonth) {
        age = year - pyear - 1;
    }
    else if (month > pmonth) {
        age = year - pyear;
    }
    else if (month == pmonth) {
        if (day < pday) {
            age = year - pyear - 1;
        }
        else if (day >= pday) {
            age = year - pyear;
        }
    }
    else if (day == pday) {
        age = year - pyear;
    }

    return age;
}

function ValidateBirthday(sender) {

    var FieldIndex = getFieldIndex(sender.id);
    if (birthdayMonth.value.length == 0)
        resetError(birthdayMonth);
    if (birthdayDay.value.length == 0)
        resetError(birthdayDay);
    if (birthdayYear.value.length == 0)
        resetError(birthdayYear);
    var blError = false;

    if (FieldIndex > -1) {
        var thisErrorMsg = "HINT: Please select your birthday.";


        if (GetAgeInFullYears() >= 13) {
            birthdayMonth.style.color = "#363636";
            birthdayDay.style.color = "#363636";
            birthdayYear.style.color = "#363636";
            resetError(birthdayMonth);
            resetError(birthdayDay);
            resetError(birthdayYear);
        }
        else {
            var FieldIndex1 = getFieldIndex(birthdayMonth.id);
            var FieldIndex2 = getFieldIndex(birthdayDay.id);
            var FieldIndex3 = getFieldIndex(birthdayYear.id);
            if (FieldIndex1 > -1 && FieldIndex2 > -1 && FieldIndex3 > -1) {
                //
                birthdayMonth.style.color = "red";
                Fields[FieldIndex1].Status = true;
                Fields[FieldIndex1].ErrorTitle = "Please enter correct age.";
                Fields[FieldIndex1].ErrorMessage = "You must be at least 13 years or older.";
                //
                birthdayDay.style.color = "red";
                Fields[FieldIndex2].Status = true;
                Fields[FieldIndex2].ErrorTitle = "Please enter correct age.";
                Fields[FieldIndex2].ErrorMessage = "You must be at least 13 years or older.";
                //
                birthdayYear.style.color = "red";
                Fields[FieldIndex3].Status = true;
                Fields[FieldIndex3].ErrorTitle = "Please enter correct age.";
                Fields[FieldIndex3].ErrorMessage = "You must be at least 13 years or older.";

                blError = true;
                getError(sender);
            }
        }
    }
    return !blError;
}
function EnableChangePasswordButton(sender) {
    var blError = true;
    if (sender != null) {

        if (ops != null && ops == sender) {
            blError = ops.value.length < 5;
        }
        else {
            blError = ValidatePasswords(sender);
        }
    }
    if (blError && ps.value.length > 5 && ps2.value.length > 5) {
        blError = CheckMatchingPassword(sender);
    }
    else {
        blError = false;
    }
    if (blError) {
        if (ops != null)
            blError = ops.value.length > 5;
    }
    if (blError) {
        blError = !PageHasError();
    }
    return blError;
}
function EnableForgotPasswordButton() {
    if (fem != null && fem.value.length > 5 && isEmailAddr(fem.value)) {
        return true;
    }
    return false;
}
var btLogindisabled = false;
function CheckLoginButton(imgSrc) {
    if (btLogin == null)
        btLogin = document.getElementById('ibtLogin');
    //button, blActive, currentlyActive, mouseover, mouseout, click
    btLogindisabled = ActivateButton(btLogin, EnableLoginButton(), btLogindisabled, loginButtonOver, loginButtonOut, login);

    if (imgSrc == null)
        imgSrc = 'log_Me_InBtn';
    if (btLogindisabled) {

        btLogin.src = 'images/' + imgSrc + '.png';
        btLogin.style.cursor = 'pointer';
        while (btLogin.disabled)
            btLogin.disabled = false;
        return;
    }
    if (!btLogindisabled) {
        btLogin.src = 'images/' + imgSrc + '_inactive.png';
        btLogin.style.cursor = 'default';
        if (!btLogin.disabled)
            btLogin.disabled = true;
    }
}
function CheckHomePageLoginButton() {
    CheckLoginButton('home14_loginbutton');
}
function CheckSignUpButton() {
    if (btLogin == null)
        btLogin = document.getElementById('ibtLogin');
    //button, blActive, currentlyActive, mouseover, mouseout, click
    btLogindisabled = ActivateButton(btLogin, EnableSignUpButton(), btLogindisabled, loginButtonOver, loginButtonOut, login);

    if (btLogindisabled) {
        btLogin.src = 'images/join_NowBtn.png';
        btLogin.style.cursor = 'pointer';
        while (btLogin.disabled)
            btLogin.disabled = false;
        return;
    }
    if (!btLogindisabled) {
        btLogin.src = 'images/join_NowBtn_inactive.png';
        btLogin.style.cursor = 'default';
        if (!btLogin.disabled)
            btLogin.disabled = true;
    }
}
function CheckForgotPasswordButton() {
    if (btLogin == null)
        btLogin = document.getElementById(btForgotID);
    //button, blActive, currentlyActive, mouseover, mouseout, click
    btLogindisabled = ActivateButton(btLogin, EnableForgotPasswordButton(), btLogindisabled, loginButtonOver, loginButtonOut, login);

    if (btLogindisabled) {
        btLogin.src = 'images/sendBtn.png';
        btLogin.style.cursor = 'pointer';
        while (btLogin.disabled)
            btLogin.disabled = false;
        return;
    }
    if (!btLogindisabled) {
        btLogin.src = 'images/sendBtn_inactive.png';
        btLogin.style.cursor = 'default';
        if (!btLogin.disabled)
            btLogin.disabled = true;
    }
}
function CheckChangePasswordButton(sender) {
    if (btLogin == null)
        btLogin = document.getElementById('ibtLogin');
    //button, blActive, currentlyActive, mouseover, mouseout, click
    btLogindisabled = ActivateButton(btLogin, EnableChangePasswordButton(sender), btLogindisabled, loginButtonOver, loginButtonOut, login);

    if (btLogindisabled) {
        btLogin.src = 'images/saveBtn.png';
        btLogin.style.cursor = 'pointer';
        while (btLogin.disabled)
            btLogin.disabled = false;
        return;
    }
    if (!btLogindisabled) {
        btLogin.src = 'images/saveBtn_inactive.png';
        btLogin.style.cursor = 'default';
        if (!btLogin.disabled)
            btLogin.disabled = true;
    }
}
var t;
function loadCheckLoginButton() {
    t = setTimeout("CheckLoginButton()", 500);
}
function loadCheckChangePasswordButton() {
    t = setTimeout("CheckChangePasswordButton()", 500);
}
function loadCheckSignUpButton() {
    t = setTimeout("CheckSignUpButton()", 500);
}
function CheckLogin(e) {
    oEvent = (window.event) ? window.event : e;
    if (btLogin.disabled)
        return false;
    switch (oEvent.keyCode) {
        case 13: //enter
            document.forms[0].submit();
            e.cancelBubble = true;
            e.returnValue = false;
            e.cancel = true;
            return false;
            break;
        default:
            return false;
            break;
    }
}

function FindParent(cbx, pe) {
    var te = cbx.parentNode;
    while (!(te == null)) {
        try {
            if (te.tagName.toUpperCase() == pe) {
                break;
            }
            te = te.parentNode;
        }
        catch (ex) {
            alert('exception');
            return null;
        }
    }
    return te;
}
function getClientBounds() {
    /// <summary>
    /// Gets the width and height of the browser client window (excluding scrollbars)
    /// </summary>
    /// <returns type="Sys.UI.Bounds">
    /// Browser's client width and height
    /// </returns>

    var clientWidth;
    var clientHeight;
    switch (Sys.Browser.agent) {
        case Sys.Browser.InternetExplorer:
            clientWidth = document.documentElement.clientWidth;
            clientHeight = document.documentElement.clientHeight;
            break;
        case Sys.Browser.Safari:
            clientWidth = window.innerWidth;
            clientHeight = window.innerHeight;
            break;
        case Sys.Browser.Opera:
            clientWidth = Math.min(window.innerWidth, document.body.clientWidth);
            clientHeight = Math.min(window.innerHeight, document.body.clientHeight);
            break;
        default:  // Sys.Browser.Firefox, etc.
            clientWidth = Math.min(window.innerWidth, document.documentElement.clientWidth);
            clientHeight = Math.min(window.innerHeight, document.documentElement.clientHeight);
            break;
    }
    return new Sys.UI.Bounds(0, 0, clientWidth, clientHeight);
}

/**
Truncate the text in a display:inline tag, and append ellipses to it if truncated

@param tag :HtmlElement			The tag to truncate the text of
@param maxWidth :Number			The size in pixels to resize to
@param options :Object			Optional parameters passed as name/value pairs:
	text	:String				The text to put into the tag; uses innerHTML if not passed.
	stripHtml :Boolean			Whether to strip HTML from the text passed in.
	forceResizing :Boolean		Use when a tag refuses to truncate properly (usually exhibited by being
								truncated down to 1 character). Moves the tag out of its container to
								ensure it isn't constrained by its parent, and sets the display directly
								to inline to ensure .offsetWidth works properly (display: block causes
								offsetWidth to always return the offsetWidth of its container).
*/
function truncateText(tag, maxWidth, options) {
	var options = options || {};
	var text = options.text || tag.innerHTML;
	if (options.stripHtml)
		text = text.replace(/<.+>/g, ' ');

	if (options.forceResizing) {
		var display = tag.style.display;
		tag.style.display = 'inline';

		var parentNode = tag.parentNode;
		var placeHolder = document.createElement('div');
		parentNode.insertBefore(placeHolder, tag);
		document.body.appendChild(tag);
	}
    
    tag.innerHTML = text.substr(0, 1);
    var lineHeight = tag.offsetHeight;
    tag.innerHTML = text;

    var truncated = tag.offsetWidth > maxWidth || tag.offsetHeight > lineHeight;

    if (truncated) {
    	// Use a Binary Search-like approach to find the right number of
    	// characters
    	// Simple while loop: 557ms on IE8 with 20 items (584 chars), 154ms on Chrome
    	// Binary search: 20ms on IE8, 1ms on Chrome
        truncate_R(tag, text, 0, text.length, maxWidth, lineHeight);

        tag.innerHTML += "...";
    }

    if (tag.className !="MessageFirstLine")   //this is a fix for remove tooltip for message only
        tag.title = text;

    if (options.forceResizing) {
    	tag.style.display = display;

    	if (parentNode) {
    		parentNode.insertBefore(tag, placeHolder);
    		parentNode.removeChild(placeHolder);
    		placeHolder = null;
    	}
    }
    
    return truncated;
}

function truncate_R(tag, text, minLength, maxLength, maxWidth, maxHeight) {
	var range = maxLength - minLength;
	
	if (range < 4) {
		for (var l = maxLength - 1; (tag.offsetWidth > maxWidth || tag.offsetHeight > maxHeight) && l > minLength; l--)
			tag.innerHTML = text.substr(0, l);

		return;
	}

	var half = Math.round(range / 2) + minLength;
	tag.innerHTML = text.substr(0, half);
	
	if (tag.offsetWidth > maxWidth || tag.offsetHeight > maxHeight)
	    truncate_R(tag, text, minLength, half, maxWidth, maxHeight);
	else
	    truncate_R(tag, text, half, maxLength, maxWidth, maxHeight);
}

/**
Truncate the text in a div tag drawn to look like a textbox, and append
ellipses to it if truncated
*/
function TruncateTextBox(objName, oMaxWidth, oMaxHeight, showTitle) {
    var Truncated = objName.offsetWidth > oMaxWidth || (oMaxHeight != null && objName.offsetHeight > oMaxHeight);
    var OrigVal = objName.innerHTML;
    if (showTitle == null)
        showTitle = false;
    while (objName.offsetWidth > oMaxWidth || (oMaxHeight != null && objName.offsetHeight > oMaxHeight)) {
        //        if (objName.innerHTML.substring(objName.innerHTML.length - 1) == ">") {
        //            objName.innerText = objName.innerText.substring(0, objName.innerText.length - 1);
        //        }
        if (is.ie) {
            if (objName.innerText.lastIndexOf(' ') < objName.innerText.length - 10) {
                objName.innerText = objName.innerText.substring(0, objName.innerText.length - 10);
            }
            else {
                objName.innerText = objName.innerText.substring(0, objName.innerText.lastIndexOf(' '));
            }
        }
        else {
            if (objName.textContent.lastIndexOf(' ') < objName.textContent.length - 10) {
                objName.textContent = objName.textContent.substring(0, objName.textContent.length - 10);
            }
            else {
                objName.textContent = objName.textContent.substring(0, objName.textContent.lastIndexOf(' '));
            }
        }
    }
    if (Truncated) {
        if (is.ie) {
            objName.innerText += "...";
            if (objName.innerText.lastIndexOf(' ') < objName.innerText.length - 10) {
                objName.innerText = objName.innerText.substring(0, objName.innerText.length - 10);
            }
            else {
                objName.innerText = objName.innerText.substring(0, objName.innerText.lastIndexOf(' '));
            }
            objName.innerText += "...";
        }
        else {
            objName.textContent += "...";
            if (objName.textContent.lastIndexOf(' ') < objName.textContent.length - 10) {
                objName.textContent = objName.textContent.substring(0, objName.textContent.length - 10);
            }
            else {
                objName.textContent = objName.textContent.substring(0, objName.textContent.lastIndexOf(' '));
            }
            objName.textContent += "...";
        }
    }
    if (showTitle)
        objName.title = OrigVal;
}

function truncateTextHeight(tag, maxHeight, options) {
	var options = options || {};
	var text = options.text || tag.innerHTML;
	if (options.stripHtml)
		text = text.replace(/<.+>/g, ' ');

	tag.innerHTML = text;

	var truncated = tag.offsetHeight > maxHeight;
	setTimeout(function() {
		alert(tag.innerHTML.length + ',' + tag.offsetHeight);
	}, 1);

	if (truncated) {
		truncateTextHeight_R(tag, text, 0, text.length, maxHeight);
		tag.innerHTML += '...';
	}

	return truncated;
}

function truncateTextHeight_R(tag, text, minLength, maxLength, maxHeight) {
	var range = maxLength - minLength;

	if (range < 8) {
		tag.innerHTML = text.substr(0, minLength - 6);
		return;
	}

	var half = Math.round(range / 2) + minLength;
	tag.innerHTML = text.substr(0, half);
	
	if (tag.offsetHeight > maxHeight)
		truncateTextHeight_R(tag, text, minLength, half, maxHeight);
	else
		truncateTextHeight_R(tag, text, half, maxLength, maxHeight);
}

function FormatDateTime() {
    this.Month;
    this.Day;
    this.Year;
    this.Hour;
    this.Min;
    this.Second;
    this.AMPM;
}

function getClockTime(oTime) {
    var hour = oTime.getHours();
    var minute = oTime.getMinutes();
    var ap = "AM";
    if (hour > 11) { ap = "PM"; }
    if (hour > 12) { hour = hour - 12; }
    if (hour == 0) { hour = 12; }
    if (hour < 10) { hour = "0" + hour; }
    if (minute < 10) { minute = "0" + minute; }
    return hour + ':' + minute + " " + ap;
}

function getScheduleDateTime(oDateTime) {
    var ScheduleDateTimeNow;
    var CurrentTime = new FormatDateTime()
    if (oDateTime != null)
        ScheduleDateTimeNow = new Date(Date.parse(oDateTime));
    else {
        ScheduleDateTimeNow = new Date();
    }
    CurrentTime.Month = ScheduleDateTimeNow.getMonth() + 1;
    CurrentTime.Day = ScheduleDateTimeNow.getDate();
    CurrentTime.Year = ScheduleDateTimeNow.getFullYear();
    CurrentTime.Hour = ScheduleDateTimeNow.getHours();
    CurrentTime.Min = ScheduleDateTimeNow.getMinutes();
    if (CurrentTime.Hour > 11) { CurrentTime.AMPM = "PM"; } else { CurrentTime.AMPM = "AM"; }
    if (CurrentTime.Hour > 12) { CurrentTime.Hour = CurrentTime.Hour - 12; }
    if (CurrentTime.Hour == 0) { CurrentTime.Hour = 12; }


    if (CurrentTime.Month < 10)
        CurrentTime.Month = "0" + CurrentTime.Month;
    if (CurrentTime.Day < 10)
        CurrentTime.Day = "0" + CurrentTime.Day;
    if (CurrentTime.Hour < 10)
        CurrentTime.Hour = "0" + CurrentTime.Hour;
    if (CurrentTime.Min < 10)
        CurrentTime.Min = "0" + CurrentTime.Min;

    return CurrentTime;
}
function SetPWDStrength(box) {
    var pwdStrength = '';
    if (box != null) {
        if (box.value) {
            var pwd = box.value;
            var pwdl = pwd.length;
            var nb = NumBlanks(pwd);
            if (pwdl == 0 || nb > 0) {
                pwdStrength = 'none';
            }
            else {
                if (pwdl < 6) {
                    pwdStrength = 'weak';
                }
            }
            if (pwdStrength == '') {
                pwdStrength = 'weak';
                var nCaps = NumCaps(pwd);
                var nLC = NumLC(pwd);
                var nDigits = NumDigits(pwd);
                var nSpecial = pwdl - nCaps - nLC - nDigits;
                if (nSpecial < 0) nSpecial = 0;
                if (nDigits == pwdl || nCaps == pwdl || nLC == pwdl) {
                    pwdStrength = 'medium';
                }
                if (nCaps > 0 && nLC > 0)
                    pwdStrength = 'strong';
                if (nDigits > 0 && (nLC + nCaps) > 0)
                    pwdStrength = 'strong';
                if (nSpecial > 0 && (nCaps + nDigits + nLC) > 0)
                    pwdStrength = 'strong';
                if (nDigits > 0 && nCaps > 0 && nLC > 0 && ((nDigits + nCaps + nLC) < pwdl))
                    pwdStrength = 'best';
            }
        }
    }
    return pwdStrength;
}
function NumDigits(s) {
    var rv = 0;
    if (typeof s == "string") {
        var l = s.length;
        var x = 0;
        while (x < l) {
            var c = s.charCodeAt(x++);
            if (c >= 48 && c <= 57)
                rv++;
        }
    }
    return rv;
}
function NumCaps(s) {
    var rv = 0;
    if (typeof s == "string") {
        var l = s.length;
        var x = 0;
        while (x < l) {
            var c = s.charCodeAt(x++);
            if (c >= 65 && c <= 90)
                rv++;
        }
    }
    return rv;
}
function NumLC(s) {
    var rv = 0;
    if (typeof s == "string") {
        var l = s.length;
        var x = 0;
        while (x < l) {
            var c = s.charCodeAt(x++);
            if (c >= 97 && c <= 122)
                rv++;
        }
    }
    return rv;
}
function NumBlanks(s) {
    // REALLY NUMBER OF JUNK CHARACTERS, either blank, control or non-ascii.
    var rv = 0;
    if (typeof s == "string") {
        var l = s.length;
        var x = 0;
        while (x < l) {
            var c = s.charCodeAt(x++);
            if (c <= 32 || c > 126)
                rv++;
        }
    }
    return rv;
}
// Removes leading whitespaces
function LTrim(value) {
    var re = /\s*((\S+\s*)*)/;
    return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim(value) {
    var re = /((\s*\S+)*)\s*/;
    return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim(value) {
    return LTrim(RTrim(value));
}


function TruncateName(text, maxChars) {
    if (text == null)
        return "";
    else if (text.length > maxChars) {
        text = text.substring(0, eval(maxChars - 3)) + "...";
    }
    return text;
}

function removeChildrenFromNode(node) {
    if ((node == undefined) || (node == null)) {
        return;
    }

    var len = node.childNodes.length;

    while (node.hasChildNodes()) {
        node.removeChild(node.firstChild);
    }
}

function CreateElement(contentRef) {
    var contentObj;
    if (typeof contentRef == "string") {
        if (contentRef.indexOf(' ') > -1) {
            contentObj = document.createElement('div');
            contentObj.id = "Dialog" + DialogInfoList.length;
            contentObj.innerHTML = contentRef;
        }
        else {
            contentObj = document.getElementById(contentRef);
        }
    }

    if (typeof contentRef == "object") {
        contentObj = contentRef;
    }

    return contentObj;
}


var blCBYesAttached = false;
var blCBNoAttached = false;
var blCBCloseAttached = false;
var lbLightBoxVisible = false;
var blActiveLBListener = false;
var ActiveCallBack;
var DialogInfoList = [];
function DialogInfo() {
    this.OrginID;
    this.ID;
    this.ContentID;
    this.active;
}
function CheckDialogInfoList(objID) {
    for (var iItems = 0; iItems < DialogInfoList.length; iItems++) {
        if (DialogInfoList[iItems].ID == objID) {
            DialogInfoList.active = true;
            return DialogInfoList[iItems].ContentID;
        }
    }
}
function AddToDialogInfoList(title, obj) {
    var retVal = obj;
    for (var iItems = 0; iItems < DialogInfoList.length; iItems++) {
        if (DialogInfoList[iItems].ID == title) {
            DialogInfoList[iItems].active = true;
            return DialogInfoList[iItems];
        }
    }
    var newDialogObj = new DialogInfo()
    newDialogObj.ID = title;
    newDialogObj.ContentID = obj.id;
    if (obj.parentNode != null)
        newDialogObj.OrginID = obj.parentNode.id;
    newDialogObj.active = true;
    DialogInfoList.push(newDialogObj);
    return retVal;
}

function calculateCenter() {

    // First, determine how much the visitor has scrolled 
    var scrolledX, scrolledY;

    if (self.pageYOffset) {
        scrolledX = self.pageXOffset;
        scrolledY = self.pageYOffset;
    } else if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) {
        scrolledX = document.documentElement.scrollLeft;
        scrolledY = document.documentElement.scrollTop;
    } else if (document.body) {
        scrolledX = document.body.scrollLeft;
        scrolledY = document.body.scrollTop;
    }

    // Next, determine the coordinates of the center of browser's window 
    var centerX, centerY;

    if (self.innerHeight) {
        centerX = self.innerWidth;
        centerY = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        centerX = document.documentElement.clientWidth;
        centerY = document.documentElement.clientHeight;
    } else if (document.body) {
        centerX = document.body.clientWidth;
        centerY = document.body.clientHeight;
    }

    LightBoxHolderleft = scrolledX + (centerX / 2);
    LightBoxHoldertop = scrolledY + (centerY / 2);

    return [scrolledY, scrolledX, centerY, centerX];
}

function centerDialog(object) {
    var dimensions = calculateCenter();
    if (object.offsetHeight <= dimensions[2]) {
        object.style.top = (LightBoxHoldertop - (object.offsetHeight / 2)) + "px";
    } else {
        object.style.top = dimensions[0] + "px";
    }
    if (object.offsetWidth <= dimensions[3]) {
        object.style.left = (LightBoxHolderleft - (object.offsetWidth / 2)) + "px";
    } else {
        object.style.left = dimensions[1];
    }
}

function ShowProgress() {
    var contentObj = document.getElementById("ProgressDivContainer");

    if (contentObj == null) {
        contentObj = document.createElement("div");
        contentObj.id = "ProgressDivContainer";
        contentObj.style.position = "absolute";
        contentObj.style.zIndex = 999;
        contentObj.style.width = "80px";
        var indicator = document.createElement("div");
        indicator.className = "ajax-loading-text";
        contentObj.appendChild(indicator);
        document.getElementById('EndOFPage').appendChild(contentObj);
    }
    centerDialog(contentObj);
    DisableBG();
}

function HideProgress() {
    var contentObj = document.getElementById("ProgressDivContainer");
    contentObj.style.display = "none";

    ActivateBG();
}

/**
Attaches events to a Textbox (html input with no type set) that cause a function to
be called if the user clicks in, or presses spacebar after tabbing in (tabbing in itself does
nothing).

User can tab in and out of the field, but can't type directly into it.
Works in IE, Firefox, Chrome, and Safari.
*/
function addTextboxHandler(textboxId, fn) {
	var div = document.getElementById(textboxId);
	div.onmousedown = function(ev) {
		fn();
	}
	div.onkeydown = function(ev) {
		var ev = ev || event;
		var key = ev.keyCode || ev.which;
		if (key == 32)
			fn();
		if (key != 9)
			return false;
	}
}

function ShowDialog(title, contentRef, height, width, dialogtype, callBack) {
    var contentObj
    if (contentRef != null) {
        contentObj = CreateElement(contentRef);
        AddToDialogInfoList(title, contentObj);
    }
    else {
        contentObj = document.getElementById(CheckDialogInfoList(title));
    }
    
    var popDialog = document.getElementById("MyWindow");
    popDialog.className = 'PopWindowHolder';
    centerDialog(popDialog);
    //popDialog.style.top = LightBoxHoldertop;
    //popDialog.style.left = LightBoxHolderleft;

    DisableBG();

    if (!lbLightBoxVisible) {
        lbLightBoxVisible = true;
        popDialog.style.height = height + "px";
        popDialog.style.width = width + "px";
        var popDialogTitle = document.getElementById("dialogTitleText");
        popDialogTitle.innerHTML = title;
        var popTitleBar = document.getElementById("dialogTitleCenterImage");
        popTitleBar.style.width = width - 14 + "px";
        var popFooterBar = document.getElementById("footerBackground");
        popFooterBar.style.width = width - 20 + "px";
        var winContent = document.getElementById("content");


        if (contentObj != null) {
            winContent.appendChild(contentObj);
        }

        //        if ((is.ie6 || is.ie7 || is.ie8) 
        //            && (!((typeof contentRef == "string") && (contentRef.indexOf(' ') > -1))))
        //        {
        //            winContent.style.width = width + "px";
        //        }
        //        else {
        //            winContent.style.width = width - 42 + "px";
        //        }

        winContent.style.height = height - (44 + (dialogtype != null && dialogtype != "" ? 22 : 0) + 10) + "px";
        winContent.style.width = width - 42 + "px";

        popDialog.style.height = "auto";

        centerDialog(popDialog);

        var CancelLink = document.getElementById("CancelLink");
        var OkBtn = document.getElementById("OkBtn");
        var SaveBtn = document.getElementById("SaveBtn");
        var YesBtn = document.getElementById("YesBtn");
        var BtnWindow = document.getElementById("buttons");
        BtnWindow.style.width = width - 42 + "px";
        if (dialogtype == null)
            dialogtype = "";
        switch (dialogtype.toLowerCase()) {
            case "ok":
                CancelLink.style.display = "none";
                BtnWindow.style.display = "block";
                OkBtn.style.display = "inline-block";
                SaveBtn.style.display = "none";
                YesBtn.style.display = "none";
                break;
            case "okcancel":
                CancelLink.style.display = "block";
                BtnWindow.style.display = "block";
                OkBtn.style.display = "inline-block";
                SaveBtn.style.display = "none";
                YesBtn.style.display = "none";
                break;
            case "save":
                CancelLink.style.display = "block";
                BtnWindow.style.display = "block";
                OkBtn.style.display = "none";
                SaveBtn.style.display = "inline-block";
                YesBtn.style.display = "none";
                break;
            case "yes":
                CancelLink.style.display = "block";
                BtnWindow.style.display = "block";
                OkBtn.style.display = "none";
                SaveBtn.style.display = "none";
                YesBtn.style.display = "inline-block";
                break;
            default:
                BtnWindow.style.display = "none";
                break;
        }

        if (callBack != null) {
            var CommandYes = document.getElementById("YesBtn");
            ActiveCallBack = callBack;
            blCBYesAttached = ActivateButton(YesBtn, true, blCBYesAttached, null, null, callBack); //closeBtn
        }

        if (!blActiveLBListener) {
            AttachLBListener();
            blActiveLBListener = true;
        }
    }
}
function YesClicked() {
    if (ActiveCallBack != null) {
        ActiveCallBack();
    }
    HideDialog();
}
function CancelClicked() {
    HideDialog();
}
function HideDialog() {
    var popDialog = document.getElementById("MyWindow");

    for (var iItems = 0; iItems < DialogInfoList.length; iItems++) {
        if (DialogInfoList[iItems].active == true) {
            DialogInfoList[iItems].active = false;
            if (DialogInfoList[iItems].OrginID != null) {
                OrginDialog = document.getElementById(DialogInfoList[iItems].OrginID);
                OrginDialog.appendChild(document.getElementById(DialogInfoList[iItems].ContentID));
            }
            else {
                OrginDialog = document.getElementById(DialogInfoList[iItems].ContentID);
                removeChildrenFromNode(OrginDialog);
            }
            break;
        }
    }
    popDialog.className = "HiddenInfo";
    if (lbLightBoxVisible) {
        lbLightBoxVisible = false;
        popDialog.className = "HiddenInfo";
        ActivateBG();
    }

    if (blCBYesAttached) {
        var CommandYes = document.getElementById("YesBtn");
        blCBYesAttached = ActivateButton(CommandYes, false, blCBYesAttached, null, null, ActiveCallBack);
        ActiveCallBack = null;
    }

}

function AttachLBListener() {
    if (is.ie) {
        document.body.onresize = function() {
            if (BGDisabled) {
                if (page_width < wrapperWidth) {
                    LightBoxHolderleft = page_width * .25;
                    page_width = wrapperWidth;
                }
                else {
                    LightBoxHolderleft = '40%';
                }
            }
            if (lbLightBoxVisible) {
                ShowDialog();
            }
        }
        window.onscroll = function() {
            if (lbLightBoxVisible) {
                // ShowDialog();
            }
        }
    }
    else {
        window.onresize = function() {
            if (BGDisabled) {
                if (page_width < wrapperWidth) {
                    LightBoxHolderleft = page_width * .25;
                    page_width = wrapperWidth;
                }
                else {
                    LightBoxHolderleft = '40%';
                }
            }
            if (lbLightBoxVisible) {
                ShowDialog();
            }
        }
        window.onscroll = function() {
            if (lbLightBoxVisible) {
                // ShowDialog();
            }
        }

    }
}

function ShowCaptchaError() {
    var rc = document.getElementById("recaptcha_div");
    AddField(rc);
    var Field = getFieldIndex(rc.id);
    Fields[Field].ErrorTitle = "Recaptcha Error";
    Fields[Field].ErrorMessage = "You did not enter the Recaptcha information correctly.";
    ShowNoodle(rc);
}

function GoToPreviousPage() {
    history.go(-1);
}

function ProcessClick(sender, callback, labelName, className, disableOnly) {
    if (sender.style.visibility == "hidden") {
        return false;
    }
    if ((!disableOnly) && (sender.style.display != "none")) {
        var l = document.getElementById("dvProcessing");
        if (l == null) {
            l = document.createElement("label");
            l.id = "dvProcessing";
            l.innerHTML = (labelName != null ? labelName : "Processing...");
        }
        l.className = (className != null ? className : "processing");
        //
        sender.style.visibility = "hidden";
        // sender.setAttribute("disabled", "disabled");

        if (document.getElementById(sender.id).parentNode != null) {
            document.getElementById(sender.id).parentNode.appendChild(l);
            var position = findPos(sender);
            l.style.top = position[1] + Math.max(0, ((sender.offsetHeight - l.offsetHeight) / 2)) + "px";
            l.style.left = position[0] + (0, (sender.offsetWidth - l.offsetWidth)) + "px";
            l.style.visibility = "visible";
        }

        if (callback) {
            callback();
        }
    }
    else {
        sender.setAttribute("disabled", "disabled");
        return false;
    }
}

function RemoveProcessClick(sender) {
    if (document.getElementById("dvProcessing") != null && document.getElementById("dvProcessing").parentNode != null) {
        document.getElementById("dvProcessing").parentNode.removeChild(document.getElementById("dvProcessing"));
    }
    sender.style.visibility = "visible";
}


// Major version of Flash required
var requiredMajorVersion = 9;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;



function goToFlash() {
    window.location.href = FlashURL;
}
var FlashURL = "http://get.adobe.com/flashplayer/";

function showFlashNotInstalled() {
    //    var FlashErrorHolder = document.getElementById("dynHookup");
    //    var ErrorMessage = document.createElement("DIV");
    //    ErrorMessage.id = "FlashError";
    //    FlashErrorHolder.appendChild(ErrorMessage);
    //    ErrorMessage = "<b>You don't have Adobe Flash Player!</b><br><div class='dvFlashMessage'>This site makes use of Adobe Flash software. To experience it the way we intended, you nedd Adobe Flash, plug-in for your Web Browser.</div><a href='javascript:goToFlash();'><div class='dvgetflash'>Click here to:<br><img src='/images/get_flash_postcards.gif' /></div><\a>";
    //    ShowDialog("Create Release", ErrorMessage, 200, 420, "ok");
    ShowDialog("Adobe Flash Player:", "<b>You don't have Adobe Flash Player!</b><br><div class='dvFlashMessage'>This site makes use of Adobe Flash software. To experience it the way we intended, you need Adobe Flash, plug-in for your Web Browser.</div><div class='dvgetflash'><a href='" + FlashURL + "' target='_blank'>Click here to:</a><br><a href='" + FlashURL + "' target='_blank'><img src='/images/get_flash_postcards.gif' border=0 /><\a></div>", 200, 420, "ok");

}
function showGetNewVersion() {
    ShowDialog("Adobe Flash Player:", "<b>You don't have latest version of Adobe Flash Player!</b><br><br><div class='dvFlashMessage'>This site makes use of latest version of Adobe Flash software. To experience it the way we intended, you need Adobe Flash, plug-in for your Web Browser.</div><br><div class='dvgetflash'><a href='" + FlashURL + "' target='_blank'>Click here to:</a><br><a href='" + FlashURL + "' target='_blank'><img src='/images/get_flash_postcards.gif' border=0 /><\a></div>", 300, 420, "ok");
}

function CheckFlashAndVersion() {
    //    var noFlashMessage = document.getElementById("noFlashMessage");    
    //    if (!(FlashDetect.versionAtLeast(9))) {
    //        showGetNewVersion();
    //    }
    var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
    if (!hasReqestedVersion) {
        showGetNewVersion();
    }
}

function HideFlashDiv() {
    if (CurrentPageType == "CreateRelease") {
        document.getElementById("dvUploadButtonHolder").style.visibility = "hidden";
        document.getElementById("UploadImageButtonDiv").style.visibility = "hidden";
    }
    if (CurrentPageType = "EditProfile") {
        document.getElementById("UploadImageButtonDiv").style.visibility = "hidden";
    }
    if (CurrentPageType = "EditRelease") {
        document.getElementById("UploadImageButtonDiv").style.visibility = "hidden";
    }
}

function MakePopup(objLabel, oMaxWidth) {
    var Truncated = objLabel.offsetWidth > oMaxWidth; // && objLabel.offsetHeight > 24;
    var PopAnchorID = 0;
    var OrigVal = objLabel.innerHTML;
    var OrigLen = objLabel.innerHTML.length;
    while (objLabel.offsetWidth > oMaxWidth) {
        OrigLen--;
        objLabel.innerHTML = OrigVal.substring(0, OrigLen);
    }
    if (Truncated) {
        OrigLen = objLabel.innerHTML.lastIndexOf(",");
        var AllHidden = OrigLen == -1;
        if (AllHidden) {
            OrigLen = objLabel.innerHTML.indexOf("by ");
        }

        objLabel.innerHTML = OrigVal.substring(0, OrigLen);
        if (AllHidden) {
            PopupText = OrigVal.substring(OrigLen + 3, OrigVal.length - 1);
        }
        else {
            PopupText = OrigVal.substring(OrigLen + 1, OrigVal.length - 1);
        }
        var NumberOfOthers = PopupText.split(',');
        var PopAnchorName = 'PopAnchor' + PopAnchorID;
        if (AllHidden) {
            objLabel.innerHTML += "<div class='PopAnchor' id=\"" + PopAnchorName + "\"></div><a href='javascript:showOthers(\"" + PopAnchorName + "\");' onmouseover='showOthers(\"" + PopAnchorName + "\");' onmouseout='hideOthers();'>Suggested by " + NumberOfOthers.length + " judges</a>)";
        }
        else {
            objLabel.innerHTML += "<div class='PopAnchor' id=\"" + PopAnchorName + "\"></div>, <a href='javascript:showOthers(\"" + PopAnchorName + "\");' onmouseover='showOthers(\"" + PopAnchorName + "\");' onmouseout='hideOthers();'>" + NumberOfOthers.length + " Other" + (NumberOfOthers.length > 1 ? "s" : "") + "</a>)";
        }
        PopAnchorID++;
    }
}
function showOthers(obj) {
    var PopupAnchor = document.getElementById(obj);
    PopupCoords = findPos(obj);

    var Popupobj = document.getElementById('popupOtherJudges');
    if (Popupobj == null)
        Popupobj = document.createElement("div");
    PopupAnchor.appendChild(Popupobj);
    Popupobj.id = 'popupOtherJudges';
    Popupobj.className = "GenreChangePopup";
    Popupobj.innerHTML = PopupText;
}
function hideOthers() {
    var Popupobj = document.getElementById('popupOtherJudges');
    Popupobj.className = "GenreChangePopupHidden";
}

function jsonParseDate(obj) {
    var d = eval('new' + obj.replace(/\//g, ' '));
    return ((d.getMonth() + 1) + '/' + d.getDate() + '/' + d.getFullYear() + ' ' + getClockTime(d));
    // return eval('new' + obj.replace(/\//g, ' '));
};

function Select_selectOptionByText(select, text) {
	var o = select.options;
	for (var i = o.length - 1; i >= 0 && o[i].text != text; i--)
		{ }

	if (i >= 0)
		select.selectedIndex = i;

	return i;
}

/**
Filters input for only keys used in entering numbers. See comments
below for accepted key list.

Typically called from onmousekeydown on an input element.

@param ev :Event	A browser event object (any browser)
*/
function filterNumberKeys(ev) {
	switch (ev.keyCode) {
		case 8: //backspace
		case 9: //tab
		case 16: //shift
		case 17: //ctrl
		case 18: //alt
		case 37: //left
		case 39: //right
		case 46: // delete
		case 145: //numlock
		case 255: //fn
			return true;
	}

	// Numpad
	if (96 <= ev.keyCode && ev.keyCode <= 105)
		return true;

	if (/\d/.test(String.fromCharCode(ev.keyCode)))
		return true;

	return ev.returnValue = false;
}

function setDefaultText(sender) {
    if (sender.value == "") {
        if (sender.id.toLowerCase().indexOf("login") > -1) {
            sender.value = "Email Address";
        }
        else if (sender.id.toLowerCase().indexOf("pass") > -1) {
            sender.value = "Password";
        }
        RemoveField(sender);
    }
}
function clearDefaultEmailText(sender) {
    if (sender.id.toLowerCase().indexOf("login") > -1) {
        if (sender.value == "Email Address")
            sender.value = "";
    }
    else if (sender.id.toLowerCase().indexOf("pass") > -1) {
        if (sender.value == "Password")
            sender.value = "";
    }
}
function setDefaultLocationText(obj) {
    if (obj != null) {
        var szValue = obj.value.trim();
        if (szValue == "") {
            obj.value = DefaultLocationText;
        }
        isDefaultLocationText(obj);
    }
}
function clearDefaultText(obj) {
    var szValue = obj.value.trim();
    if (szValue == DefaultLocationText) {
        obj.value = "";
    }
    isDefaultLocationText(obj);
}


function isDefaultLocationText(obj) {
    var szValue = obj.value.trim();
    if (szValue == DefaultLocationText) {
        obj.className = "DefaultLocationText";
        return true;
    }
    if (szValue == '')
        return true;

    obj.className = "ProfileFormField367";
    return false;
}