﻿// JScript File

var currProcessingPage="";
var isHIPPADone = false;
var debug_msg=false;
var scardInitialized = false;
var scardCalls = 0;//used for ignoring the first call made to ProcessSCard(code,path)
var objTopValue=0;
var objLeftValue=0;

var minHeight = (window.opener || window.frameElement) ? 0 : 620;
var minWidth = (window.opener || window.frameElement) ? 0 : 1200;

function logOff(path)
{
    location.href = path;
}

function GoTo(path)
{
    location.href = path;
}

function GetTime(msg)
{
    if(debug_msg)
    {
        var d = new Date();
        var curr_hour = d.getHours();
        var curr_min = d.getMinutes();
        window.status = msg + " " +d.getHours() + " : " + d.getMinutes() + " : " + d.getSeconds();
    }
}

function AddWidth(elemID,toAddVal) {
   var mydiv = document.getElementById(elemID);
   var curr_width = parseInt(mydiv.style.width); // removes the "px" at the end
   mydiv.style.width = (curr_width + toAddVal) +"px";
}

function SessionExpiredAlert()
{
    var port = window.parent.document.location.port;
    if(port=="")
        port="80";
    alert("Your Session has expired. Need to Re-Login");    
    location.href(window.parent.document.location.protocol+"//"+window.parent.document.location.hostname+":"+port+"/OpalWeb/Login.aspx?MSG=Session Expired. Please Login Again.");
}

//SmartCard Functions
function initializecard()
{
    try
    {
        if(!scardInitialized)
	        kicker.InitializeSmartCard();
	}
	catch (e) {}      	    
}

function ProcessSCard(code,path)
{
    if(scardCalls!=0)
        logOff(path);
    scardCalls++;    
}
//End of SmartCard Functions

var topPos;
var leftPos;

function setCenter(popwidth,popheight)
{
    var w = 480, h = 340;

    if (document.all) {
       /* the following is only available after onLoad */
       w = document.body.clientWidth;
       h = document.body.clientHeight;
    }
    else if (document.layers) {
       w = window.innerWidth;
       h = window.innerHeight;
    }

    leftPos = (w-popwidth)/2;
    topPos = (h-popheight)/2;

}

function displaySettings(id)
{
    var toggleDIV = document.getElementById(id);
    var displayDIV = document.getElementById(id+'Content');
    
    if(toggleDIV.innerText=="+ "+id)
    {
        displayDIV.style.display='inline';
        toggleDIV.innerText = "- "+id;
    }
    else
    {
        displayDIV.style.display='none';
        toggleDIV.innerText = "+ "+id;
    }

}

function showWStatus(sMsg) 
{
    window.status = sMsg ;
    return true ;
}

