// JavaScript Document
var valInt;

function showLoginBox() {
	$("#" + headerControl + "_clientLoginBox").animate({width:"395px", opacity:1},600);
	$("#passTxtLabel").show();
}

function hideLoginBox() {
	
    $("#" + headerControl + "_clientLoginBox").animate({ width: "0px", opacity: 0 }, 600, function () {
        if ($("#" + headerControl + "_txtUserName").parent().hasClass("error"))
            $("#" + headerControl + "_txtUserName").parent().removeClass("error");
			
        if ($("#" + headerControl + "_txtUserPassword").parent().hasClass("error"))
            $("#" + headerControl + "_txtUserPassword").parent().removeClass("error");
			
		if ($("#" + headerControl + "_txtUserNameEmail").parent().hasClass("error"))
            $("#" + headerControl + "_txtUserNameEmail").parent().removeClass("error");
			
        if ($("#" + headerControl + "_rememberMeBox").hasClass("checked"))
            $("#" + headerControl + "_rememberMeBox").removeClass("checked");
			
		if ($("#txtUserName_err").hasClass("forgotPass_errMsg"))
			$("#txtUserName_err").removeClass("forgotPass_errMsg");
			
		resetLoginBox();
	});
	
	$("#txtUserName_err").hide();
	$("#txtUserPassword_err").hide();
}


function resetLoginBox() {
	$("#passRecoverOk_Mode").hide();
	$("#passRecoverFail_Mode").hide();
	$("#forgotPass_Mode").hide();
	$("#forgotPass_Btns").hide();
	$("#forgotPass_sendBtn").hide();
	$("#forgotPass_backBtn").hide();
	$("#fail_Btns").hide();
	$("#login_Mode").show();
	$("#login_Btns").show();
	
	$("#" + headerControl + "_txtUserName").val("Username (your E-mail)");
	$("#" + headerControl + "_txtUserNameEmail").val("Username (your E-mail)");
	$("#" + headerControl + "_txtUserPassword").val("");
	$("#passTxtLabel").css("display","block");
}

function setErrorMsgWidth() {
	$("#txtUserName_err").css("width","auto").css("width",$("#txtUserName_err").width());
	$("#txtUserPassword_err").css("width","auto").css("width",$("#txtUserPassword_err").width());
}

function checkInOut() {
    $("#" + headerControl + "_rememberMeBox").toggleClass("checked");
    if ($("#" + headerControl + "_rememberMeBox").hasClass("checked")) {
        $("#" + headerControl + "_hdnRememberMe").val(1);
    }
    else {
        $("#" + headerControl + "_hdnRememberMe").val(0);
    }
}

function recoverPassword() {
	$("#txtUserName_err").hide();
	$("#txtUserPassword_err").hide();
	$("#login_Mode").hide();
	$("#login_Btns").hide();
	$("#forgotPass_Mode").show();
	$("#forgotPass_Btns").show();
	$("#forgotPass_sendBtn").show();
}

function recoverPasswordResponse(requestSent) {
	if (requestSent == true) {
		$("#txtUserName_err").hide();
		$("#login_Mode").hide();
		$("#login_Btns").hide();
		$("#forgotPass_sendBtn").hide();
		$("#ucHeader_passRecoverOk_Mode").show();
		$("#forgotPass_Btns").show();
		$("#forgotPass_backBtn").show();
		$("#" + headerControl + "_txtUserNameEmail").val("Username (your E-mail)");
	}
	else {
		$("#txtUserName_err").hide();
		$("#forgotPass_Mode").hide();
		$("#forgotPass_Btns").hide();
		$("#login_Mode").hide();
		$("#login_Btns").hide();
		$("#ucHeader_passRecoverFail_Mode").show();
		$("#fail_Btns").show();
	}
	$("#" + headerControl + "_clientLoginBox").css("width","395px").css("opacity","1");
}

function returnPassRecoverForm() {
	$("#ucHeader_passRecoverFail_Mode").hide();
	$("#fail_Btns").hide();
	$("#forgotPass_Mode").show();
	$("#forgotPass_Btns").show();
	$("#forgotPass_sendBtn").show();
}

function hidePasswordTxt() {
	$("#passTxtLabel").css("display","none");
	$("#passTxtLabel").prev().focus();
}

