
	    var req = new XMLHttpRequest(); 
	    var nitem = 0;
	    var citemid = '';
	    var nTimerID = 0;
	    var dStart = new Date();
	    var iTimerID = 0;
        var ajaxreturn = null;
		var ControlToSet;
		var theForm = document.Scheduling;
		var CalWidth=180;
		var nHwnd=0;
		var StartYear = "";
		var EndYear = "";
		var FormatAs;
		var NN4 = (navigator.appName.indexOf("Netscape")>=0 && !document.getElementById)? true : false;
		var NN6 = (document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? true: false;
		var TOP;
		var LEFT;
		
		if(NN4)document.captureEvents(Event.MOUSEMOVE);
		
		document.onmousemove = LogPosition;
		
		function LogPosition(evt){
		
		    if (NN4||NN6){
		    LEFT=evt.screenX;
		    TOP=evt.screenY-10;
		    }
		    else{
		    LEFT=event.screenX;
		    TOP=event.screenY-10;
		    }
		
		}
		
		
		function ShowCalendar(CONTROL,START_YEAR,END_YEAR,FORMAT){
		
		ControlToSet = eval(CONTROL);
		StartYear = START_YEAR;
		EndYear = END_YEAR;
		FormatAs = FORMAT;
		
		var strFeatures = "width=" + CalWidth + ",height=160" + ",left=" + LEFT + ",top=" + TOP;
		var CalWindow = window.open("include/Calendar.htm","Calendar", strFeatures)
		CalWindow.focus();
		} //End Function
		
		function SetDate(DATE){
		if(ControlToSet){
		ControlToSet.value = DATE; 
		}
		ControlToSet = null;
		StartYear = null;
		EndYear = null;
		FormatAs = null;
		}
		
		function selectMatch(obj,cname) {
			for (var i=0; i<obj.options.length; i++) {
				  citem = obj.options[i].value;
				  if (citem == cname) {
				     obj.options[i].selected = true;
				   }
				}
			}

function returnSelections(obj) {
	    var retstr = "";
		for (var i=0; i<obj.options.length; i++) {
			  citem = obj.options[i].value;
			  if (obj.options[i].selected == true) {
				  if (retstr.length > 0) {
					   retstr = retstr + ",";
				   }
				  retstr = retstr + "'" + citem + "'";
			  }
		}
		return retstr;
}

function isValidDate(dateStr) {

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year

	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		return false;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
		return false;
	}
	if (day < 1 || day > 31) {
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		return false;
	}
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			return false;
	   }
	}
	return true;
}

function isValidTime(timeStr) {
	var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

	var matchArray = timeStr.match(timePat);
	if (matchArray == null) {
		return false;
	}
	hour = matchArray[1];
	minute = matchArray[2];
	second = matchArray[4];
	ampm = matchArray[6];

	if (second=="") { second = null; }
	if (ampm=="") { ampm = null }

	if (hour < 0  || hour > 23) {
		return false;
	}
	if (hour <= 12 && ampm == null) {
		return false;
	}
	if  (hour > 12 && ampm != null) {
		return false;
	}
	if (minute < 0 || minute > 59) {
		return false;
	}
	if (second != null && (second < 0 || second > 59)) {
		return false;
	}
	return true;
}

function CalcTime(oObj) {
	date1 = new Date();
	date2 = new Date();
	diff  = new Date();
    var cstarttime = oObj.starttime.value;
    var cendtime = oObj.endtime.value;
	var hours = 0;
	var mins = 0;

   if (oObj.Length.value != "") return true;
	if (isValidDate(oObj.startdate.value) && isValidTime(cstarttime)) { // Validates first date 
		date1temp = new Date(oObj.startdate.value + " " + cstarttime);
		date1.setTime(date1temp.getTime());
	}
	else return false; // otherwise exits

	if (isValidDate(oObj.enddate.value) && isValidTime(cendtime)) { // Validates second date 
		date2temp = new Date(oObj.enddate.value + " " + cendtime);
		date2.setTime(date2temp.getTime());
	}
	else return false; // otherwise exits

	// sets difference date to difference of first date and second date

	diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
   
	timediff = diff.getTime();

	weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
	timediff -= weeks * (1000 * 60 * 60 * 24 * 7);

	days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
	timediff -= days * (1000 * 60 * 60 * 24);

	hours = Math.floor(timediff / (1000 * 60 * 60)); 
	timediff -= hours * (1000 * 60 * 60);

	mins = Math.floor(timediff / (1000 * 60)); 
	timediff -= mins * (1000 * 60);

	secs = Math.floor(timediff / 1000); 
	timediff -= secs * 1000;
   if (hours > 0) {
      oObj.HrMin.value = "1";
            oObj.Length.value = hours + (weeks * 56) + (days * 8) + (mins/60);
      }
    else {
      oObj.HrMin.value = "0";
      oObj.Length.value = mins;
    }
	return true; 
}

