function zipFieldOnBlur(sender, args)
{   
    try
    {    
       // validateNum(zipID); 
        var digits =10;   
        var tempctrl=document.getElementById(zipID);         
        var tempValue= tempctrl.value;
           
        if(!(tempValue == '') )
        {    
        var formatedStr = tempctrl.value;
            
            if((tempValue.length == 5))
            {
            }
            else if(tempValue.length == 10)
            {
            if (tempValue.indexOf('-')==-1)
            {
               //alert("Zip field must be five or nine digits long.");                
               tempctrl.value="";
               document.getElementById(zipID).focus();
               args.IsValid = false;
                return;
             }            
             if (tempValue.indexOf('-')!=5)
              {
               // alert("Sign -  must be in sixth position.");                
               tempctrl.value="";
               document.getElementById(zipID).focus();
               args.IsValid = false;
                return;
              }
              
            }
            else if(tempValue.length == 9)
            {
             if (tempValue.indexOf('-')>-1)
             {
               //alert("Zip field must be five or nine digits long.");                
               tempctrl.value="";
               document.getElementById(zipID).focus();
               args.IsValid = false;
                return;
             }
                else
                {
                    formatedStr= tempValue.substring(0,5)+ "-" + tempValue.substring(5,9); 
                }
               
             }
            else
            {
            // alert("Zip field must be five or nine digits long.");                
                tempctrl.focus();
                  SetCursorPosition(0);
               args.IsValid = false;
                return;
                }
            tempctrl.value = formatedStr;
        }      
        args.IsValid = true;
    }
    catch(e)
    {
        alert(e.description);
               args.IsValid = false;
                return;
    }   
}


function ZipFieldOnKeyPress(param)
{
    try
    {
         var tempctrl=document.getElementById(param);
          var tempval=tempctrl.value;
         //Capture the keycode by the user
        var keyAscii = window.event.keyCode;
        debug:
        if (tempval.indexOf("-")!=-1)
        {
            if (tempval.indexOf("-")!=5)
            {
             tempctrl.value=  tempval.replace("-",'') ;
                tempval=tempctrl.value;
            }
        }
                    
                     if (tempval.length==5)
                {
                     tempctrl.value=tempctrl.value+"-";
                }
             
                     if (tempval.length>5 && tempval.indexOf("-")==-1 )
                     
                {
                   //tempctrl.value=tempval.slice(0,5)+"-"+tempval.slice(5);
                   tempctrl.value="";
                }
//            if (tempval.length==10)
//            {
//             window.event.keyCode = 0;
//             return false;
//            
//            }
            
       if((keyAscii > 47) && (keyAscii <58))
            {
      
               return true;
                        
            }
            else
            {
             window.event.keyCode = 0;
             return false;
            }
            
        

    }
    catch(e)
    {
       return false;
    }
}

function zipFieldOnFocus(param)
{
    try
    {    
        var tempctrl=document.getElementById(param);
        var tempValue= tempctrl.value;        
        
        if(!(tempValue == '') )
        { 
            var cursorPos = GetCursorPosition()             
            formatedStr=  tempValue.replace("-",'') ;
            formatedStr=  formatedStr.replace(" ",'') ;           
         
            tempctrl.value=formatedStr;
          
            SetCursorPosition(cursorPos);
         }
    }
    catch(e)
    {
        return false;
    }   
}

function ResetForm()
{
	
	var confirmrslt= confirm('Are you sure to clear the screen?');
	
	if(confirmrslt)
	location.href = location.href; 
	return false;
}


function SetCursorPosition(pos) {
    var obj = document.activeElement;
    if (obj) {
    var tr = obj.createTextRange();    
    if (obj && tr) {
        tr.moveStart("character", pos);
        tr.collapse();
        tr.select();
        return true;
        }
    }
    return false;
}