function selectOptionMove(param,SourceID,DestID)
{
	 var oSourceOptions,oDestOptions,oOption;
	 var oSource = document.getElementById(SourceID);
	 var oDest = document.getElementById(DestID);
	    
	 switch(param)
	 {
	    //removes all selected items from source and adds in destination
	    case "1":   
	             if ((oSource.length == -1) || (oSource.selectedIndex == -1))
	             {return;}
        	     
	             while(oSource.selectedIndex!=-1)
	             {
	               oSourceOptions = oSource.options;
	               oOption = oSourceOptions.item(oSource.selectedIndex);
	               oSourceOptions.remove(oSource.selectedIndex);
	               oDestOptions = oDest.options;
	               oOption.selected = false;
	               oDestOptions.add(oOption);            	   
                }
                if(!(SourceID=="selectedCol" || SourceID=="unselectedCol"))
                sortSelect(oDest);
                break;
        
        //removes all from source and adds to destination        
        case "-1":
                if ((oSource.length == -1))
	             {return;}
	             var count = oSource.length;
	             for(var i=0;i<count;i++)
	             {
	               oSourceOptions = oSource.options;
	               oOption = oSourceOptions.item(0);
	               oSourceOptions.remove(0);
	               oDestOptions = oDest.options;
	               oOption.selected = false;
	               oDestOptions.add(oOption);
	             }
	             if(!(SourceID=="selectedCol" || SourceID=="unselectedCol"))	 
	             sortSelect(oDest);            
	             break;
	    
	    //copies from source to destination         
        case "0":
                if ((oSource.length == -1))
	             {return;}
	             var count = oSource.length;
	             var destCount = oDest.length;
	             var inDest = false;
	             for(var i=0;i<count;i++)
	             {
	               oSourceOptions = oSource.options;
	               oOption = oSourceOptions.item(i);
	               for(var j=0;j<destCount;j++)
	               {
	                    if(oDest.options[j].value == oOption.value)
	                    {
	                        inDest = true;
	                        break;
	                    }
	               }
	               
	               if(!inDest)
	               {
	                    var newOpt = new Option(oOption.text, oOption.value);
	                    oDest.add(newOpt);
	                    inDest = false;	               	               
	               }
	             }
	             if(!(SourceID=="selectedCol" || SourceID=="unselectedCol"))	 
	             sortSelect(oDest);            
	             break;
        
        //removes from source        
        case "2":
                if ((oSource.length == -1) || (oSource.selectedIndex == -1))
	             {return;}
        	     
	             while(oSource.selectedIndex!=-1)
	             {
	               oSourceOptions = oSource.options;
	               oOption = oSourceOptions.item(oSource.selectedIndex);
	               oSourceOptions.remove(oSource.selectedIndex);	                 	   
                }
                if(!(SourceID=="selectedCol" || SourceID=="unselectedCol"))
                sortSelect(oSource);          
	            break;
    }
}

//sorting of the select list
function sortSelect(obj) {
	var o = new Array();
	if (!hasOptions(obj)) { return; }
	for (var i=0; i<obj.options.length; i++) {
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
		}
	if (o.length==0) { return; }
	o = o.sort( 
		function(a,b) { 
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
			return 0;
			} 
		);

	for (var i=0; i<o.length; i++) {
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
		}
	}


function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
	}


//Validation Stuff
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   if(sText.length==0)
   { IsNumber=false; }
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

//Date Validation begins here.

// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

//function isInteger(s){
//	var i;
//    for (i = 0; i < s.length; i++){   
//        // Check that current character is number.
//        var c = s.charAt(i);
//        if (((c < "0") || (c > "9"))) return false;
//    }
//    // All characters are numbers.
//    return true;
//}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || IsNumeric(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}


//to load the scripts required for a page on demand.........called through img onload embedded in the page.
function dhtmlLoadScript(url)
{
   var e = document.createElement("script");
   e.src = url;
   e.type="text/javascript";
   document.getElementsByTagName("head")[0].appendChild(e); 
}


function textAreaFormat(theString)
{
  var workingString = "";
  var outputString = "";
  
  workingString = theString;
  workingString = replace(workingString,chr(13)&chr(10),"<br>","all");
  workingString = replace(workingString,chr(32),"&nbsp;","all");
  outputString = workingString;
  return outputString;
}

//not used
//<script type="text/javascript">

//function staticLoadScript(url)
//{
//   document.write('<script src="', url, '" type="text/JavaScript"><\/script>');
//}

//staticLoadScript("static_way.js");

//</script> 