function PopulateEndDate(oObj) {
    if (oObj.enddate.value < oObj.startdate.value) {
    oObj.enddate.value=oObj.startdate.value;
    }
    return true;
}

function ESetAMPM(oObj) {
    if (oObj.EndHour.value > 0 && oObj.EndHour.value < 7) {
       oObj.EAMPM.value = 'PM'; 
       }
    else {
       if (oObj.EndHour.value == 12) {
          oObj.EAMPM.value = 'PM';
          }
       else
          {
          oObj.EAMPM.value = 'AM';
          }
       }
    return true;
}

function SSetAMPM(oObj) {
    if (oObj.StartHour.value > 0 && oObj.StartHour.value < 7) {
       oObj.SAMPM.value = 'PM'; 
       }
    else {
       if (oObj.StartHour.value == 12) {
          oObj.SAMPM.value = 'PM';
          }
       else
          {
          oObj.SAMPM.value = 'AM';
          }
       }
    return true;
}
<!--[if gte IE 5.5000]>
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }
   try {
		window.attachEvent("onload", correctPNG);
   } catch(e) {}
<!--[endif]-->
	var xpPanel_slideActive = true;	// Slide down/up active?
	var xpPanel_slideSpeed = 15;	// Speed of slide
	
	var dhtmlgoodies_xpPane;
	var dhtmlgoodies_paneIndex;
	
	var savedActivePane = false;
	var savedActiveSub = false;

	var xpPanel_currentDirection = false;
	
	var cookieNames = new Array();
	/*
	These cookie functions are downloaded from 
	http://www.mach5.com/support/analyzer/manual/html/General/CookiesJavaScript.htm
	*/	
	function Get_Cookie(name) { 
	   var start = document.cookie.indexOf(name+"="); 
	   var len = start+name.length+1; 
	   if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
	   if (start == -1) return null; 
	   var end = document.cookie.indexOf(";",len); 
	   if (end == -1) end = document.cookie.length; 
	   return unescape(document.cookie.substring(len,end)); 
	} 
	// This function has been slightly modified
	function Set_Cookie(name,value,expires,path,domain,secure) { 
		expires = expires * 60*60*24*1000;
		var today = new Date();
		var expires_date = new Date( today.getTime() + (expires) );
	    var cookieString = name + "=" +escape(value) + 
	       ( (expires) ? ";expires=" + expires_date.toGMTString() : "") + 
	       ( (path) ? ";path=" + path : "") + 
	       ( (domain) ? ";domain=" + domain : "") + 
	       ( (secure) ? ";secure" : ""); 
	    document.cookie = cookieString; 
	}

	function cancelXpWidgetEvent()
	{
		return false;	
		
	}
	
	function showHidePaneContent()
	{
		var img = this.getElementsByTagName('IMG')[0];
		var numericId = img.id.replace(/[^0-9]/g,'');
		var obj = document.getElementById('paneContent' + numericId);
		if(img.src.toLowerCase().indexOf('up')>=0){
			img.src = img.src.replace('up','down');
			if(xpPanel_slideActive){
				obj.style.display='block';
				xpPanel_currentDirection = (xpPanel_slideSpeed*-1);
				slidePane((xpPanel_slideSpeed*-1), obj.id);
			}else{
				obj.style.display='none';
			}
			if(cookieNames[numericId])Set_Cookie(cookieNames[numericId],'0',100000);
		}else{
			img.src = img.src.replace('down','up');
			if(xpPanel_slideActive){
				if(document.all){
					obj.style.display='block';
					//obj.style.height = '1px';
				}
				xpPanel_currentDirection = xpPanel_slideSpeed;
				slidePane(xpPanel_slideSpeed,obj.id);
			}else{
				obj.style.display='block';
				subDiv = obj.getElementsByTagName('DIV')[0];
				obj.style.height = subDiv.offsetHeight + 'px';
			}
			if(cookieNames[numericId])Set_Cookie(cookieNames[numericId],'1',100000);
		}	
		return true;	
	}
	
	function slidePane(slideValue,id)
	{
		if(slideValue!=xpPanel_currentDirection){
			return false;
		}
		var activePane = document.getElementById(id);
		if(activePane==savedActivePane){
			var subDiv = savedActiveSub;
		}else{
			var subDiv = activePane.getElementsByTagName('DIV')[0];
		}
		savedActivePane = activePane;
		savedActiveSub = subDiv;
		
		var height = activePane.offsetHeight;
		var innerHeight = subDiv.offsetHeight;
		height+=slideValue;
		if(height<0)height=0;
		if(height>innerHeight)height = innerHeight;
		
		if(document.all){
			//activePane.style.filter = 'alpha(opacity=' + (10 + (Math.round((height / subDiv.offsetHeight)*90))) + ')';
		}else{
			var opacity = (height / subDiv.offsetHeight);
			if(opacity==0)opacity=0.01;
			if(opacity==1)opacity = 0.99;
			//activePane.style.opacity = opacity;  // removed: nasty IE bug
		}			
		
		if(slideValue<0){			
			activePane.style.height = height + 'px';
			subDiv.style.top = height - subDiv.offsetHeight + 'px';
			if(height>0){
				setTimeout('slidePane(' + slideValue + ',"' + id + '")',10);
			}else{
				if(document.all)activePane.style.display='none';
			}
		}else{			
			subDiv.style.top = height - subDiv.offsetHeight + 'px';
			activePane.style.height = height + 'px';
			if(height<innerHeight){
				setTimeout('slidePane(' + slideValue + ',"' + id + '")',10);				
			}
			else
			{

		    }		
		}
		
	}
	
	function mouseoverTopbar()
	{
		var img = this.getElementsByTagName('IMG')[0];
		var src = img.src;
		img.src = img.src.replace('.gif','_over.gif');
		
		var span = this.getElementsByTagName('SPAN')[0];
		span.style.color='#428EFF';		
		
	}
	function mouseoutTopbar()
	{
		var img = this.getElementsByTagName('IMG')[0];
		var src = img.src;
		img.src = img.src.replace('_over.gif','.gif');		
		
		var span = this.getElementsByTagName('SPAN')[0];
		span.style.color='';
	}
	
	function initDhtmlgoodies_xpPane(panelTitles,panelDisplayed,cookieArray)
	{
		dhtmlgoodies_xpPane = document.getElementById('xpPane');
		var divs = dhtmlgoodies_xpPane.getElementsByTagName('DIV');
		dhtmlgoodies_paneIndex=0;
		cookieNames = cookieArray;
		for(var no=0;no<divs.length;no++){
			if(divs[no].className=='panel'){
				
				var outerContentDiv = document.createElement('DIV');	
				var contentDiv = divs[no].getElementsByTagName('DIV')[0];
				outerContentDiv.appendChild(contentDiv);	
			
				outerContentDiv.id = 'paneContent' + dhtmlgoodies_paneIndex;
				outerContentDiv.className = 'panelContent';
				var topBar = document.createElement('DIV');
				topBar.onselectstart = cancelXpWidgetEvent;
				var span = document.createElement('SPAN');				
				span.innerHTML = panelTitles[dhtmlgoodies_paneIndex];
				topBar.appendChild(span);
				topBar.onclick = showHidePaneContent;
				if(document.all)topBar.ondblclick = showHidePaneContent;
				topBar.onmouseover = mouseoverTopbar;
				topBar.onmouseout = mouseoutTopbar;
				
				var img = document.createElement('IMG');
				img.id = 'showHideButton' + dhtmlgoodies_paneIndex;
				img.src = 'images/arrow_up.gif';				
				topBar.appendChild(img);
				
				if(cookieArray[dhtmlgoodies_paneIndex]){
					cookieValue = Get_Cookie(cookieArray[dhtmlgoodies_paneIndex]);
					if(cookieValue)panelDisplayed[dhtmlgoodies_paneIndex] = cookieValue==1?true:false;
					
				}
				if(!panelDisplayed[dhtmlgoodies_paneIndex]){
					outerContentDiv.style.height = '0px';
					contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px';
					if(document.all)outerContentDiv.style.display='none';
					img.src = 'images/arrow_down.gif';
				}
								
				topBar.className='topBar';
				divs[no].appendChild(topBar);				
				divs[no].appendChild(outerContentDiv);	
				dhtmlgoodies_paneIndex++;			
			}			
		}
	}	