function pswBlur() {
	if($("#ucHeader_txtUserPassword").val()=="" && $("#ucHeader_txtUserPassword").parent().attr('class').indexOf('error')<0) {
		$('#passTxtLabel').show();
	}
}


var isShowPopUp;

function showPopUp(popUpSizeType,popUpHeaderText,iFrameSource,queryString) {
	isShowPopUp = true;
	var popUpWidth = 0;
	var popUpHeight = 0;			
	var popUpSizes = [
		"sizeType1:100,100",
		"sizeType2:450,430",
		"sizeType3:615,490",
		"sizeType4:380,190",
		"sizeType5:620,470",
		"sizeType6:680,560",
		"sizeType7:680,500",
		"sizeType8:680,550",
		"sizeType9:360,250",
		"sizeType10:680,580",
		"sizeType11:610,460",
		"sizeType12:790,592",
		"sizeType13:430,440",
		"sizeType14:600,610",
		"sizeType15:600,470",
        "sizeType16:620,530",
		"sizeType17:685,555"
	];
	
	//CUSTOM HIDE Stock Ticker Div
	$("#appletdiv").css("visibility","hidden");
	
	for(var i=0;i<popUpSizes.length;i++) {
		if(popUpSizes[i].indexOf(popUpSizeType) > -1) {
			popUpWidth = parseInt(popUpSizes[i].split(":")[1].split(",")[0],10);
			popUpHeight = parseInt(popUpSizes[i].split(":")[1].split(",")[1],10);
		}	
	}
	
	var contentHeight = (popUpHeight - 85);
	var contentWidth = ((popUpWidth - 27) - 15);
	
	if ($("#popUpFramwork").css("display")===("block")) {
		$("#popUpBox DIV.middle DIV.content IFRAME").css("backgroundColor","transparent");
		$("#popUpBox DIV.middle DIV.content IFRAME").css("visibility","hidden");
		$("#popUpBox").css("width",popUpWidth).css("height",popUpHeight);
		$("#popUpBox DIV.top DIV.top_center").css("width",(popUpWidth - 27));
		$("#popUpBox DIV.middle DIV.mid_left").css("height",contentHeight);
		$("#popUpBox DIV.middle DIV.content").css("width",contentWidth).css("height",(contentHeight - 12));
		$("#popUpBox DIV.middle DIV.mid_right").css("height",contentHeight);
		$("#popUpBox DIV.bottom DIV.bottom_center").css("width",(popUpWidth - 26));
		$("#popUpBox DIV.top DIV.top_center H1.header").html(popUpHeaderText);
		$("#popUpBox DIV.middle DIV.content IFRAME").css("width",contentWidth).css("height",(contentHeight - 12));
		if ((queryString) && (queryString != "undefined"))  {
			$("#popUpBox DIV.middle DIV.content IFRAME").attr("src", "popups/" + iFrameSource + ".aspx" + queryString);
		}
		else {
			$("#popUpBox DIV.middle DIV.content IFRAME").attr("src", "popups/" + iFrameSource + ".aspx");
		}	
	}
	else {
		$("#popUpFramwork").show();
		$("#popUpBox").css("width",popUpWidth).css("height",popUpHeight);
		$("#popUpBox DIV.top DIV.top_center").css("width",(popUpWidth - 27));
		$("#popUpBox DIV.middle DIV.mid_left").css("height",contentHeight);
		$("#popUpBox DIV.middle DIV.content").css("width",contentWidth).css("height",(contentHeight - 12));
		$("#popUpBox DIV.middle DIV.mid_right").css("height",contentHeight);
		$("#popUpBox DIV.bottom DIV.bottom_center").css("width",(popUpWidth - 26));
		$("#popUpBox DIV.top DIV.top_center H1.header").html(popUpHeaderText);
		$("#popUpBox DIV.middle DIV.content IFRAME").css("width",contentWidth).css("height",(contentHeight - 12));
		if ((queryString) && (queryString != "undefined"))  {
			$("#popUpBox DIV.middle DIV.content IFRAME").attr("src", "popups/" + iFrameSource + ".aspx" + queryString);
		}
		else {
			$("#popUpBox DIV.middle DIV.content IFRAME").attr("src", "popups/" + iFrameSource + ".aspx");
		}
		$("#popUpFramwork DIV.dark_shadow").animate({opacity:0.5},300,function() {
			$("#popUpBox").css("position","static").css("top","0px");																	   
		});
	}
	
	$("#popUpBox DIV.middle DIV.content IFRAME").ready(function() {
		$("#popUpBox DIV.middle DIV.content IFRAME").load(function() {
			if (isShowPopUp) {
				$("#popUpBox DIV.middle DIV.content IFRAME").css("backgroundColor","#fff");
				$("#popUpBox DIV.middle DIV.content IFRAME").css("visibility","visible");
			}
		});
	});
}