function getCheckedValue(strRadioObj) 
{
	radioObj = document.getElementsByName(strRadioObj);
	
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function setCheckedValue(radioObj, newValue) {
    if (!radioObj)
        return;
    var radioLength = radioObj.length;
    if (radioLength == undefined) {
        radioObj.checked = (radioObj.value == newValue.toString());
        return;
    }
    for (var i = 0; i < radioLength; i++) {
        radioObj[i].checked = false;
        if (radioObj[i].value == newValue.toString()) {
            radioObj[i].checked = true;
        }
    }
}

function getDDTextVal(ddName,returnType)
{
    var tempDD = document.getElementById(ddName);
    var retVal="";
    switch(returnType)
    {
        case "ddValue":
            retVal = tempDD.options[tempDD.selectedIndex].value;
            break;
            
        case "ddText":
            retVal = tempDD.options[tempDD.selectedIndex].text;
            break;            
    }
    return retVal;
}

function GetBrowserWidth()
{
    var winW;
    if (parseInt(navigator.appVersion)>3) 
    {
         if (navigator.appName=="Netscape") 
         {
          winW = window.innerWidth-16;  //minus for scrollbar        
         }
         if (navigator.appName.indexOf("Microsoft")!=-1) 
         {
              winW = document.body.offsetWidth-20;              
         }
    }
    return winW;
}

function GetBrowserHeight()
{
    var winH;
    if (parseInt(navigator.appVersion)>3) 
    {
         if (navigator.appName=="Netscape") 
         {          
          winH = window.innerHeight-16;
         }
         if (navigator.appName.indexOf("Microsoft")!=-1) 
         {              
              winH = document.body.offsetHeight-20;
         }
    }
    
    return winH;
}

function GetPosition(obj){
    objTopValue= 0;
    objLeftValue= 0;
    while(obj){
	objLeftValue+= obj.offsetLeft;
	objTopValue+= obj.offsetTop;
	obj= obj.offsetParent;
    }    
}

function ChangeDefaultText(obj,txtVal)
{
    if(obj.value==txtVal)
    obj.value ="";
}


function checkPhoneFaxNumber(phoneNo) {
 var phone10 = /^\d\d\d\-\d\d\d-\d\d\d\d$/;
 var phone07 = /^\d\d\d-\d\d\d\d$/;
 var phone11 = /^\d-\d\d\d\-\d\d\d-\d\d\d\d$/;
 if (phoneNo.match(phone10))  
   return true; 
 else 
 {
   if(phoneNo.match(phone11))
     return true;
   else
   {
     if(phoneNo.match(phone07))
       return true;
     else {
       alert( "The phone/fax number entered is invalid! Correct Format is xxx-xxx-xxxx" );
       return false;
     }
    } 
 }
}



//used from both Transcription window and StudyListHome
function DoSendFax(sID,winToClose)
{
    var faxnum =  document.getElementById('txtFaxNum').value;
    if(checkPhoneFaxNumber(faxnum))
    {
        var formParams="CMD=SEND_FAX&SID="+sID+"&FAXNUM="+faxnum;
        var postResult="";    
        postResult = makeAPOST("FaxProcessor.aspx",formParams);
        alert(postResult);
        CloseAjaxWindow(winToClose);
    }   
}

function SwapDIVs(divToUse,doWat)
{    
   document.getElementById(divToUse).style.display = doWat;
}

function popNewWin(url,winName,ht,wdt,res,scroll,tool,stat)
{
    setCenter(ht,wdt);
	newwindow=window.open(url,winName,'height='+ht+',width='+wdt+',left='+leftPos+',top='+topPos+',resizable='+res+',scrollbars='+scroll+',toolbar='+tool+',status='+stat);
	if (window.focus) {newwindow.focus()}
}

function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) 
  {
     obj['e'+type+fn] = fn;
     obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
     obj.attachEvent( 'on'+type, obj[type+fn] );
  }
  else
     obj.addEventListener( type, fn, false );
 }
 
function removeEvent( obj, type, fn ) 
{
   if ( obj.detachEvent ) 
   {
     obj.detachEvent( 'on'+type, obj[type+fn] );
     obj[type+fn] = null;
   } 
   else
     obj.removeEventListener( type, fn, false );
} 

function checkEnter(e,currObj){
    var characterCode;
    if(e && e.which){ //if which property of event object is supported (NN4)
    e = e
    characterCode = e.which //character code is contained in NN4's which property
    }
    else{
        e = event
        characterCode = e.keyCode //character code is contained in IE's keyCode property
    }

    if (characterCode == 13) { //if generated character code is equal to ascii 13 (if enter key)
        switch (currObj.name) {
            case "txtAddIP":
                AddLocalIP();
                break;

            case "txtAddFlag": 
                AddFlag();
                break;

            case "txtViewUsersFilter":
                ViewUsersFilter();
                break;


            case "txtUserPerm":
                return false;
                break;

        }
    return false
    }
    else{
    return true
    }
}