var dhtmlgoodies_slideSpeed = 100;	// Higher value = faster
var dhtmlgoodies_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var dhtmlgoodies_activeId = false;
function showHideContent(e,inputId)
{
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);
	
	objectIdToSlideDown = false;
	
	if(!answerDiv.style.display || answerDiv.style.display=='none'){

		if(dhtmlgoodies_activeId &&  dhtmlgoodies_activeId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(dhtmlgoodies_activeId,(dhtmlgoodies_slideSpeed*-1));
		}else{
			
			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';
			
			slideContent(numericId,dhtmlgoodies_slideSpeed);
		}
	}else{
		slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));
		dhtmlgoodies_activeId = false;
	}	
}

function slideContent(inputId,direction)
{
	var obj =document.getElementById('dhtmlgoodies_a' + inputId);
	var contentObj = document.getElementById('dhtmlgoodies_ac' + inputId);
	height = obj.clientHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',dhtmlgoodies_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed);				
			}
		}else{
			dhtmlgoodies_activeId = inputId;
		}
	}
}


function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='scrollcontainer'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'dhtmlgoodies_q'+divCounter;
			
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			
			answer.id = 'dhtmlgoodies_a'+divCounter;	
			
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='scrollcontent';
			contentDiv.id = 'dhtmlgoodies_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}		
	}	
}