function closePopUp() {
	isShowPopUp = false;
	$("#popUpBox").css("position","absolute").css("top","-10000px");
	$("#popUpFramwork DIV.dark_shadow").animate({ opacity: 0 }, 300, function () {
	    $("#popUpBox DIV.middle DIV.content IFRAME").attr("src", "");
		$("#popUpBox DIV.middle DIV.content IFRAME").css("backgroundColor","transparent");
		$("#popUpBox DIV.middle DIV.content IFRAME").css("visibility","hidden");
	    $("#popUpFramwork").hide();
	});
	//CUSTOM SHOW Stock Ticker Div
	$("#appletdiv").css("visibility","visible");
}

function returnToForm() {
	$("#divSuccess").hide();
	$("#divFail").hide();
	$("#divForm").show();	
}

function TextAreaLimiter(ev) {
    try {
        if (typeof ev == "undefined") {
            var s = event.srcElement;
        } else {
            var s = ev.target;
        }
        var lim = s.getAttribute("YkMaxLength");
        if (lim == null) return;
        var nlim = Number(lim);
        if (s.value.length > nlim) {
            if (s.value.charCodeAt(nlim - 1) == 10 && s.value.charCodeAt(nlim) == 13) {
                nlim--;
            }
        }
        if (s.value.length > nlim) {
            // Overflow, cut
            if (typeof ev == "undefined") {
                event.cancelBubble = true;
            } else {
                ev.stopPropagation();
                ev.preventDefault();
            }
            s.value = s.value.substr(0, nlim);
            return false;
        }
    } catch (e) {
    }
}

function SetTextAreaLimiters() {
    var all_ta = document.getElementsByTagName("textarea");
    for (var i = 0; i < all_ta.length; i++) {
        if (all_ta[i].getAttribute("YkMaxLength") != null) {
            // Has limiter
            all_ta[i].onchange = TextAreaLimiter;
            all_ta[i].onkeyup = TextAreaLimiter;
            all_ta[i].onkeypress = TextAreaLimiter;
            all_ta[i].onkeydown = TextAreaLimiter;
        }
    }
}

function CheckEvent13(ev, func, func2, multiline, func3) {
    var isIE = false;
    if (!multiline) multiline = false;
    if (navigator.appName.indexOf("Microsoft") > -1 || navigator.appName.indexOf("IE") > -1) {
        isIE = true;
    }
    if ((isIE && event.keyCode == 13) || (!isIE && ev.which == 13)) {
        if (multiline) return true;
        if (isIE) {
            event.cancelBubble = true;
        } else {
            ev.preventDefault();
            ev.stopPropagation();
        }
        var res = func();
        if (typeof func2 != 'undefined' && func2 != null) {
            func2();
        }
		if (typeof func3 != 'undefined' && func3 != null) {
            func3();
        }
        return res;
    }
    return true;
}


var val_textBox;
var isfocus;

function onKeyPress(ev) {
	if(ev.keyCode==40) {
		isfocus=false;	
	}
	if (!isfocus) {
 		 if (ev.keyCode == 13) {
			setTimeout(function() {
	     	this.focus();
			isfocus=true;
			hidePasswordTxt();
    		}, 0);
			// but cancel the default behavior (submitting the form) directly in the event listener
			ev.preventDefault();
			return false;
		}
	} else { 
		 if (ev.keyCode == 13) {
			return CheckEvent13(ev,validateAuthentication,setErrorMsgWidth,false,hidePasswordTxt);
		 }
	}
}
function ofocus() {
		isfocus = true;
		valInt = setInterval(checkVal, 100);
}
function checkVal() {
	var val = $('#ucHeader_txtUserPassword').val();
	if (val!="") {
		$("#passTxtLabel").hide();
		clearInterval(valInt);
	}
}

function fOnBlur() {
	if ($('#ucHeader_txtUserName').val()=="") {
		$('#ucHeader_txtUserName').val("Username (your E-mail)");
	}
	isfocus=false;
}