//*********************Hash Table Class ********************************//
function Hash()
{
	this.length = 0;
	this.items = new Array();
//	for (var i = 0; i < arguments.length; i += 2) {
//		if (typeof(arguments[i + 1]) != 'undefined') {
//			this.items[arguments[i]] = arguments[i + 1];
//			this.length++;
//		}
//	}
   
    this.addItems=function(in_itemsString)
    {
        var tempArray = new Array();
        tempArray = in_itemsString.split("@");
        for(var k=0;k<tempArray.length;k++)
        {
            try
            {
                this.items[tempArray[k]] = tempArray[k+1];
                k++;
                this.length++;
            }
            catch(e)
            {
            }
        }
        return "";
    }
    
	this.removeItem = function(in_key)
	{
		var tmp_value;
		if (typeof(this.items[in_key]) != 'undefined') {
			this.length--;
			var tmp_value = this.items[in_key];
			delete this.items[in_key];
		}
	   
		return tmp_value;
	}

	this.getItem = function(in_key) {
	    if(in_key=="length" || in_key=="shift" || in_key=="reverse" || in_key=="sort" || in_key=="pop"  || in_key=="slice")
	    {
	        return in_key;
	    }
	    else
	    {
		    return this.items[in_key];
		}    
	}

	this.setItem = function(in_key, in_value)
	{
		if (typeof(in_value) != 'undefined') {
			if (typeof(this.items[in_key]) == 'undefined') {
				this.length++;
			}
			this.items[in_key] = in_value;
		}
	   
		return in_value;
	}

	this.hasItem = function(in_key)
	{
		return typeof(this.items[in_key]) != 'undefined';
	}
}
//******************************End of Hash Table Class***********************************************//
////////////////////////////////////////////////////////////////////////////////////////////////
//filtering drop downs
var typeAheadData =
{
   keyStrokes:"", // Stores user entered keystrokes.
   focusDDLId:"", // Id of the dropdown with focus.
   
   // Reset if DDL ID changes.
   ResetOnNewDDLRequest:function(id)
   {
      if (this.focusDDLId != id)
         {this.focusDDLId=id; this.keyStrokes="";}
   }
}; 


function filterDD(list,funcToCall){
    if(event.keyCode)
    {         
         // Reset typeAheadData on new DDL requests.
        typeAheadData.ResetOnNewDDLRequest(list.id);
         
         var c = String.fromCharCode(event.keyCode)
         if (c != null)
         {
            typeAheadData.keyStrokes += c;
         } 
         
         // cancel default dropdown behavior.
         event.cancelBubble = true;
         event.returnValue = false; 
         
	    pattern = new RegExp('^'+typeAheadData.keyStrokes,"i");
	    i=0;
	    sel=0;
	    while(i<list.options.length){
		    if(pattern.test(list.options[i].text)){sel=i;break}
		    i++;
	    }
	    list.options.selectedIndex=sel;
	    if(sel==0)
	    {
	        typeAheadData.keyStrokes ="";
	    }
	    if(funcToCall!="")
	    {
	        switch(funcToCall)
	        {
	            case "getRefPhy":
	                getRefPhy(list.options[sel].value);
	                break;
	                
	            case "getSpecialist":
	                getSpecialist(list.options[sel].value);
	                break;
	                
	            default:
	                break;         
	                
	        }
	    }
	}   
}
/////////////////////////////////////////////////////////////////////
//filtering multi-select with every keyboard entry
var originalMultiListDIV="";
var processingDIV="";