function FormatPhoneNumber(oObj){
	var re= /\D/;
	// test for this format: (xxx)xxx-xxxx
	var re2 = /^\({1}\d{3}\)\d{3}-\d{4}/; 
	// test for this format: xxx-xxx-xxxx
	//var re2 = /^\d{3}-\d{3}-\d{4}/;
	
		var num=oObj.value;
		var newNum;
		 if (num != "" && re2.test(num)!=true){
		   if (num != ""){
		     while (re.test(num)){
		     num = num.replace(re,"");
		     }
		   }
		
		  if (num.length != 10 && num.length > 0){
		    return 1;
		    }
		   else {
		     // for format (xxx)xxx-xxxx
		     newNum = '(' + num.substring(0,3) + ')' + num.substring(3,6) + '-' + num.substring(6,10);
		     // for format xxx-xxx-xxxx
		     // newNum = num.substring(0,3) + '-' + num.substring(3,6) + '-' + num.substring(6,10);
		     oObj.value=newNum;
		     }
		   }
}
   
	function copyToList(fromList,toList){
		var sel = false;
  		for (i=0;i<fromList.options.length;i++){
    		var current = fromList.options[i];
    		if (current.selected){
      			sel = true;
      			if (current.value == '[Empty]'){
        			alert ('You cannot move this text!');
        			return;
      			}
      			txt = current.text;
      			val = current.value;
      			toList.options[toList.length] = new Option(txt,val);
      			fromList.options[i] = null;
      			i--;
    		}
  		}
		if (!sel) ;
	}
		
		
	function allSelect(oObj)
	{
  		var List = oObj;
  		if (List.length > 0 && List.options[0].value == '[Empty]') return;
  		for (i=0;i<List.length;i++)
  		{
     		List.options[i].selected = true;
  		}
	}
   function ignoreError() 
   {
     return true;
   }
   window.onerror = ignoreError

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;
	}

	var aryRequired = new Array();
    var intArrayCount = 0;

    window.name = 'OasisCRM';
    
    function defineRequired(strElementName, strDisplayMessage, blnIsEmail, blnIsNumber)
    {
        var objRequired = new Object();
        objRequired.ElementName = strElementName;
        objRequired.DisplayMessage = strDisplayMessage;
        objRequired.IsEmail = blnIsEmail;
        objRequired.IsNumber = blnIsNumber;
        aryRequired[intArrayCount] = objRequired;
        intArrayCount++;
    }
    
    function checkForm(objForm)
    {
        //web tv bug fix
        if (navigator.userAgent.indexOf("WebTV") == -1) {
          for (var i = 0; i < aryRequired.length; i++) {
            var blnFail = true; 
            var objElement = eval("objForm." + aryRequired[i].ElementName);
           
            if (objElement.length && !objElement.type && document.images) {
              //looping through element array
              for (var x = 0; x < objElement.length; x++) {
                if (objElement[x].checked && objElement[x].value != "") blnFail = false;
              } 
            } 
            else {
              if (objElement.value != "") {
                if (aryRequired[i].IsEmail) { if (CheckEmail(objElement.value)) blnFail = false; }
                else if (aryRequired[i].IsNumber) { if (!isNaN(objElement.value)) blnFail = false; }
                else blnFail = false;
              }
            }
            if (blnFail) {  
              alert(aryRequired[i].DisplayMessage);
              if (objElement.length && !objElement.type) objElement[0].focus();
              else objElement.focus();
              return false;
            } 
          }
        // all elements passed, submit form
        }
        return true;
    }
    
    function CheckEmail(strData) 
    {
        var posAt = strData.indexOf("@")
        var strName = strData.substring(0, posAt)
        var strDomain = strData.substring(posAt+1, strData.length)
        var posDot = strDomain.indexOf(".")
        var strSubDomain = strDomain.substring(posDot+1,strDomain.length)
        
        if ( strName=="" || strDomain=="" || posDot < 1 || strSubDomain =="") return false;
        else return true;
    }

    // Change these to the inputs you want required
    //defineRequired("inputBox","The Input Box is required field. Please fill it in.");
    function ShowTimeoutWarning ()
	{
       alert( "You will be automatically logged out in fifteen minutes due to inactivity." );
	}

	function SnapShot(cObj)
	{ 
	  var disp_setting="toolbar=no,location=no,directories=no,menubar=yes,dependent=yes,resizable=yes,"; 
		  disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; 
	  var content_vlue = document.getElementById(cObj).innerHTML; 
	  
	  var docprint=window.open("about:blank",cObj,disp_setting); 
	   docprint.document.open(); 
	   docprint.document.write('<html><head><title>Oasis-CRM&trade;&nbsp;Snapshot</title>'); 
       docprint.document.write('<LINK REL="stylesheet" HREF="Oasis3IE.css" TYPE="text/css" MEDIA="screen">');
	   docprint.document.write('<BGSOUND SRC="images/click.wav">');
	   docprint.document.write('</head><body style="text-align:left;">');          
	   docprint.document.write(content_vlue);          
	   docprint.document.write('</body></html>'); 
	   docprint.document.close(); 
	   docprint.focus(); 
	}
	
	
   function AjaxLookup(cDiv, reqstr) 
   {
	       if (iTimerID>0) {
			   req.abort();
		   }
		   req = new XMLHttpRequest(); 
		   req.onreadystatechange = ajaxreturn;
		   req.open('POST', reqstr ,true); 
		   if (iTimerID != 0) clearTimeout(iTimerID);
		   iTimerID = setTimeout("ajaxreturn", 250);
		   document.getElementById(cDiv).innerHTML = "<img src='images/loading.gif' border='0' align='middle'>";
		   req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		   req.send("Process=1");

		   function ajaxreturn() {
				if (req.readyState == 4)  {
					 var ctext = req.responseText;
					 document.getElementById(cDiv).innerHTML = ctext;
					 clearTimeout(iTimerID);
					 return 0;
					 }
					 nitem++;
					 var dCurrent = new Date();
					 if (Math.floor((dCurrent.getTime()-dStart.getTime())/1000) < 30) {
						}
					 else
						{
						  clearTimeout(iTimerID);
						}
		   }
}

	function AJAX_PrintSerial(strObject, strInv) 
	{
		oObj = eval('document.POInfo.SerialNo');
		cSerialNo = oObj.value;

		oObj = eval('document.POInfo.ManufacturerSerialNo');
		cManufacturerSerialNo = oObj.value;

		oObj = eval('document.POInfo.LabelID');
		cLabelID = oObj.options[oObj.selectedIndex].value;

		var reqstr = 'include/PrintSerial.asp?FormID='+cLabelID+'&ID='+strInv+'&SerialNo='+cSerialNo+'&ManufacturerSerialNo='+cManufacturerSerialNo;
		hWnd = window.open(reqstr,'PrintSerial','alwaysRaised,dependent,toolbar=no,resizable=yes,scrollbars=yes,titlebar=no,status=no');
		hWnd.focus();
		//if (confirm('Did the label print correctly? (Select [Cancel] to reprint the label)')) {
		//   hWnd.close(); }
		//   else {
		//   hWnd.print();
		//   }
}

	function AJAX_GenerateSerial(strButton,strObject, strInv)
	   {
		   oObj = eval('document.POInfo.'+strObject);
		   oButton = eval('document.POInfo.'+strButton);
		   oButton.disabled='disabled';
		   var reqstr = 'include/GenerateSerial.asp?ID='+strInv;
		   req = new XMLHttpRequest(); 
		   req.onreadystatechange = ajaxreturn;
		   req.open('POST', reqstr ,true); 
		   if (iTimerID != 0) clearTimeout(iTimerID);
		   iTimerID = setTimeout("ajaxreturn", 250);
		   req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		   req.send("Process=1");
	
			   function ajaxreturn() {
					if (req.readyState == 4)  {
						 var ctext = req.responseText;
						 oObj.value=req.responseText;
						 clearTimeout(iTimerID);
						 return 0;
						 }
						 nitem++;
						 var dCurrent = new Date();
						 if (Math.floor((dCurrent.getTime()-dStart.getTime())/1000) < 30) {
							}
						 else
							{
							  clearTimeout(iTimerID);
							}
			   }
	
}

 function ProductSearch() {
	var oFrame = document.getElementById('ProductListing');
	oFrame.innerHTML = "<img src='images/loadingajax_ani.gif' border=0 height=32 width=32>"
	var cSelections = "";
	var modlist = document.getElementById('ModList').value;
	var basecode = document.getElementById('BaseCode').value;
	var basecategory = document.getElementById('BaseCategory').value;
if (modlist.length == 0) return 0;
	if (basecode.length == 0) return 0;
	
	var nMulti = modlist.indexOf(",")
	if (nMulti < 0) {
		oItem = document.getElementById(modlist);
		cValue = oItem.value;
		if (cValue.length > 0) {
			cProdList = cProdList + cValue + "*";
		}
	}
    else
	{
		var aList = modlist.split(",");
		for(i = 0; i < aList.length; i++)
		{
		try {
			   oObj = document.getElementById(aList[i]);
			   oItem = eval('document.' +oObj.form.name+'.'+oObj.name);
			
			   if (oItem.length>0) {
				   var cName = oObj.name;
				   var cSlotValue = ButtonValue(oItem);
				   if (cSlotValue.length>0) {
				      var aSlotData = cName.split("-");
				      cSelections = cSelections + cSlotValue + "*"
				   }
			   }
			   else {
				   if (oObj.checked) 
				   {
					  var cName = oObj.name;
					  var cSlotValue = oObj.value
					  var aSlotData = cName.split("-");
					  cSelections = cSelections + cSlotValue + "-" + aSlotData[1] + "*"
					}
			   }
		   } catch(e) {}
		}
	}

   var reqstr = 'include/ESearch.asp?BASECODE='+basecode+'&SELECTIONS='+cSelections+'&CATEGORY='+basecategory;
   if (window.ActiveXObject){
	  req=new ActiveXObject("Microsoft.XMLHTTP");
	  if (! req){
			req=new ActiveXObject("Msxml2.XMLHTTP");
	  }
   }
   req.onreadystatechange = ajaxreturn;
   req.open('POST', reqstr ,true); 
   if (iTimerID != 0) clearTimeout(iTimerID);
   iTimerID = setTimeout("ajaxreturn", 150);
   req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
   req.send("Process=1");

	   function ajaxreturn() {
			if (req.readyState == 4)  {
				 var ctext = req.responseText;
				 oFrame.innerHTML = ctext;
			}
	   }
}

