//set wait cursor

function SetWait()
{  
	document.activeElement.style.cursor = "wait";
}  

// keystroke testing
function TestKeyStroke(objEvent, testType, cancelEnter)
{
	var iKeyCode, strKey;
   
    iKeyCode = objEvent.keyCode;
   
	if (cancelEnter == true && iKeyCode == 13)
	{
		return false
	}
	
	if (testType == 'numeric')
	{
		if (window.event.shiftKey && iKeyCode != 9)
		    return false;
		if ((iKeyCode >= 32) && (iKeyCode <= 47) && (iKeyCode != 46))
			return false;
		else if (((iKeyCode >= 58) && (iKeyCode < 96)) || (iKeyCode > 105))
			return false;
	}
}

// phone number format

function ValidatePhone(ctrl)
{
	var curVal = ctrl.value;
	var curVal2;
	var openParenPos;
	var closeParenPos;
	var tempStr;
	var tempStr2;
	var tempStrPart1;
	var tempStrPart2;
	var tempStrPart3;
	var tempLen;
	var tempLen2;
	
	if (curVal.length == 3)
	{
		curVal2 = curVal;
        
        openParenPos = curVal.indexOf('(');
        closeParenPos = curVal.indexOf(')');
        
        if (openParenPos == -1)
        {
			curVal2= "(" + curVal2;
        }
        if(closeParenPos == -1)
        {
			curVal2 = curVal2 + ")";
        }
        ctrl.value="";
        ctrl.value= curVal2;
	}

	if	(curVal.length > 3)
	{
        openParenPos = curVal.indexOf('(');
        closeParenPos = curVal.indexOf(')')
        
        if (closeParenPos == -1)
        {
			tempLen = curVal.length;
            tempStr = curVal.substring(0, 4);
            tempStr = tempStr + ")"
            tempStr2 = curVal.substring(4, tempLen);
            curVal2 = tempStr + tempStr2;
            ctrl.value = "";
            ctrl.value = curVal2;
        }
	}

	if (curVal.length > 5)
	{
		tempStr = curVal.substring(openParenPos +1, closeParenPos);
        
        if(tempStr.length > 3)
        {
             tempStr2 = tempStr;
             tempLen = tempStr2.length;
             tempLen2 = curVal.length
             tempStrPart1 = tempStr.substring(0, 3);
             tempStrPart2 = tempStr.substring(3, tempLen);
             tempStrPart3 = curVal.substring(closeParenPos + 1, tempLen2);
             ctrl.value = "";
             curVal2= "(" + tempStrPart1 +")" + tempStrPart2 + tempStrPart3;
             ctrl.value = curVal2;
        }
  
		tempLen = curVal.length;
		tempStr = curVal.substring(closeParenPos +1, tempLen);
		tempLen2 = tempStr.length;
		
		if( tempLen2 > 3 && tempStr.indexOf('-') == -1)
		{
			tempStrPart1 = curVal.substring(0, closeParenPos + 1);
			tempStrPart2 = curVal.substring(closeParenPos +1, closeParenPos + 4);
            tempStrPart3 = curVal.substring(closeParenPos +4, tempLen);
            curVal2 = tempStrPart1 + tempStrPart2 + "-" + tempStrPart3;
			ctrl.value = "";
			ctrl.value = curVal2;
        }
	}
}

function ValidateDate(ctrl)
{
	var curVal = ctrl.value;
	var curVal2;
	var firstSlashPos;
	var secSlashPos;
	var tempStr;
	var tempStr2;
	var tempStrPart1;
	var tempStrPart2;
	var tempStrPart3;
	var tempLen;
	var tempLen2;
	
	if (curVal.length == 2)
	{
		curVal2 = curVal;
        
        firstSlashPos = curVal.indexOf('/');
                
        if (firstSlashPos == -1)
        {
			curVal2 = curVal2 + "/";
        }
        ctrl.value = "";
        ctrl.value = curVal2;
	}

    if (curVal.length > 2)
	{
        firstSlashPos = curVal.indexOf('/');
        
        if (firstSlashPos == -1)
        {
			tempLen = curVal.length;
            tempStr = curVal.substring(0, 2);
            tempStr = tempStr + "/"
            tempStr2 = curVal.substring(2, tempLen);
            curVal2 = tempStr + tempStr2;
            ctrl.value = "";
            ctrl.value = curVal2;
        }
	}

    if (curVal.length > 5)
	{
        secSlashPos = curVal.indexOf('/', firstSlashPos + 1);
        
        if (secSlashPos == -1)
        {
			tempStrPart1 = curVal.substring(0, firstSlashPos + 1);
			tempStrPart2 = curVal.substring(firstSlashPos + 1, firstSlashPos + 3);
            tempStrPart3 = curVal.substring(firstSlashPos + 3, tempLen);
            curVal2 = tempStrPart1 + tempStrPart2 + "/" + tempStrPart3;
			ctrl.value = "";
			ctrl.value = curVal2;
        }
	}

}
function ValidateZip(ctrl)

{
	var curVal = ctrl.value;
    var curVal2;
    var HiphenPos;
    var tempStrPart1;
    var tempStrPart2;

    if (curVal.length == 6)
    {
		curVal2 = curVal;
        HiphenPos = curVal.indexOf('-');
      
        if (HiphenPos == -1)
        {
	        tempLen = curVal.length;                  
            tempStr = curVal.substring(0, 5);
            tempStr = tempStr + "-"
            tempStr2 = curVal.substring(5, tempLen + 1);
            curVal2 = tempStr + tempStr2;
            ctrl.value = "";
            ctrl.value = curVal2;               
        }
	}
}