function filterMultiSelectDD(objTxtBox, listItem, listItemDIV)
{    
    var valArray = new Array();
    var txtArray = new Array();
    return;
    if(originalMultiListDIV=="" || processingDIV!=listItemDIV)
    {
        originalMultiListDIV = document.getElementById(listItemDIV).innerHTML;
        processingDIV = listItemDIV;
    }
    else
    {
        document.getElementById(listItemDIV).innerHTML = originalMultiListDIV;
    }
       
    var originalMultiList = document.getElementById(listItem);         
	    var pattern = new RegExp(objTxtBox.value,"i");
	    i=0;	    	    	    
	    while(i<originalMultiList.options.length){
		    if(pattern.test(originalMultiList.options[i].text))
		    {
		         valArray.push(originalMultiList.options[i].value);
                 txtArray.push(originalMultiList.options[i].text);                 	        
		    }
		    i++;
	    }
	    
	    if(valArray.length>0)
	    { 
	        originalMultiList.options.length=0;
	        
	        for(var j=0;j<valArray.length;j++)
	        {
	             var optn = document.createElement("OPTION");
                 optn.text = txtArray[j];
                 optn.value = valArray[j];
                 originalMultiList.options.add(optn); 
            }     
	    }
	    else
	    {
	        alert("No matches found. Original list restored.");
	    }
}

//filterting multiselect with search button
function filterMultiSelect(txtBoxID,listItemDIV,url,filterType)
{
    var formParams="";
    var postResult="";
    formParams = "CMD="+filterType+"&FILTER_TEXT="+document.getElementById(txtBoxID).value;
    postResult = makeAPOST(url,formParams);    
    document.getElementById(listItemDIV).innerHTML = postResult;
}



////////////////////////@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//script to run for loading the jquery calendar
function LoadCalendar(fromPage)
{
    popUpCal.autoPopUp = false;   
    
    $(document).ready(function () {
                popUpCal.autoPopUp = false;
                popUpCal.buttonText = 'Calendar';
                if(fromPage=="admin")
                {
                    popUpCal.buttonImage = '../images/calendar.gif';
                }
                else
                {
                    popUpCal.buttonImage = 'images/calendar.gif';
                }    
                //$('.calendarFocus').calendar();
                $('.calendarButton').calendar();
                });
}

////////////////////////@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function CloseAjaxWindow(winID)
{
    var objWindow = document.getElementById(winID)
    if(objWindow)
    {
       objWindow.style.display = "none";     
    }
}

//added to allow ,. usage in the abbr. in auto-correct mechanism
function DeMystify(wordToConvert)
{    
    var re1 = /,/g;
    wordToConvert = wordToConvert.replace(re1,"vizcomma");
    
    var re2 = /[.$]/g;
    wordToConvert = wordToConvert.replace(re2,"vizperiod");
    return wordToConvert;
}

function escapeHTML(str)
{
   var div = document.createElement('div');
   var text = document.createTextNode(str);
   div.appendChild(text);
   return div.innerHTML;
}



//A function to capture a tab keypress in a textarea and insert 4 spaces and NOT change focus.
function tab_to_tab(e,el) {
    if(e.keyCode==9){
        var oldscroll = el.scrollTop; //So the scroll won't move after a tabbing
        e.returnValue=false;  //This doesn't seem to help anything, maybe it helps for IE
        //Check if we're in a firefox
      	if (el.setSelectionRange) {
      	    var pos_to_leave_caret=el.selectionStart+4;
      	    //Put in the tab
     	    el.value = el.value.substring(0,el.selectionStart) + '    ' + el.value.substring(el.selectionEnd,el.value.length);
            //There's no easy way to have the focus stay in the textarea, below seems to work though
            setTimeout("var t=document.getElementById('code1'); t.focus(); t.setSelectionRange(" + pos_to_leave_caret + ", " + pos_to_leave_caret + ");", 0);
      	}
      	//Handle IE
      	else {      		
      		document.selection.createRange().text='    ';
      	}
        el.scrollTop = oldscroll; //put back the scroll
    }
}

//added to String to enable string searches - EndWith
if (!String.prototype.endsWith) {
  String.prototype.endsWith = function(suffix) {
    var startPos = this.length - suffix.length;
    if (startPos < 0) {
      return false;
    }
    return (this.lastIndexOf(suffix, startPos) == startPos);
  };
}

//if (!String.prototype.startsWith) {
//    String.prototype.startsWith = function(str) {
//        return (this.match(”^”+str)==str)}
//}    