function ProductUpdate()
 {

	  var req = new XMLHttpRequest(); 
      var modlist = document.getElementById('ModList').value;
      try {
      var optionlist = document.getElementById('OptionList').value;
      } catch(e) {
        optionlist = "";
      }
      var basecode = document.getElementById('BaseCode').value;
      var oPriceFrame = document.getElementById('PriceFrame');
      var oPhotoFrame = document.getElementById('PhotoFrame');
      var nBasePrice = 0;
      try {
            var oBasePrice = document.getElementById('BasePrice');
            nBasePrice = oBasePrice.value;
      } catch(e) {}
      var cProdList = basecode + "*";
      var cOptionList = "";
      if (modlist.length == 0) return 0;
      if (basecode.length == 0) return 0;
      oPriceFrame.innerHTML = "<img src='images/loadingajax_ani.gif' border=0 height=32 width=32>"

      var nMulti = modlist.indexOf(",")
      
      var aList = modlist.split(",");
      var cValue = "";
      for(i = 0; i < aList.length; i++)
      {
            try {
                  oObj = document.getElementById(aList[i]);
                  oItem = eval('document.' +oObj.form.name+'.'+oObj.name);
                  cValue = ButtonValue(oItem);
            } catch(e) {}
            if (cValue.length == 0) {
               try {
                     oItem = document.getElementById(aList[i]);
                     cValue = oItem.value;
               } catch(e) {}
            }
            if (cValue.length > 0) {
                  cProdList = cProdList + cValue + "*";
            }
      }     

      if (optionlist.length > 0) {
            var nMulti = optionlist.indexOf(",")
            if (nMulti < 0) {
               oItem = eval('document.' +oObj.form.name+'.'+optionlist);
               cValue = oItem.value;
                  if (cValue.length > 0) {
                        cOptionList = cOptionList + cValue + "*";
                  }
            }
            else
            {
                  var aList = optionlist.split(",");
                  for(i = 0; i < aList.length; i++)
                  {
                        oObj = document.getElementById(aList[i]);
                        oItem = eval('document.' +oObj.form.name+'.'+oObj.name);
                        cValue = oItem.value;
                        if (cValue.length > 0) {
                              cOptionList = cOptionList + cValue + "*";
                        }
                  }           
            }
      }
   var reqstr = 'include/ProductData.asp?ID='+cProdList+'&OPTION='+cOptionList+"&BASEPRICE="+nBasePrice;
   req.onreadystatechange = ajaxreturn;
   req.open('POST', reqstr ,true); 
   if (iTimerID != 0) clearTimeout(iTimerID);
   iTimerID = setTimeout("ajaxreturn", 150);
   req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
   req.send("Process=1");

         function ajaxreturn() {
                  if (req.readyState == 4)  {
                         var ctext = req.responseText;
						 var nOutofStock = ctext.indexOf(String.fromCharCode(7));
						 if (nOutofStock > 0) {
                              oPriceFrame.innerHTML = "Temporarily Out of Stock.. <br>"; 
                              document.getElementById('Add2Order').disabled='disabled';
							  clearTimeout(iTimerID);
							  return 0;
						 }
                         var nReject = ctext.indexOf(String.fromCharCode(8));
                         if (nReject > 0) {
                              alert('Sorry, this product is not available in the configuration you have selected.  Please select a different configuration for your product.');
                              oPriceFrame.innerHTML = "Not available in this configuration .. <br><font size=1></b>" + ctext.replace(String.fromCharCode(8),"") + "</font>"; 
                              document.getElementById('Add2Order').disabled='disabled';
                         }
                         else
                         {
                            aSplit = ctext.split(String.fromCharCode(9));     
                              document.getElementById("ItemCode").value=aSplit[0];
                              oPriceFrame.innerHTML = aSplit[1];
                              oPhotoFrame.innerHTML = aSplit[2];
                              document.getElementById('Add2Order').disabled='';
                              cName = document.getElementById('Add2Order').form.name;
                              try {
                              oItem = eval('document.' + cName + '.ShowMe');
                              oItem[0].checked = true;
                              ItemDetail(0);
                         } catch(e) {
                         }
}
                         clearTimeout(iTimerID);
                         return 0;
                         }
                         nitem++;
                         var dCurrent = new Date();
                         if (Math.floor((dCurrent.getTime()-dStart.getTime())/1000) < 30) {
                              }
                         else
                              {
                                clearTimeout(iTimerID);
                              }
         }
 }

