﻿var browser=navigator.userAgent;

var availwidth=new Number(0);
var availheight=new Number(0);

var isIE=false;
var isIE7=false;
var isSafari=false;
var isFireFox=false;
var isOpera=false;

if (browser.indexOf("Opera")>=0)
{
	isOpera=true;
	isIE=false;
	isSafari=false;
	isFireFox=false;
}
else if (browser.indexOf("MSIE")>=0)
{
	isIE=true;
	isOpera=false;
	isSafari=false;
	isFireFox=false;
	if (browser.indexOf("MSIE 7")>=0)
	{
	    isIE7=true;
	}
}
else if (browser.indexOf("Safari")>=0)
{
	isSafari=true;
	isIE=false;
	isOpera=false;
	isFireFox=false;	
}
else if (browser.indexOf("Firefox")>=0)
{
	isFireFox=true;
	isSafari=false;
	isIE=false;
	isOpera=false;
}

if (isIE==true)
{
	availwidth=new Number(screen.width);
	availheight=new Number(screen.height);
}
else
{
	availwidth=new Number(screen.availWidth);
	availheight=new Number(screen.availHeight);
}

function IsValidEmail(emailstring)
{
	var Epattern = /(@.*@)|(\.\.)|(@\.)|(^\.)/
	var Epattern1 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/
	
	Epattern.IgnoreCase = true
	Epattern1.IgnoreCase = true
	
	var bResult = Epattern.exec(emailstring)
	var bResult1 = Epattern1.exec(emailstring)

	if ((bResult==null) && (bResult1!=null))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function IsValidURL(urlString) 
{
    var strMatch = /(ftp|http|https):\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#]\w+)*\/?$/i
    if (strMatch.test(urlString)) {
        return true;
    }
    else 
    {
        return false;
    }
}

function OpenWindow(strUrl, intWidth, intHeight) 
{
    var intLeft = (availwidth - intWidth) / 2;
    var intTop = (availheight - intHeight) / 2;
    window.open(strUrl, "endsession", "toolbars=0,scrollbars=0,resizable=0,width=" + intWidth + ",height=" + intHeight + ",left=" + intLeft + ",top=" + intTop);
}

function OpenWindowEx(strUrl, intWidth, intHeight, intResizable, intToolbars, intScrollbar, intMenubar, intStatus,setfocustowindow) 
{
    var intLeft = (availwidth - intWidth) / 2;
    var intTop = (availheight - intHeight) / 2;
    var objWin=window.open(strUrl, "endsession","location=yes,menubar=" + intMenubar.toString() + ",toolbars=" + intToolbars.toString() + ",scrollbars=" + intScrollbar.toString() +
                ",resizable=" + intResizable.toString() + ",status=" + intStatus.toString() + ",width=" + intWidth + ",height=" + intHeight + ",left=" + intLeft + ",top=" + intTop);
    if (setfocustowindow == 1) 
    {
        objWin.focus();
    }
}

function OpenModalWindow(WinName, Url, intIEWidth, intIEHeight, intNonintIEWidth, intNonintIEHeight, scroll, status, resizable) 
{
    if (isIE == true) {
        if (isIE7 == true) {
            intIEHeight = intIEHeight - 30;
        }
        var objVal = window.showModalDialog("IFrameloader.aspx?url=" + Url + "&scroll=1&width=" + intIEWidth + "&height=" + intIEHeight + "", "", "scroll:" + scroll + ";status:" + status + ";resizable:" + resizable + ";center:yes;" + "dialogWidth:" + intIEWidth + "px;dialogHeight:" + intIEHeight + "px;edge:sunken");
    }
    else {
        var ileft = (availwidth - intNonintIEWidth) / 2
        var itop = (availheight - intNonintIEHeight) / 2
        var objVal = window.open(Url, WinName, "toolbars=no,scrollbars=" + scroll + ",resizable=" + resizable + ",modal=yes," + "width=" + intNonintIEWidth + ",height=" + intNonintIEHeight + ",left=" + ileft + ",top=" + itop + "", true)
        if ((ileft + intNonintIEWidth) > availwidth) {
            ileft = (ileft + intNonintIEWidth) - (availwidth + 5);
        }
        objVal.moveTo(ileft, itop - 25);
    }
    return objVal;
}

function OpenModalWindowEx(WinName, Url, sArgs, nsArgsName, intIEWidth, intIEHeight, intNonintIEWidth, intNonintIEHeight, scroll, status, resizable) {
    try 
    {
        if (isIE == true) 
        {
            if (isIE7 == true) 
            {
                intIEHeight = intIEHeight - 30;
            }
        }
        else 
        {
            intIEWidth = intNonintIEWidth;
        }

        var objVal = window.showModalDialog("IFrameloader.aspx?url=" + Url + "&scroll=1&width=" + intIEWidth + "&height=" + intIEHeight + "", sArgs, "scroll:" + scroll + ";status:" + status + ";resizable:" + resizable + ";center:yes;centerscreen:1;" + "dialogWidth:" + intIEWidth + "px;dialogHeight:" + intIEHeight + "px;edge:sunken");
    }
    catch(objErr)
    {
        var ileft = (availwidth - intNonintIEWidth) / 2
        var itop = (availheight - intNonintIEHeight) / 2
        var objVal = window.open(Url + "&" + nsArgsName + "=" + sArgs, WinName, "toolbars=no,scrollbars=" + scroll + ",resizable=" + resizable + ",modal=yes,center=1," + "width=" + intNonintIEWidth + ",height=" + intNonintIEHeight + ",left=" + ileft + ",top=" + itop + "", true)
    }
    return objVal;
}

function OpenWhyCodePage() 
{
    var intWidth = 400;
    var intHeight = 200;
    OpenWindowEx("WhyCode.htm", intWidth, intHeight, 1, 0, 1, 0, 0, 1);
}

function disableRightClick() {
    if (isIE == true) {
        document.body.onmousedown = alertOnRightClick;
    }
    else
    {
        document.captureEvents(Event.MOUSEDOWN);
        document.body.onmousedown = alertOnRightClickMozilla;
    }

    document.body.oncontextmenu=Function("return false");   
    document.body.onselectstart=Function("return false");
    document.body.ondragstart=Function("return false");
    document.body.onmousedrag=Function("return false");
}

function alertOnRightClick() 
{
    if (event.button == 2 || event.button == 3) 
    {
        alert("Copyrighted content.  Please do not attempt to copy!");
        return false;
    }
}

function alertOnRightClickMozilla(e) 
{
    if (e.which == 2 || e.which == 3) 
    {
        alert("Copyrighted content.  Please do not attempt to copy!");
        return false;
    }
}

function isAlphaNumeric(strValue) {
    if (strValue.match(/^[0-9a-zA-Z]+$/)) {
        return true;
    }
    else {
        return false;
    }
}

function isNumber(strNumber) {
    if (strNumber.length > 0) {
        return !isNaN(strNumber);
    }
    else {
        return false;
    }
}


function IsPCValid(strValue) {

    if (strValue.length >= 8 && strValue.length<=25) {
        var regNum = /[0-9]/;
        var regAlpha = /[a-zA-Z]/;
        if (regNum.test(strValue) == true && regAlpha.test(strValue) == true) {
            return true;
        }
        else {
            return false;
        }
    }
    else {
        return false;
    }
}

function EnforceMaxLength(TargetObject, intSize, e) {
    if (e.ctrlKey == true) {
        return false;
    }

    if (isIE == false) {
        if (e.which <= 0 || e.which == 8) {
            return false;
        }
    }

    if ((TargetObject.value.length + 1) > intSize) {
        if (isIE == true) {
            e.keyCode = 0;
        }
        else {
            e.stopPropagation();
            e.preventDefault();
        }
        return false;
    }
}