function sleep(naptime)
{
      naptime = naptime * 1000;
      var sleeping = true;
      var now = new Date();
      var alarm;
      var startingMSeconds = now.getTime();
      //alert("starting nap at timestamp: " + startingMSeconds + "\nWill sleep for: " + naptime + " ms");
      while(sleeping){
         alarm = new Date();
         alarmMSeconds = alarm.getTime();
         if(alarmMSeconds - startingMSeconds > naptime){ sleeping = false; }
      }      
      //alert("Wakeup!");
}

function AddDropDownItem(obj,text,value)
{
    // Create an Option object        

    var opt = document.createElement("option");

    // Add an Option object to Drop Down/List Box
    document.getElementById(obj).options.add(opt);

    // Assign text and value to Option object
    opt.text = text;
    opt.value = value;
    opt.selected = true;

}


function GenericOptionMove(type, sourceID, destinationID, postUrl)
{
     var oSourceOptions,oDestOptions,oOption;
	 var oSource = document.getElementById(sourceID);
	 var oDest = document.getElementById(destinationID);
	 
	 var formParams="";
	 var count = oSource.length;  
	 oSourceOptions = oSource.options; 
	 switch(type)
	 {
	    case "1":   
	             if ((oSource.length == -1) || (oSource.selectedIndex == -1))
	             {return;} 
	             for(var i=0;i<count;i++)
	             { 
	               oOption = oSourceOptions.item(i);	               	          
	               if(oOption.selected == true)
	                    formParams += oOption.value+",";      
	             }	          	     
                break;
                
        case "-1":
        case "0":
                if ((oSource.length == -1))
	             {return;}	             
	             for(var i=0;i<count;i++)
	             {
	               oOption = oSourceOptions.item(i);	               	          
	               formParams += oOption.value+",";      
	             }	             
	             break;
        
    }
    
    formParams = "OP="+destinationID+"&DATA="+formParams;                 	                      
    
    $.ajax({
               type: "POST",
               url: postUrl,
               data: formParams,
               success: function(msg){
                    if(msg=="0")
                        selectOptionMove(type,sourceID,destinationID);         	   
                    else
                        alert("Unable to complete this operation");                        
               }
             });
	
        
}


//Cookie related
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}


/////////////////////////////////////////////////////
function getElement(id, suffix) {
    if (document.getElementById(id)) return document.getElementById(id);
    else if (document.getElementById(id + '' + suffix)) return document.getElementById(id + '' + suffix);
    else if (document.getElementById('ctl00_body_' + id + '' + suffix)) return document.getElementById('ctl00_body_' + id + '' + suffix);
    else if (document.getElementById('ctl00_ctl00_body_body_' + id + '' + suffix)) return document.getElementById('ctl00_ctl00_body_body_' + id + '' + suffix);
    else if (document.getElementById('ctl00_ctl01_body_body_' + id + '' + suffix)) return document.getElementById('ctl00_ctl01_body_body_' + id + '' + suffix);
    else if (document.getElementById('ctl00_' + id + '' + suffix)) return document.getElementById('ctl00_' + id + '' + suffix);
    else if (document.getElementById('ctl00_ctl00_' + id + '' + suffix)) return document.getElementById('ctl00_ctl00_' + id + '' + suffix);
    else if (document.getElementById('ctl00_ctl01_' + id + '' + suffix)) return document.getElementById('ctl00_ctl01_' + id + '' + suffix);
    return null;
}
document.newGetElementById = function (cl) {
    return getElement(cl, '');
};
document.getDateElementById = function (cl) {
    return getElement(cl, '_txtDate');
};
document.getSSNElementById = function (cl) {
    return getElement(cl, '_txtSSN');
};
document.getPhoneElementById = function (cl) {
    return getElement(cl, '_txtPhone');
};
document.getTimeElementById = function (cl) {
    return getElement(cl, '_txtTime');
};
document.getHourElementById = function (cl) {
    return getElement(cl, '_ddlHr');
};
document.getMinuteElementById = function (cl) {
    return getElement(cl, '_ddlMin');
};
document.getAmPmElementById = function (cl) {
    return getElement(cl, '_ddlAMPM');
};
//////////////////////////////////////////////////////
//////////////////////Get Window Width////////////////////////////////
function innerWindow() {
    this.AppName = (navigator.appName == "Netscape") ? "Netscape" : "IE";
    this.Width = function () {
        if (parseInt(navigator.appVersion) > 3) {
            if (navigator.appName.indexOf("Microsoft") != -1) return (document.documentElement.offsetWidth < minWidth) ? minWidth : document.documentElement.offsetWidth;
            else return (window.innerWidth < minWidth) ? minWidth : window.innerWidth;
        }
        //return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
        //return document.documentElement.clientWidth;
    }
    this.Height = function () {
        if (parseInt(navigator.appVersion) > 3) {
            if (navigator.appName.indexOf("Microsoft") != -1) return (document.documentElement.offsetHeight < minHeight) ? minHeight : document.documentElement.offsetHeight;
            else return (window.innerHeight < minHeight) ? minHeight : window.innerHeight;
        }
        //var ht = window.innerHeight != null ? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null ? document.body.clientHeight : null;
        //if (document.body.clientHeight && ht < document.body.clientHeight) ht = document.body.clientHeight;
        //return ht;
    }
    
}
/////////////////////////////////////////////////////
////////////Custom Alert//////////////////////