function ButtonValue(btn) {
    var cnt = -1;
	try {
		for (var i=btn.length-1; i > -1; i--) {
			if (btn[i].checked) {cnt = i; i = -1;}
		}
		if (cnt > -1) return btn[cnt].value;
		else return '';
	} catch(e) {
		return '';
	}
}

function tabOnEnter (field, evt) {
	var keyCode = document.layers ? evt.which : document.all ?
	evt.keyCode : evt.keyCode;
	if (keyCode != 13)
	return true;
	else {
	getNextElement(field).focus();
	return false;
}
}
	function getNextElement (field) {
	var form = field.form;
	for (var e = 0; e < form.elements.length; e++)
	if (field == form.elements[e])
	break;
	return form.elements[++e % form.elements.length];
}

 function FormatNumber (obj, decimal) {
	 //decimal  - the number of decimals after the digit from 0 to 3
//-- Returns the passed number as a string in the xxx,xxx.xx format.
	   anynum=eval(obj.value);
	   divider =10;
	   switch(decimal){
			case 0:
				divider =1;
				break;
			case 1:
				divider =10;
				break;
			case 2:
				divider =100;
				break;
			default:  	 //for 3 decimal places
				divider =1000;
		}

	   workNum=Math.abs((Math.round(anynum*divider)/divider));

	   workStr=""+workNum

	   if (workStr.indexOf(".")==-1){workStr+="."}

	   dStr=workStr.substr(0,workStr.indexOf("."));dNum=dStr-0
	   pStr=workStr.substr(workStr.indexOf("."))

	   while (pStr.length-1< decimal){pStr+="0"}

	   if(pStr =='.') pStr ='';

	   //--- Adds a comma in the thousands place.    
	   if (dNum>=1000) {
		  dLen=dStr.length
		  dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen)
	   }

	   //-- Adds a comma in the millions place.
	   if (dNum>=1000000) {
		  dLen=dStr.length
		  dStr=parseInt(""+(dNum/1000000))+","+dStr.substring(dLen-7,dLen)
	   }
	   retval = dStr + pStr
	   //-- Put numbers in parentheses if negative.
	   if (anynum<0) {retval="("+retval+")";}

	  
	//You could include a dollar sign in the return value.
	  //retval =  "$"+retval
	  
	  obj.value = retval;
 }
 
function IsNumeric(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 CheckDateInput(input)
{
	var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
	var returnval=false
	if (!validformat.test(input.value))
	alert("Invalid Date Format. Please correct and submit again.")
	else{ //Detailed check for valid date ranges
	var monthfield=input.value.split("/")[0]
	var dayfield=input.value.split("/")[1]
	var yearfield=input.value.split("/")[2]
	var dayobj = new Date(yearfield, monthfield-1, dayfield)
	if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
	alert("Invalid Day, Month, or Year range detected. Please correct and submit again.")
	else
	returnval=true
}
	if (returnval==false) input.select()
	return returnval
}