﻿var Constants = new Object();
Constants.OneMB = 1000000;
function GetPageElement(ElementName)
{
    var ReturnElement = "";

    if (document.getElementById)
    {
        ReturnElement = "document.getElementById('" + ElementName + "')";
    }
    else if (document.all)
    {
        ReturnElement = "document.all['" + ElementName + "']";
    }
    return eval(ReturnElement);
}
function SplitString(JoinedList,DelimA,DelimB)
{
	var args = JoinedList.split(DelimA);
	for (var i=0; i<args.length; i++)
	{
		var pair = args[i].split(DelimB);

		temp = unescape(pair[0]).split('+');
		name = temp.join(' ');

		temp = unescape(pair[1]).split('+');
		value = temp.join(' ');
        
        if(pair != "")
		    this[name]=value;
	}
	return this;
}
function IsINT(sText)
{
    var ValidChars = "0123456789";
    var IsNumber=true;
    var Char;

    var checkText = RemoveCommas(sText);

    if (checkText.length == 0)
        return false;
         
    for (i = 0; i < checkText.length && IsNumber == true; i++) 
    { 
        Char = checkText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) 
        {
            IsNumber = false;
        }
    }
    return IsNumber;
}
function FormatIntControl(val)
{
	var ctlVal;
	var iPeriodPos;
	ctlVal = val;

	if (isNaN(ctlVal)) 
	{
		return ctlVal;
	} else {
		iPeriodPos = ctlVal.indexOf(".");
		if (iPeriodPos>0) 
		{
            ctlVal = ctlVal.substring(0,iPeriodPos);    
		}
		return ctlVal;
	}
}
function IsNumeric(sText)
{
    var ValidChars = "0123456789.-";
    var IsNumber=true;
    var Char;

    var checkText = RemoveCommas(sText);

    if (sText.length == 0)
        return false;
         
    for (i = 0; i < sText.length && IsNumber == true; i++) 
    { 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) 
        {
            IsNumber = false;
        }
    }
    return IsNumber;
}
function RemoveCommas(sText)
{
    var newText = sText + "";
    return newText.replace(",","");
}
function trim(field)
{
    while (field.charAt(field.length-1) == " "){field = field.substring(0,field.length-1);} 
	while (field.substring(0,1) ==" "){field = field.substring(1,field.length);}
	return field;
}
function trimString(inputString) 
{
   inputString=inputString.replace(/^\s+/g,"");
   inputString=inputString.replace(/\s+$/g,"");
   return inputString;
}  
function Hide(id) {
    var node = GetPageElement(id);
    if (node != null) {
        node.style.display = "none";
    }
}
function Show(id) {
    var node = GetPageElement(id);
    if (node != null) {
        node.style.display = "";
    }
}
function Toggle(id) {
    var node = GetPageElement(id);
    if (node != null) {
        node.style.display = node.style.display == "none" ? "" : "none";
    }
}
function QuickMessageBoard(URL) {
	MessageWin = this.open(URL, "messageWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=700,height=600");
}
function setstatus(str) {
    window.status = str;
    return true;
}
function UTCDate()
{
    var herenow = new Date();
    var utcnow = new Date();

    utcnow.setDate(herenow.getUTCDate());
    utcnow.setMonth(herenow.getUTCMonth());
    utcnow.setFullYear(herenow.getUTCFullYear());
    utcnow.setHours(herenow.getUTCHours());
    utcnow.setMinutes(herenow.getUTCMinutes());
    utcnow.setSeconds(herenow.getUTCSeconds());
    utcnow.setMilliseconds(herenow.getUTCMilliseconds());

    return utcnow;
}
function UTCDateWithOffset(offsetMinutes)
{
    var now = UTCDate();
    now.setMinutes(now.getMinutes() + offsetMinutes);
    return now;
}
function SetDropDownSelection(dropDown, newValue)
{
    for(var i=0; i< dropDown.options.length; i++)
    {
        if(dropDown.options[i].value == newValue)
        {
            dropDown.selectedIndex = i;
            break;
         }
    }
}
function SwitchMenu(obj){
    var el = GetPageElement(obj);
    if (el != null)
    {
        el.className = 'navblueon';
    }
}
function SwitchMenu2(obj){
    var el = GetPageElement(obj);
    if (el != null)
    {
        el.className = 'navblue';
    }
}
function showSubNav(obj){
    var subnav;
    var thisobj = "GetPageElement('" + obj + "Menu')";
    subnav = eval(thisobj);
    if (subnav != null){
        subnav.style.visibility = 'visible';	
    }
}
function hideSubNav(obj){
    var subnav;
    var thisobj = "GetPageElement('" + obj + "Menu')";
    subnav = eval(thisobj);
    if (subnav != null){
        subnav.style.visibility = 'hidden';	
    }
}
function ScrollToTop()
{
    if (window.pageYOffset)
        window.pageYOffset = 0;
    else if (document.body.scrollTop)
        document.body.scrollTop = 0;
}
function IgnoreEnter(e)
{
    var characterCode;

    if(e && e.which)
    {
        characterCode = e.which;
    }
    else
    {
        e = event;
        characterCode = e.keyCode;
    }

    if(characterCode == 13)
    {
        return false;
    }
    else
    {
        return true;
    }
}
function StringCleaner(oldString)
{
    while (oldString.indexOf("%20") > -1)
    {
        oldString = oldString.replace("%20"," ");
    }

    while (oldString.indexOf("%22") > -1)
    {
        oldString = oldString.replace("%22","\"");
    }
                            
    return oldString;
}
function Open_New(str)
{
    OpenWinNew = this.open(str);
}