//if (document.getElementById) {
//    window.alert = function (txt) {
//        createCustomAlert(txt);
//    }
//}

function createCustomAlert(txt) {
    try { txt = txt.replace(/\n/g, '<BR>'); } catch (err) { }
    var alertObj = document.getElementById("alertbox");
    if (alertObj) {
        $('#alertMessage').html(txt);
        var myWindow = new innerWindow();
        alertObj.style.display = "block";                
        alertObj.style.left = (myWindow.Width() - alertObj.offsetWidth) / 2 + "px";
        alertObj.style.top = (myWindow.Height() - alertObj.offsetHeight) / 2 + "px";
        alertObj.style.display = "block";
        if (document.getElementById('CloseAlertBtn')) document.getElementById('CloseAlertBtn').focus();
    }        
    return false;
}

function autoHideAlert() {
    setTimeout(function () { if (document.newGetElementById('alertbox')) document.newGetElementById('alertbox').style.display = 'none'; }, 3000);
}
function removeCustomAlert() {
    //$.modal.close();
    $('#alertbox')[0].style.display = "none";
}

///////////////////////////////////

///////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
// File: vector.js
//
// Author: Jason Geissler
// 
// Date: Sept 3, 2003
//
// Purpose: To have a dynamic collection instead
//          of using arrays when the total quantity
//          is unknown
//////////////////////////////////////////////////////
// Vector Constructor -- constructs the object
function Vector(inc) {
	if (inc == 0) {
		inc = 100;
	}
	
	/* Properties */
	this.data = new Array(inc);
	this.increment = inc;
	this.size = 0;
	
	/* Methods */
	this.getCapacity = getCapacity;
	this.getSize = getSize;
	this.isEmpty = isEmpty;
	this.getLastElement = getLastElement;
	this.getFirstElement = getFirstElement;
	this.getElementAt = getElementAt;
	this.addElement = addElement;
	this.insertElementAt = insertElementAt;
	this.removeElementAt = removeElementAt;
	this.removeAllElements = removeAllElements;
	this.indexOf = indexOf;
	this.contains = contains
	this.resize = resize;
	this.toString = toString;
	this.sort = sort;
	this.trimToSize = trimToSize;
	this.clone = clone;
	this.overwriteElementAt;
}

// getCapacity() -- returns the number of elements the vector can hold
function getCapacity() {
	return this.data.length;
}

// getSize() -- returns the current size of the vector
function getSize() {
	return this.size;
}

// isEmpty() -- checks to see if the Vector has any elements
function isEmpty() {
	return this.getSize() == 0;
}

// getLastElement() -- returns the last element
function getLastElement() {
	if (this.data[this.getSize() - 1] != null) {
		return this.data[this.getSize() - 1];
	}
}




