
var DHTML = (document.getElementById || document.all || document.layers);	

function getObj(name)
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if (document.all)
	{
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if (document.layers)
	{
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
}

function checkinvi(cont)
{
	if (!DHTML) return;
		var x = new getObj(cont);
	if (x.style.visibility =='hidden'){
		return true
	}else if (x.style.visibility =='visible'){
		return false 					
	}
}


function setInvisible(item, flag)
{
    if (!DHTML) return;
    var x = new getObjStyle(item);
    x.style.visibility = (flag) ? 'hidden' : 'visible';
    x.style.display = (flag) ? 'none': 'block';
}

function changeStatus(item)
{
    if (!DHTML) return;
	var x = new getObjStyle(item);
	
	if (x.style.display=='none')
	{
		x.style.display='block';
		x.style.visibility = 'visible';
	}
	else
	{		
		x.style.display='none';
		x.style.visibility = 'hidden';
	}	
}


function getObjStyle(name)
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if (document.all)
	{
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if (document.layers)
	{
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
}
		
function invi(flag, cont)
{
	if (!DHTML) return;
		var x = new getObj(cont);
		x.style.visibility = (flag) ? 'hidden' : 'visible'
		x.style.display = (flag) ? 'none' : 'block'
}

function checkEmail(name){
	  	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(document.getElementById(name).value))
			testresults=true
                       else{
                       alert('Invalid email address!')
                           testresults=false
                       }
        return (testresults)
}


function InsertText(input, insTexte) { 

	startTag = ''; 
	endTag = ''; 

	if (input.createTextRange) {
		var text; 
		input.focus(input.caretPos); 
		input.caretPos = document.selection.createRange().duplicate(); 

		if(input.caretPos.text.length>0) { 
			input.caretPos.text = startTag + input.caretPos.text + endTag;
			} 
			else { 
			input.caretPos.text = startTag + "" + insTexte + " " + endTag; 
			}
         }
         else 
		input.value += startTag + insTexte + endTag; 
}

function CheckToDisplay(obj)
{
    if (event.keyCode != 8) 
    {
        var myValue = String.fromCharCode(event.keyCode);
        event.returnValue = (IsNumeric(myValue)) ? myValue : "";
    }
}

function IsNumeric(value)
{
    var validChars = "0123456789";
    return (validChars.indexOf(value) != -1);
}
     
      function IsCellPhone(sText,charCount)
    {
        var ValidChars = "0123456789";
        var IsNumber=true;
        var Char;

        for (i = 0; i < sText.length && IsNumber == true; i++) 
        { 
            
            Char = sText.charAt(i) ;
            if (charCount == 0 && Char == '+') {
				IsNumber = true;
            }
			else if (ValidChars.indexOf(Char) == -1) 
			{
                IsNumber = false;
            }
        }
        return IsNumber;
     }
     function ConvertToCell(obj)
	{
	    var strHoldText  = ''
	    strHoldText = obj.value;
	    var strHoldNew = ''
	    for (var i = 0 ; i < strHoldText.length ; i++)
	    {
	        if (IsCellPhone(strHoldText.charAt(i),i) == true)
	        {
	            strHoldNew += strHoldText.charAt(i) ;
	        }
	    }
	    obj.value = strHoldNew;
	}

     
      function IsNumber(sText)
    {
        var ValidChars = "0123456789";
        var IsNumber=true;
        var Char;

        for (i = 0; i < sText.length && IsNumber == true; i++) 
        { 
            Char = sText.charAt(i) ; 
            if (ValidChars.indexOf(Char) == -1) 
            {
                IsNumber = false;
            }
        }
        return IsNumber;
     }
     
     function ConvertNumber(obj)
	{
	    var strHoldText  = ''
	    strHoldText = obj.value;
	    var strHoldNew = ''
	    for (var i = 0 ; i < strHoldText.length ; i++)
	    {
	        if (IsNumber(strHoldText.charAt(i)) == true)
	        {
	            strHoldNew += strHoldText.charAt(i) ;
	        }
	    }
	    obj.value = strHoldNew;
	}
	
	function IsRealNumber(sText)
    {
        var ValidChars = ".0123456789";
        var IsNumber=true;
        var Char;

        for (i = 0; i < sText.length && IsNumber == true; i++) 
        { 
            Char = sText.charAt(i) ; 
            if (ValidChars.indexOf(Char) == -1) 
            {
                IsNumber = false;
            }
        }
        return IsNumber;
     }
     
	function OnlyRealNumbers(obj) {
	    var strHoldText  = ''
	    strHoldText = obj.value;
	    var strHoldNew = ''
	    for (var i = 0 ; i < strHoldText.length ; i++)
	    {
	        if (IsRealNumber(strHoldText.charAt(i)) == true)
	        {
	            strHoldNew += strHoldText.charAt(i) ;
	        }
	    }
	    obj.value = strHoldNew;
	}
	
	 function Trim1(obj)
	{
	    var strHoldText  = ''
	    strHoldText = obj.value;
	    var strHoldNew = ''
	    for (var i = 0 ; i < strHoldText.length -1 ; i++)
	    {
	        strHoldNew += strHoldText.charAt(i) ;
	    }
	    obj.value = strHoldNew;
	}


	/**
	*
	*  Javascript trim, ltrim, rtrim
	*  http://www.webtoolkit.info/
	*
	**/

	function trim(str, chars) {
	    return ltrim(rtrim(str, chars), chars);
	}

	function ltrim(str, chars) {
	    chars = chars || "\\s";
	    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
	}

	function rtrim(str, chars) {
	    chars = chars || "\\s";
	    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
	
	}
	
	//What it does
//	Displays the amount of characters left in a lable that may be typed into a textbox and and pops up a msgbox 
//	to let user know when max amount has been reached 
	//How to use
    //Create a text box and a maching lable underneath
    //For argument sake txtTextBox and lblLable
    //lblLable text  = “”
    //add the onkeypress and onkeyup events for txtTextBox
    //e.g. 
    //<asp:TextBox ID="txtTextBox" onkeypress="return CheckTextCount(this,'ctl00_ContentPlaceHolder1_lblLable',250);" onkeyup="return CheckTextCount(this,'ctl00_ContentPlaceHolder1_lblLable',250);" runat="server" Height="60px" TextMode="MultiLine" Width="200px">
    //</asp:TextBox>
    //<br />
    //<asp:Label ID="lblLable" runat="server"></asp:Label>

    //This example was made for dot net 2006
    //For 2003 all you would need to change is the lable name you sent through “ctl00_ContentPlaceHolder1_lblLable” to what ever it need to be in 2003
		
	function CheckTextCount(TextControl,DisplayControl,Max)
    { 
        var strText = new String(""); 
        strText = TextControl.value;
        if (strText.length < Max)
	    { 
		    document.getElementById(DisplayControl).innerText = (Max - strText.length) + ' characters left'; 
		} 
		else 
		{
		    strText = TextControl.value;
		    strText = strText.substr(0,Max);
		    TextControl.value = strText;
		    document.getElementById(DisplayControl).innerText = (Max - strText.length) + ' characters left';
		    alert('Maximum Amount of Caracters Reached');
		    return false;
		}
    }
    
			isIE=document.all;
			isNN=!document.all&&document.getElementById;
			isN4=document.layers;
			
			function openPopup(URL)
			{
				var x;
				var y;
				x = (screen.width/2) - 200;//220
				y = (screen.height/2) - 200;//10.50
				if (isN4)
				{
					if (e.which==2||e.which==3)
					{
						dPUW=window.open(URL,'','width=670,height=480,top='+y+',left='+x+',directories=no,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,resizable=no');
						return false;
					}
				}
				else
				{
					dPUW=window.open(URL,'','width=670,height=480,top='+y+',left='+x+',directories=no,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,resizable=no');
					return false;
				}
			}