function swapImage(ctrl,img)
{
    ctrl.src="../../images/SkillTesting/"+img;     
}
function IsValidFileExtension(file, extListType) {

        var extAt = file.lastIndexOf(".");
        if (extAt == -1) {
          return false;
        }
        ext = file.substring(extAt,file.length).toLowerCase();
          
        switch (extListType){   
            case "generic":
                        extArray = new Array(".accdb", ".avi", ".bmp", ".doc", ".docx", ".eps", ".gif", ".htm", ".html", ".jpeg", ".jpg", ".mdb", ".mde", ".mov", ".mp3", ".mpe", ".mpeg", ".mpg", ".pdf", ".png", ".pps", ".ppsx", ".ppt", ".pptx", ".psd", ".qxd", ".swf", ".tif", ".tiff", ".txt", ".wav", ".wmv", ".xls", ".xlsx", ".zip");
                        extArray.sort();
                        break;
            case "image":  
                        extArray = new Array(".gif",".jpeg",".jpg",".bmp");
                        extArray.sort();
                        break;
        }     
      for (var i = 0; i < extArray.length; i++) {
          if (extArray[i] == ext) {
              return true;
          }
      }
      alert("Please only upload files that end in types:  " + (extArray.join("  ")) + "\nPlease select a new " + "file to upload and submit again.");
      return false;
}

  function is_space(filepath){
    var invalid = " \\"; // Invalid character is a space
    var invalid2= "\\ ";
    if (filepath.indexOf(invalid) > -1 || filepath.indexOf(invalid2) > -1){
      alert("DO NOT include spaces in your file's name");
      return false;
    }
    return true;
  }

//Return the sum of the digits
function sumof()
{
    var total=0;
     for (var i=0; i<arguments.length; i++){ //step through each parameter entered
      total+=arguments[i]
     }
     return total
}

// returns true if space exist in between string
function isContainSpace(inputString)
{
    var invalid = " ";
    if (inputString.indexOf(invalid) > -1) 
    {
        return false;
    }
    return true;

}

//returns true for valid email address
function isEmail(email)
{
    if(!email.match(/^[A-Za-z0-9\._\-+]+@[A-Za-z0-9_\-+]+(\.[A-Za-z0-9_\-+]+)+$/))
    {
        return false;
    }
    return true;
}
//Function for clicking the button on Enter key press
function doClick(buttonName,e)
{    
     var key;
     if(window.event)
        key = window.event.keyCode;     //IE
     else
        key = e.which;     //firefox
    if (key == 13)
    {
        //Get the button the user wants to have clicked
        var btn = GetPageElement(buttonName);
        if (btn != null)
        { 
            //If we find the button click it
            btn.click();
            event.keyCode = 0;
        }
    }
}
function setFocus(inputField)
{
    GetPageElement(inputField).focus();
}

function swapImage(ctrl,imgWithPath)
{   
    ctrl.src=imgWithPath;     
}
findPosY = function(obj){
    var curtop = 0;
    if (document.getElementById || document.all) {
    while (obj.offsetParent) {
    curtop += obj.offsetTop;
    if (typeof(obj.scrollTop) == 'number')
    curtop -= obj.scrollTop;
    obj = obj.offsetParent;
    }
    }
    else if (document.layers)
    curtop += obj.y;
    return curtop;
}
function showCalloutDiv(control, xCordinatePos, divInnerHTML) 
{
    var x, y, obj, controlName = control.value;
    obj = document.getElementById('divHelpCallout');
    obj.style.display = "inline";
    obj.style.position = "absolute";
    x  = xCordinatePos;
    y  = findPosY(control) - 14;
    obj.style.left = x + "px";
    obj.style.top  = y + "px";
    document.getElementById('calloutInnerTextID').innerHTML = divInnerHTML;
}
function hideCalloutDiv()
{
    var obj = document.getElementById('divHelpCallout');
    obj.style.display = "none";
}
function MatchPassword(Password, ConfirmPassword)
{
    if(GetPageElement(Password).value != GetPageElement(ConfirmPassword).value)
    {
        GetPageElement(Password).value="";
        GetPageElement(ConfirmPassword).value="";
        return false;
    }
    else
    {
        return true;
    }
}