// getFirstElement() -- returns the first element
function getFirstElement() {
	if (this.data[0] != null) {
		return this.data[0];
	}
}

// getElementAt() -- returns an element at a specified index
function getElementAt(i) {
	try {
		return this.data[i];
	} 
	catch (e) {
		return "Exception " + e + " occured when accessing " + i;	
	}	
}

// addElement() -- adds a element at the end of the Vector
function addElement(obj) {
	if(this.getSize() == this.data.length) {
		this.resize();
	}
	this.data[this.size++] = obj;
}

// insertElementAt() -- inserts an element at a given position
function insertElementAt(obj, index) {
	try {
		if (this.size == this.capacity) {
			this.resize();
		}
		
		for (var i=this.getSize(); i > index; i--) {
			this.data[i] = this.data[i-1];
		}
		this.data[index] = obj;
		this.size++;
	}
	catch (e) {
		return "Invalid index " + i;
	}
}

// removeElementAt() -- removes an element at a specific index

function removeElementAt(index) {
	try {
		var element = this.data[index];
		
		for(var i=index; i<(this.getSize()-1); i++) {
			this.data[i] = this.data[i+1];
		}
		
		this.data[getSize()-1] = null;
		this.size--;
		return element;
	}
	catch(e) {
		return "Invalid index " + index;
	}
} 

// removeAllElements() -- removes all elements in the Vector
function removeAllElements() {
	this.size = 0;
	
	for (var i=0; i<this.data.length; i++) {
		this.data[i] = null;
	}
}

// indexOf() -- returns the index of a searched element
function indexOf(obj) {
	for (var i=0; i<this.getSize(); i++) {
		if (this.data[i] == obj) {
			return i;
		}
	}
	return -1;
}

// contains() -- returns true if the element is in the Vector, otherwise false
function contains(obj) {
	for (var i=0; i<this.getSize(); i++) {
		if (this.data[i] == obj) {
			return true;
		}
	}
	return false;
}

// resize() -- increases the size of the Vector
function resize() {
	newData = new Array(this.data.length + this.increment);
	
	for	(var i=0; i< this.data.length; i++) {
		newData[i] = this.data[i];
	}
	
	this.data = newData;
}


// trimToSize() -- trims the vector down to it's size
function trimToSize() {
	var temp = new Array(this.getSize());
	
	for (var i = 0; i < this.getSize(); i++) {
		temp[i] = this.data[i];
	}
	this.size = temp.length - 1;
	this.data = temp;
} 

// sort() - sorts the collection based on a field name - f
function sort(f) {
	var i, j;
	var currentValue;
	var currentObj;
	var compareObj;
	var compareValue;
	
	for(i=1; i<this.getSize();i++) {
		currentObj = this.data[i];
		currentValue = currentObj[f];
		
		j= i-1;
		compareObj = this.data[j];
		compareValue = compareObj[f];
		
		while(j >=0 && compareValue > currentValue) {
			this.data[j+1] = this.data[j];
			j--;
			if (j >=0) {
				compareObj = this.data[j];
				compareValue = compareObj[f];
			}				
		}	
		this.data[j+1] = currentObj;
	}
}

// clone() -- copies the contents of a Vector to another Vector returning the new Vector.
function clone() {
	var newVector = new Vector(this.size);
	
	for (var i=0; i<this.size; i++) {
		newVector.addElement(this.data[i]);
	}
	
	return newVector;
}

// toString() -- returns a string rep. of the Vector
function toString() {
	var str = "Vector Object properties:\n" +
	          "Increment: " + this.increment + "\n" +
	          "Size: " + this.size + "\n" +
	          "Elements:\n";
	
	for (var i=0; i<getSize(); i++) {
		for (var prop in this.data[i]) {
			var obj = this.data[i];
			str += "\tObject." + prop + " = " + obj[prop] + "\n";
		}
	}
	return str;	
}

// overwriteElementAt() - overwrites the element with an object at the specific index.
function overwriteElementAt(obj, index) {
	this.data[index] = obj;
}
////end of code used by dustin


