﻿        var IE = document.all ? true : false

        // If NS -- that is, !IE -- then set up for mouse capture
        if (!IE) document.captureEvents(Event.MOUSEMOVE)

        // Set-up to use getMouseXY function onMouseMove
        document.onmousemove = getMouseXY;

        // Temporary variables to hold mouse x-y pos.s
        var tempX = 0
        var tempY = 0

        // Main function to retrieve mouse x-y pos.s

        function getMouseXY(e) {
            if (IE) { // grab the x-y pos.s if browser is IE
                tempX = event.clientX + document.body.scrollLeft
                tempY = event.clientY + document.body.scrollTop
            } else {  // grab the x-y pos.s if browser is NS
                tempX = e.pageX
                tempY = e.pageY
            }
            // catch possible negative values in NS4
            if (tempX < 0) { tempX = 0 }
            if (tempY < 0) { tempY = 0 }
            // show the position values in the form named Show
            // in the text fields named MouseX and MouseY
            form1.x.value = tempX
            form1.y.value = tempY
            return true
        }

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
}

/* Client-side access to querystring name=value pairs
	Version 1.3
	28 May 2008
	
	License (Simplified BSD):
	http://adamv.com/dev/javascript/qslicense.txt
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	
	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		
		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;
		
		this.params[name] = value;
	}
}

Querystring.prototype.get = function(key, default_) {
	var value = this.params[key];
	return (value != null) ? value : default_;
}

Querystring.prototype.contains = function(key) {
	var value = this.params[key];
	return (value != null);
}


function tooLong(txtBox, iLength, errorSpan) {
    var errorTxt = "";
    
    if (txtBox.value.length > iLength) {
        txtBox.style.background = 'Yellow';
        errorTxt = "Must be less than " + iLength.toString() + " characters long.";
    }
    errorSpan.innerHTML = errorTxt;
}
function integerCheck(txtBox, iMinValue, iMaxValue, errorSpan) {
    var errorTxt = "";

    if ( iMinValue > iMaxValue ) {
	var iHold = iMinValue;
	iMinValue = iMaxValue;
	iMaxValue = iHold;
    }
    txtBox.style.background = 'White';

    if (txtBox.value.length > 0) {
        var numEx = new RegExp("^[-+]?[0-9]*$");
        if (txtBox.value.match(numEx)) {
            var iVal = parseInt(txtBox.value, 10);
            if (iVal > iMaxValue) {
                txtBox.style.background = 'Yellow';
                errorTxt += "The Maximum Value allowed is: " + iMaxValue.toString() + "\n";
            }
            if (iVal < iMinValue) {
                txtBox.style.background = 'Yellow';
                errorTxt += "The Minimum Value allowed is: " + iMinValue.toString() + "\n";
            }
        }
        else {
            txtBox.style.background = 'Yellow';
            errorTxt += "Must be an integer value.\n";
        }
    }

    if(errorTxt != ""){
	alert(errorTxt);
	txtBox.value = "";
    }
}
function floatCheck(txtBox, iMinValue, iMaxValue, iPrecision, errorSpan) {
    var errorTxt = "";

    if (iMinValue > iMaxValue) {
        var iHold = iMinValue;
        iMinValue = iMaxValue;
        iMaxValue = iHold;
    }

    txtBox.style.background = 'White';

    if (txtBox.value.length > 0) {
        var numEx = new RegExp("^[-+]?[0-9]*[.]?([0-9]*)$");
        if (txtBox.value.match(numEx)) {
            var fVal = parseFloat(txtBox.value);
            var precExp = new RegExp("^[-+]?[0-9]*[.]?([0-9]{0," + iPrecision.toString() + "})$");
            if (txtBox.value.match(precExp)) {
                if (fVal > iMaxValue) {
                    errorTxt += "The Maximum Value allowed is: " + iMaxValue.toString() + "\n";
                }
                if (fVal < iMinValue) {
                    errorTxt += "The Minimum Value allowed is: " + iMinValue.toString() + "\n";
                }
            }
            else {
                errorTxt += "Value can only have " + iPrecision.toString() + " points of precision.\n";
            }
        }
        else {
            errorTxt += "Value must be a valid floating point number.\n";
        }
    }

    if (errorTxt != "") {
        txtBox.style.background = 'Yellow';
        alert(errorTxt);
        txtBox.value = "";
    }
}

function checkEmail(txtBox) {
    var emailEx = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$");

    if (!txtBox.value.match(emailEx)) {
        txtBox.value = "";
        txtBox.style.background = 'Yellow';
        alert('Please provide a valid Email address');
    }
    else {
        txtBox.style.background = 'White';
    }
}
function checkUrl(txtBox) {
    var urlEx = new RegExp("(http://)|(https://)(.*)");
    if (!txtBox.value.match(urlEx)) {
        txtBox.value = "http://" + txtBox.value;
    }
}


function generateCaptcha(first, second) {
    first.innerText = Math.floor(Math.random() * 10);
    second.innerText = Math.floor(Math.random() * 10);
}
function checkCaptcha(first, second, answer) {
    try {
        var iFirst = parseInt(first.innerText, 10);
        var iSecond = parseInt(second.innerText, 10);
        var iAnswer = parseInt(answer.value, 10);

        var realAnswer = iFirst + iSecond;
        if (realAnswer != iAnswer) {
            answer.value = "";
            answer.style.background = 'Yellow';
            alert('Wrong answer to Captcha');
            generateCaptcha(first, second);
	    return false;   
        }
        else {
            answer.style.background = 'White';
	    return true;
        }
    }
    catch (e) {

    }
}
function DateCheck(txtBox) {
    var errorTxt = "";

    var dateTimeRegEx = RegExp("^(([0]?[1-9]{1,1})|([1]{1,1}[1-2]{1,1}))[-|/]{1,1}(([0]?[1-9]{1,1})|([1]{1,1}[0-9]{1,1})|([2]{1,1}[0-9]{1,1})|([3]{1,1}[0-1]{1,1}))[-|/]{1,1}(((18)|(19)|((2)[0-9]))[0-9][0-9])?$");
    if (txtBox.value.trim().match(dateTimeRegEx)) {
        var dateArray = new Array();
        dateArray = txtBox.value.split('/');
        if (dateArray.length == 1) {
            dateArray = txtBox.value.split('-');
        }
        var adjustedMonth = parseInt(dateArray[0], 10);
        adjustedMonth = adjustedMonth - 1;
        var testDate = new Date(dateArray[2], adjustedMonth.toString(), dateArray[1]);

        if ((dateArray[1] == testDate.getDate()) && (adjustedMonth == testDate.getMonth()) && (dateArray[2] == testDate.getFullYear())) {
            txtBox.style.background = 'White';
        }
        else {
            errorTxt = "The Date Entered was not valid";
        }

    }
    else {
        errorTxt = "Enter Date in a MM/DD/YYYY format";
    }

    if (errorTxt != "") {
        txtBox.style.background = 'Yellow';
        alert(errorTxt);
        txtBox.value = "";
    }
}
function hideCalendars(calendarHolder) {
    var allCal = calendarHolder.childNodes;
    var calCount = allCal.length;
    for( var i=0; i<calCount; i++){
        allCal[i].style.visibility = 'hidden';
    }
}
function IsRequired(txtBox) {
    var errorTxt = "";
    if (txtBox.value.trim() == "") {
        errorTxt = "Field is required";
    }
    else {
        txtBox.style.background = 'White';
    }

    if (errorTxt != "") {
        alert(errorTxt);
        txtBox.style.background = 'Yellow';
        return false;
    }
    return true;
}
function FillHiddenValues(submitForm) {
    var qs = new Querystring();
    for (i = 0; i < submitForm.elements.length; i++) {
        if (submitForm.elements[i].type == "hidden") {
            var qsValue = qs.get(submitForm.elements[i].name);

            if (qsValue != undefined) {
                submitForm.elements[i].value = qsValue;
            }
            
        }
    }
}
function ValidateTextCheck(txtBox1, txtBox2) {
    var sTxt1 = txtBox1.value.trim();
    var sTxt2 = txtBox2.value.trim();
    var errorTxt = "";

    if (sTxt1 == "" || sTxt2 == "") {
        errorTxt = "Invalid";
    }
    
    if (sTxt1 != sTxt2) {
        errorTxt = "Invalid";
    }

    if (errorTxt != "") {
        alert('Confirmation Field is not correct');
        txtBox1.style.background = 'Yellow';
        txtBox2.style.background = 'Yellow';
        txtBox2.value = "";
        return false;
    }
    return true;
}