﻿//Print
function PrintWin(elmPrint)
{
	var win = window.open();
	
	win.document.write("<Link href='../CSS/Style_en.css' rel='stylesheet' type='text/css'>");
	win.document.write("<TABLE cellpadding='10' cellspacing='0' border='0' width='100%'>");
	win.document.write(document.getElementById(elmPrint).innerHTML);
	win.document.write("</TABLE>");
	win.document.close();
	
	win.print();
}

function SetDisable(ButtonID, value)
{
	document.getElementById(ButtonID).disabled = value;
}

//Disable Button
function DisableButton(ButtonID)
{
	document.getElementById(ButtonID).disabled = true;
}

function Disable(ButtonID, Period)
{
	window.setInterval("DisableButton('" + ButtonID + "')", Period);
}

function ShowArr(IDArr)
{
	for(i = 0; i < IDArr.length; i++)
	{
		document.getElementById(IDArr[i]).style.display = '';
	}
}

function HideArr(IDArr)
{
	for(i = 0; i < IDArr.length; i++)
	{
		document.getElementById(IDArr[i]).style.display = 'none';
	}
}

function FillArr(IDArr, value)
{
	for(i = 0; i < IDArr.length; i++)
	{
		FillElem(IDArr[i], value);
	}
}

function EmptyArr(IDArr)
{
	for(i = 0; i < IDArr.length; i++)
	{
		FillElem(IDArr[i], '');
	}
}

function Empty(elemID)
{
    FillElem(elemID, '');
}

// Empty an element
function FillElem(elemID, value)
{
	try
	{
	    document.getElementById(elemID).value = value;
	    document.getElementById(elemID).innerHTML = value;
    }
    catch(e)
    {
    	try
        {
            document.getElementById(elemID).innerHTML = value;
            document.getElementById(elemID).value = value;
        }
        catch(e)
        {
        }
    }
}

//Default Button
function SetDefaultButton(btnID, event)
{
	if(event.keyCode == 13)
	{
		event.returnValue = false;
		event.cancel = true;
		document.getElementById(btnID).click();
	}
}

function SetFocus(elemID)
{
    document.getElementById(elemID).focus();
}

// Checks if an element exists
function IsVisible(elemID)
{
	try
	{
		document.getElementById(elemID).tagName;
		return true;
	}
	catch(e)
	{
		return false;
	}
}

//Show - Hide
function Show(objectID)
{
	document.getElementById(objectID).style.visibility = 'visible';
}

function Hide(objectID)
{
	document.getElementById(objectID).style.visibility = 'hidden';
}

function FillCombo(ComboID, DispArr, ValArr)
{
	document.getElementById(ComboID).options.length = 1;
	
	for(i = 0; i < DispArr.length; i++)
	{
		document.getElementById(ComboID).options[i + 1] = new Option(DispArr[i], ValArr[i]);
	}
}

function IsNumberKey(e) {
    e = e || window.event;
    var key = e.which || e.keyCode;    

	if (key == 13 || key == 46 || key == 8 || key == 37 || key == 39 || key == 190 || key == 110 || (key > 95 && key < 106) || key == 9 || (key > 47 && key < 58)) 
		return true; 
	else
		return false;
}

function trim(inputString)// To DO Add to a library -->
{
        // Removes leading and trailing spaces from the passed string. Also removes
        // consecutive spaces and replaces it with one space. If something besides
        // a string is passed in (null, custom object, etc.) then return the input.
        if (typeof inputString != "string") { return inputString; }

        var retValue = inputString;
        var ch = retValue.substring(0, 1);
        while (ch == " ")
        {   // Check for spaces at the beginning of the string
            retValue = retValue.substring(1, retValue.length);
            ch = retValue.substring(0, 1);
        }

        ch = retValue.substring(retValue.length-1, retValue.length);

        while (ch == " ")
        {   // Check for spaces at the end of the string
            retValue = retValue.substring(0, retValue.length-1);
            ch = retValue.substring(retValue.length-1, retValue.length);
        }

        while (retValue.indexOf("  ") != -1)
        {   // Note that there are two spaces in the string - look for multiple spaces within the string
            retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
        }

        return retValue; // Return the trimmed string back to the user
}

// XMLHTTP Object Creator
function GetXmlHttpObject()
{
	if(window.XMLHttpRequest)
	{
		return new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		try
		{
			return new ActiveXObject('Msxml2.XMLHTTP');
		}
		catch(e)
		{
			return new ActiveXObject('Microsoft.XMLHTTP');
		}
	}
}

function XmlHttpGet(xmlhttp, url)
{
	xmlhttp.open('GET', url, true);
	xmlhttp.send(null);
}



