function handleHttpResponse() {
  if (http.readyState == 4) {
	 scstart = http.responseText.indexOf("mrecode:");
	 scend = http.responseText.indexOf('mend');
	 results = http.responseText.substr(scstart+8,scend-scstart-8);
	
	 WriteLayer ('curcount',null,results);

  }
}

function WriteLayer(ID,parentID,sText) { 
 if (document.layers) { 
   var oLayer; 
   if(parentID){ 
     oLayer = eval('document.' + parentID + '.document.' + ID + '.document'); 
   }else{ 
     oLayer = document.layers[ID].document; 
   } 
   oLayer.open(); 
   oLayer.write(sText); 
   oLayer.close(); 
 } 
 else if (parseInt(navigator.appVersion)>=5&&navigator.appName=="Netscape") { 
   document.getElementById(ID).innerHTML = sText; 
 } 
 else if (document.all) document.all[ID].innerHTML = sText 
} 
 function getHTTPObject() {

  var xmlhttp;

  /*@cc_on

  @if (@_jscript_version >= 5)

    try {

      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e) {

      try {

        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (E) {

        xmlhttp = false;

      }

    }

  @else

  xmlhttp = false;

  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }

  return xmlhttp;

}
	var http = getHTTPObject(); 
	
function updatepropcount() {

  var url = "getpropcount.cfm?"; // The server-side script

	url += updateSubmitParams();
	//alert(url);
	//window.open(url,'mywindow','width=650,height=500,toolbar=yes, location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
	http.open("GET", url, true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);


 }
 
 function updateSubmitParams (){
	var paramString = 'commid='; 
	//var for_sale;
	var commid = document.getElementById("commid").value;
	var Property_Class_ID = 'Property_Class_ID';
	var PROP_TYPE = 'PROP_TYPE';

//  alert(document.getElementById("for_lease_button").checked );
  if(document.getElementById("for_lease_button").checked == true){
	  var PROP_TYPE = checkboxval("PROP_TYPE","");
	 // alert(prop_type);
	  //for_sale = 7;
	  if(PROP_TYPE !=''){
	  PROP_TYPE = PROP_TYPE.concat("");
	  }
	  var LEASE_PRICE_MIN = document.getElementById("LEASE_PRICE_MIN").value;
	  var LEASE_PRICE_MAX = document.getElementById("LEASE_PRICE_MAX").value;
  }else if (document.getElementById("for_sale_button").checked == true){
  	//document.getElementById("for_sale").value = 1;
	//for_sale = 1;
   	var Property_Class_ID =checkboxval("Property_Class_ID",""); 
	//alert(Property_Class_ID);
 	 if(Property_Class_ID != ''){
		 Property_Class_ID = Property_Class_ID.concat(0);
		// alert(Property_Class_ID);
	 }
	  var LISTING_PRICE_MIN = document.getElementById("LISTING_PRICE_MIN").value;
 // alert
  		var LISTING_PRICE_MAX = document.getElementById("LISTING_PRICE_MAX").value;
  }
  var BEDROOM_NUM = document.getElementById("BEDROOM_NUM").value;
  var FULL_BATH_NUM = document.getElementById("FULL_BATH_NUM").value;
  var SQURE_FEET_MIN = document.getElementById("SQURE_FEET_MIN").value;
  var SQURE_FEET_MAX = document.getElementById("SQURE_FEET_MAX").value;
  var GARAGE_NUM = document.getElementById("GARAGE_NUM").value;
  var GARAGE_DESC = document.getElementById("GARAGE_DESC").value;
  var STORIES = document.getElementById("STORIES").value;

  var NEW_CONSTR = document.getElementById("NEW_CONSTR").value;
  var YEAR_BUILT =document.getElementById("YEAR_BUILT").value;
  var subdivision = document.getElementById("subdivision").value;
  var PRIVATE_POOL = '';
  var AREA_POOL = '';
  var GOLF = '';
  var VIRTUAL_TOURS = '';
  var OPEN_HOUSES = '';
  

  if(document.getElementById("PRIVATE_POOL").checked ==true ){
   PRIVATE_POOL = document.getElementById("PRIVATE_POOL").value;
  }
   if(document.getElementById("AREA_POOL").checked ==true){
   AREA_POOL =document.getElementById("AREA_POOL").value;
  }
   if(document.getElementById("GOLF").checked == true){
   GOLF = document.getElementById("GOLF").value;
  }
   if(document.getElementById("VIRTUAL_TOURS").checked == true ){
   VIRTUAL_TOURS = document.getElementById("VIRTUAL_TOURS").value;
  }
   if(document.getElementById("OPEN_HOUSES").checked == true){
   OPEN_HOUSES = document.getElementById("OPEN_HOUSES").value;
  }

	paramString= paramString+escape(commid);//must have commid value
	
	
	 if(document.getElementById("for_lease_button").checked == true){
	 	paramString= paramString.concat('&for_sale=7');
		if (PROP_TYPE != '' ){
			paramString = paramString.concat('&PROP_TYPE=');
			paramString = paramString.concat(PROP_TYPE);
		}
		if (LEASE_PRICE_MIN != ''){
			paramString = paramString.concat('&LEASE_PRICE_MIN=');
			paramString = paramString.concat(LEASE_PRICE_MIN);
		}
		if (LEASE_PRICE_MAX != ''){
			paramString = paramString.concat('&LEASE_PRICE_MAX=');
			paramString = paramString.concat(LEASE_PRICE_MAX);
		}
	}else{
			paramString= paramString.concat('&for_sale=1');
		if (Property_Class_ID != ''){
			paramString = paramString.concat('&Property_Class_ID='); 
			paramString = paramString.concat(Property_Class_ID);
		}
		if (LISTING_PRICE_MIN != ''){
			paramString = paramString.concat('&LISTING_PRICE_MIN='); 
			paramString = paramString.concat(LISTING_PRICE_MIN);
		}
		if (LISTING_PRICE_MAX != ''){
			paramString = paramString.concat('&LISTING_PRICE_MAX=');
			paramString = paramString.concat(LISTING_PRICE_MAX);
		}
	}
	if (BEDROOM_NUM != ''){
		paramString = paramString.concat('&BEDROOM_NUM=');
		paramString = paramString.concat(BEDROOM_NUM);
	}
	if (FULL_BATH_NUM != ''){
		paramString = paramString.concat('&FULL_BATH_NUM=');
		paramString = paramString.concat(FULL_BATH_NUM);
	}
	if (SQURE_FEET_MIN != ''){
		paramString = paramString.concat('&SQURE_FEET_MIN=');
		paramString = paramString.concat(SQURE_FEET_MIN);
	}
	if (SQURE_FEET_MAX != ''){
		paramString = paramString.concat('&SQURE_FEET_MAX=');
		paramString = paramString.concat(SQURE_FEET_MAX);
	}
	if (GARAGE_NUM != ''){
		paramString = paramString.concat('&GARAGE_NUM=');
		paramString = paramString.concat(GARAGE_NUM);
	}
	if (GARAGE_DESC != ''){
		paramString = paramString.concat('&GARAGE_DESC=');
		paramString = paramString.concat(GARAGE_DESC);
	}
	if (STORIES != ''){
		paramString = paramString.concat('&STORIES=');
		paramString = paramString.concat(STORIES);
	}
	
	
	if (PRIVATE_POOL != ''){
		paramString = paramString.concat('&PRIVATE_POOL=');
		paramString = paramString.concat(PRIVATE_POOL);
	}
	if (AREA_POOL != ''){
		paramString= paramString.concat('&AREA_POOL=');
		paramString = paramString.concat(AREA_POOL);
	}
	if (NEW_CONSTR != ''){
		paramString = paramString.concat('&NEW_CONSTR=');
		paramString = paramString.concat(NEW_CONSTR);
	}
	if (YEAR_BUILT != ''){
		paramString = paramString.concat('&YEAR_BUILT=');
		paramString = paramString.concat(YEAR_BUILT);
	}
	if (GOLF != ''){
		paramString = paramString.concat('&GOLF=');
		paramString = paramString.concat(GOLF);
	}
	if (VIRTUAL_TOURS != ''){
		paramString = paramString.concat('&VIRTUAL_TOURS=');
		paramString = paramString.concat(VIRTUAL_TOURS);
	}
	if (OPEN_HOUSES != ''){
		paramString = paramString.concat('&OPEN_HOUSES=');
		paramString = paramString.concat(OPEN_HOUSES);
	}
	if (subdivision != ''){
		paramString = paramString.concat('&subdivision=');
		paramString = paramString.concat(subdivision);
	}
	
	return paramString;
}
 


function searchformsubmit(){ 
var url = "dispSearch.cfm?"; // The server-side script
	url += updateSubmitParams();
	url += '&listSRND=yes';

  // alert(url);
   
   document.location =url;
//	showdiv('Child1');
} 
	/*
	 var xhr; 
		
    try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
    catch (e)    {
        try {   xhr = new ActiveXObject('Microsoft.XMLHTTP'); 
		}
        catch (e2)   {
          try {  xhr = new XMLHttpRequest();     }
          catch (e3) {  xhr = false;   }
        }
     }
  
    xhr.onreadystatechange  = function()  { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) {
                 // document.ajax.dyn="Received:"  + xhr.responseText; 
				// alert('recived'+ xhr.responseText);
				 SucceededCallback(xhr.responseText);
			  }
              else {
                // document.ajax.dyn="Error code " + xhr.status;
				alert('Error occured:'+ xhr.status);
			  }
         }
    }; 
//	alert(url);
   xhr.open("GET", url,  true); 
   xhr.send(null); 
  */

function SucceededCallback(response){
	//alert('i am here in call back function');
    var result = response;
	//alert(result);
  //  var icon = options.params.icon;
  //  alert(icon);

    var totalcnt = 0;
    var pushPinShape;

    try{

        var points = result;
        propIcon = "graphics/smbluePointer.gif"
        
        if(points.length > 0 ) {
          //  alert(points.length);
            var latLongTokens = points.split('|');
            var veLatLongs = new Array(latLongTokens.length -1);
            //alert(latLongTokens.length);
            var centerLatLong;
            totalcnt = latLongTokens[0].split(',')[1];
			
			var listingvewhtml = "<table width='765px' border='0' class='table2' cellpadding='0' cellspacing='0'>"+
                "<tr><td align='left' valign='top'>"+
				"<div id='toolTipLayer' style='VISIBILITY:hidden; POSITION:absolute; z-index: 99;'></div>"+
                "<table width='100%' border='0' cellpadding='5' cellspacing='1'><tr >"+
                "<th align='left' valign='top' class='smGrayBold' ></th>"+
                "<th align='left' valign='top' class='smGrayBold' >MLNUM</th>"+
                "<th align='left' valign='top' class='smGrayBold' >Address</th>"+
                "<th align='left' valign='top' class='smGrayBold' >Subdivision</th>"+
                "<th align='left' valign='top' class='smGrayBold' >Listing Price</th>"+
                "<th align='left' valign='top' class='smGrayBold' >Bed/Bath</th>"+
				"<th align='center' valign='top' class='smGrayBold' >Status</th></tr>";
		  //new for loop
		  var detailurl = 'http://search.har.com/engine/dispSearch.cfm';
		  
		   for(index = 1; index <= veLatLongs.length-1; index++)      {
			var latitude = latLongTokens[index].split(',')[0];
			var longitude = latLongTokens[index].split(',')[1];
			var address  = latLongTokens[index].split(',')[2];
			var mlnum  = latLongTokens[index].split(',')[3];
			var pid  = latLongTokens[index].split(',')[4];
			var pPrice  = latLongTokens[index].split(',')[5];
			var propclass = latLongTokens[index].split(',')[6];
			var bed = latLongTokens[index].split(',')[7];
			var bath  = latLongTokens[index].split(',')[8];
			var sqft = latLongTokens[index].split(',')[9];
			var sqftsrc = latLongTokens[index].split(',')[10];
			var PropStatus  = latLongTokens[index].split(',')[11];
			var city  = latLongTokens[index].split(',')[12];
			var zip  = latLongTokens[index].split(',')[13];
			var bednum  = latLongTokens[index].split(',')[14];
			var bathnum  = latLongTokens[index].split(',')[15];
			var subdivision = latLongTokens[index].split(',')[16];
			var agentname  = latLongTokens[index].split(',')[17];
			var officename = latLongTokens[index].split(',')[18];
			//		alert(latitude+ ','+ longitude+','+pid);
			//number formating
			pPrice = '$'+new NumberFormat(pPrice).toFormatted();
			sqft = new NumberFormat(sqft).toFormatted();
			
			if (pid == 7){
				propIcon = "MapSearch/images/smgooglePointer.gif";
				}
			else {
				propIcon = "/MapSearch/images/smbluePointer.gif";
							
			}
			
			veLatLongs[index] = new VELatLong(latitude, longitude);
			if(pid != 6 && pid !=2){
							
				propString = "<div style='width:200px'><iframe src='/mapsearch/sliderollenh.cfm?mlnum="+mlnum+"&latitude="+latitude+"&longitude="+longitude+"&zipcdoe="+zip+"&MAP_address="+address+"&pid="+pid+"' width='200' height='155px' scrolling='no' frameborder='0' marginwidth='0' marginheight='0'></iframe><div  id='propDetailDiv' style='font-size:10px; background-color:ffffff;width:200px'>"+"<span class='mdBlueBold'>"+address+"<br></span> "+city+', '+zip+"<br>"+pPrice+" (" +propclass+")- " + PropStatus 

				if(bed != '')
					propString = propString +"<br>"+bed;
				if(bath != '')
					propString = propString +" / "+bath;
			
				
				if(sqft != '')
					propString = propString +"<br>SQFT: "+sqft;
				if(sqftsrc != '')
					propString = propString +sqftsrc;
			

				propString = propString +"<br><a href='"+detailurl+"?mlnum="+mlnum+"&class="+pid+"&sType=0' target='new'><img src='http://www.har.com/SeniorLiving/graphics/btnDetails.gif' border='0'></a>"

		}
		if(pid ==6 || pid== 2){
			propString = "<div style='width:210px'><iframe src='/mapsearch/multiLists.cfm?mlnum="+mlnum+"&latitude="+latitude+"&longitude="+longitude+"&zipcdoe="+zip+"&MAP_address="+address+"&pid="+pid+"' width='200px' height='360px'  scrolling='auto' frameborder='0' marginwidth='0' marginheight='0'></iframe>"
		}

// I am here

listingvewhtml += "<tr onmouseover='changeClass(this,\"hoverLightBlue\");ddrivetip(\"<div class=iconKey><b>Listing Broker:</b> <span class=none>"+officename+"</span><br> <b>Listing Agent:</b> "+agentname+"</div>\",350);' style='CURSOR: hand;'	class='whiteBG' onmouseout='changeClass(this);hideddrivetip()'>"+
                    "<td class='smGray' vAlign='top' align='left'><input type='checkbox' name='listMLNUM' value='"+mlnum+"' onclick='checkNumber(this)'></td>"+
					"<td class='smGray' vAlign='top' align='left'><a href='http://search.har.com/engine/dispSearch.cfm?mlnum="+mlnum+"' target='_blank'>"+mlnum+"</a></td>"+
					
                    "<td class='smGray' vAlign='top' align='left'>"+address+"</td>"+
                    "<td class='smGray' vAlign='top' align='left'>"+subdivision+"</td>"+
                    "<td class='smGray' vAlign='top' align='middle'>"+ pPrice+"</td>"+
                    "<td class='smGray' vAlign='top' align='middle'>"+ bed +"/"+ bath +"</td>"+
                    "<td class='smGray' vAlign='top' align='center' >"+ PropStatus +"</td></tr>";


propString = propString +"<br>Drive Direction <a  href=\"javascript:showDriveDiv('drivedivfrom');\">From Here</a>  <a href=\"javascript:showDriveDiv('drivedivto');\">To Here</a>";
propString = propString +"<div>";
var driveDivHTMLfrom = "";
driveDivHTMLfrom = driveDivHTMLfrom +"<div id='drivedivfrom' style='display:none;width:200px;backgroudcolor:ffffff;font-size:10px;font-family:Arial'><input style='font-size:10px;font-family:Arial' id='txtFrom' type='text' name='txtFrom' value=' "+address+','+city+','+zip+"' size='40'>"
driveDivHTMLfrom = driveDivHTMLfrom +"<br>  To:<INPUT style='font-size:10px;font-family:Arial' id='fromtxtTo' type='text' name='fromtxtTo' value='' size='40'>"

driveDivHTMLfrom = driveDivHTMLfrom +"<br><INPUT  style='font-size:10px;font-family:Arial' id='find' type='button' value='Find' onclick=\"FindLoc('from');\" ></div>"

var driveDivHTMLto = "";
driveDivHTMLto = driveDivHTMLto +"<div id='drivedivto' style='display:none;width:200px;backgroudcolor:ffffff;font-size:10px;font-family:Arial'><input style='font-size:10px;font-family:Arial' id='totxtFrom' type='text' name='totxtFrom' value='' size='40'>"
driveDivHTMLto = driveDivHTMLto +"<br>  To:<INPUT style='font-size:10px;font-family:Arial' id='txtTo' type='text' name='txtTo' value=' "+address+','+city+','+zip+"' size='40'>"

driveDivHTMLto = driveDivHTMLto +"<br><INPUT  style='font-size:10px;font-family:Arial' id='find' type='button' value='Find' onclick=\"FindLoc('to');\" ></div>"

propString = propString +driveDivHTMLto + driveDivHTMLfrom+"</div></div>";


		var shape = new VEShape(VEShapeType.Pushpin, veLatLongs[index]);

         //Set the icon
         shape.SetCustomIcon(propIcon);
         
         //Set the info box
       //  map.ClearInfoBoxStyles();
	   if(pid != 6 && pid !=2){
         shape.SetTitle("<font face='Arial, Helvetica, sans-serif' size='1px' color='666666'>"+address+"</font>");
	   }
         shape.SetDescription(propString);
         
         //Add the shape the the map
    
				
				try{
				     map.AddShape(shape);
				
				}
				catch(e){}
				
		
			
			/*
	 	if(pid != 6 && pid !=2){
         proptTitle = "<font face='Arial, Helvetica, sans-serif' size='1px' color='666666'>Property Information</font>";
	   }else{
	   proptTitle = "";
	   }
				
			AddClickPin(mlnum,veLatLongs[index], propIcon, proptTitle, propString);
			
			*/
				
        }//end for
         
             listingvewhtml+="</table></td></tr></table>";
		//	 alert(listingvewhtml);
            document.getElementById('listingview').innerHTML = listingvewhtml;
        }// end if has result
        
  
	
    }catch(err){
       
    }
    
    
}

//end succeededCallback function;

function checkboxval(boxname, boxval){
	var counter = 0;
	var i;
	var Property_Class_ID = 'Property_Class_ID';
	var PROP_TYPE = 'PROP_TYPE';
	if(document.getElementById('for_sale_button').checked ==true){
		for(i=1;i<=6;i++){
			//alert(document.getElementById(Property_Class_ID+i).checked);
			if(document.getElementById(Property_Class_ID+i).checked == true){
				counter++;
				boxval = boxval.concat(document.getElementById(Property_Class_ID+i).value);
				boxval = boxval.concat(',')
			}
		}
}else if(document.getElementById('for_lease_button').checked == true){
		for(i=1;i<=3;i++){
				if(document.getElementById(PROP_TYPE+i).checked == true){
				counter++;
				boxval = boxval.concat(document.getElementById(PROP_TYPE+i).value);
				boxval = boxval.concat(',')
				}
			}
		boxval =boxval.concat("'end'");	
}	
//alert('counter'+counter);
//alert(boxval);
	if(counter == 0){
		alert("You have to select at least one property type.");
		return (false);
	}
	else{
		return (boxval);
	}

}
function showdiv(divid) {
	obj = document.getElementById(divid);
	if(obj.style.display == 'none') {
		obj.style.display = '';
	}
	else {
		obj.style.display = 'none';
	}
}
function showBuyDiv(ival){
	//if(obj.checked){
	//searchform.for_sale.value = 1;
	var Property_Class_ID = 'Property_Class_ID';
	var PROP_TYPE = 'PROP_TYPE';
		document.getElementById("divBuy").style.display = '';
		document.getElementById("divLease").style.display = 'none';
		document.getElementById("LEASE_PRICE_MIN").selectedIndex = 0;
		document.getElementById("LEASE_PRICE_MAX").selectedIndex = 0;
		document.getElementById("for_sale").value  = 1;
		document.getElementById("for_lease_button").checked = false;
		for(i=1;i<4;i++){
			document.getElementById(PROP_TYPE+i).checked =false;
		}
		if(ival==0){
			for(i=1;i<7;i++){
			document.getElementById(Property_Class_ID+i).checked =true;
			}
		}

	//}
	//fnClearFormObjects(searchform);
	updatepropcount();
}
function showLeaseDiv(ival){
	//	alert(document.getElementById("for_sale").value);
	var Property_Class_ID = 'Property_Class_ID';
	var PROP_TYPE = 'PROP_TYPE';
	document.getElementById("for_sale").value = 7;
	document.getElementById("for_sale_button").checked = false;
	document.getElementById("divLease").style.display = '';
	document.getElementById("divBuy").style.display = 'none';
	document.getElementById("LISTING_PRICE_MIN").selectedIndex = 0;
	document.getElementById("LISTING_PRICE_MAX").selectedIndex = 0;
	
	
	for(i=1;i<=6;i++){
	document.getElementById(Property_Class_ID+i).checked =false;
	}
	if(ival==0){
		for(i=1;i<=3;i++){
			document.getElementById(PROP_TYPE+i).checked =true;
		}
	}	
	//fnClearFormObjects(searchform);
	//searchform.for_sale.value = 7;
	
	updatepropcount();
}


function flipdiv(divid){
		whichviewmap = document.getElementById('mmapview');
		whichviewlisting = document.getElementById('mlistingview');
	if (divid == 'searchlist'){
		obj = document.getElementById('searchlist');
		otherobj = document.getElementById('map');
		whichviewmap.style.display = 'none';
		whichviewlisting.style.display = '';
		//alert('lisitngview now');
		
	}
	if (divid == 'map'){
		obj = document.getElementById('map');
		otherobj = document.getElementById('searchlist');
		whichviewmap.style.display = '';
		whichviewlisting.style.display = 'none';
		//alert('map view now');
	}
	
	if(obj.style.display == 'none') {
		obj.style.display = '';
		otherobj.style.display = 'none';
	}
	else {
		obj.style.display = 'none';
		otherobj.style.display = '';
	}

}
function flipsec(divid){
		whichviewmap = document.getElementById('profilep');
		whichviewlisting = document.getElementById('detailp');
	if (divid == 'detailview'){
		obj = document.getElementById('detailview');
		otherobj = document.getElementById('profileview');
		whichviewmap.style.display = 'none';
		whichviewlisting.style.display = '';
		//alert('lisitngview now');
		
	}
	if (divid == 'profileview'){
		obj = document.getElementById('profileview');
		otherobj = document.getElementById('detailview');
		whichviewmap.style.display = '';
		whichviewlisting.style.display = 'none';
		//alert('map view now');
	}
	
	if(obj.style.display == 'none') {
		obj.style.display = '';
		otherobj.style.display = 'none';
	}
	else {
		obj.style.display = 'none';
		otherobj.style.display = '';
	}

}

/*==============================================================================

    Routines written by John Gardner - 2003 - 2005

    See www.braemoor.co.uk/software for information about more freeware
    available.

/*==============================================================================

Routine to write a session cookie

    Parameters:
        cookieName        Cookie name
        cookieValue       Cookie Value
    
    Return value:
        true              Session cookie written successfullly
        false             Failed - persistent cookies are not enabled

   e.g. if (writeSessionCookie("pans","drizzle") then
           alert ("Session cookie written");
        else
           alert ("Sorry - Session cookies not enabled");
*/

function writeSessionCookie (cookieName, cookieValue) {
  if (testSessionCookie()) {
    document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
    return true;
  }
  else return false;
}

/*==============================================================================

Routine to get the current value of a cookie

    Parameters:
        cookieName        Cookie name
    
    Return value:
        false             Failed - no such cookie
        value             Value of the retrieved cookie

   e.g. if (!getCookieValue("pans") then  {
           cookieValue = getCoookieValue ("pans2);
        }
*/

function getCookieValue (cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}

/*==============================================================================

Routine to see if session cookies are enabled

    Parameters:
        None
    
    Return value:
        true              Session cookies are enabled
        false             Session cookies are not enabled

   e.g. if (testSessionCookie())
           alert ("Session coookies are enabled");
        else
           alert ("Session coookies are not enabled");
*/

function testSessionCookie () {
  document.cookie ="testSessionCookie=Enabled";
  if (getCookieValue ("testSessionCookie")=="Enabled")
    return true 
  else
    return false;
}

/*==============================================================================

Routine to see of persistent cookies are allowed:

    Parameters:
        None
    
    Return value:
        true              Session cookies are enabled
        false             Session cookies are not enabled

   e.g. if (testPersistentCookie()) then
           alert ("Persistent coookies are enabled");
        else
           alert ("Persistent coookies are not enabled");
*/

function testPersistentCookie () {
  writePersistentCookie ("testPersistentCookie", "Enabled", "minutes", 1);
  if (getCookieValue ("testPersistentCookie")=="Enabled")
    return true  
  else 
    return false;
}

/*==============================================================================

Routine to write a persistent cookie

    Parameters:
        CookieName        Cookie name
        CookieValue       Cookie Value
        periodType        "years","months","days","hours", "minutes"
        offset            Number of units specified in periodType
    
    Return value:
        true              Persistent cookie written successfullly
        false             Failed - persistent cookies are not enabled
    
    e.g. writePersistentCookie ("Session", id, "years", 1);
*/       

function writePersistentCookie (CookieName, CookieValue, periodType, offset) {

  var expireDate = new Date ();
  offset = offset / 1;
  
  var myPeriodType = periodType;
  switch (myPeriodType.toLowerCase()) {
    case "years":
      expireDate.setYear(expireDate.getFullYear()+offset);
      break;
    case "months":
      expireDate.setMonth(expireDate.getMonth()+offset);
      break;
    case "days":
      expireDate.setDate(expireDate.getDate()+offset);
      break;
    case "hours":
      expireDate.setHours(expireDate.getHours()+offset);
      break;
    case "minutes":
      expireDate.setMinutes(expireDate.getMinutes()+offset);
      break;
    default:
      alert ("Invalid periodType parameter for writePersistentCookie()");
      break;
  } 
  
  document.cookie = escape(CookieName ) + "=" + escape(CookieValue) + "; expires=" + expireDate.toGMTString() + "; path=/";
}  

/*==============================================================================

Routine to delete a persistent cookie

    Parameters:
        CookieName        Cookie name
    
    Return value:
        true              Persistent cookie marked for deletion
    
    e.g. deleteCookie ("Session");
*/    

function deleteCookie (cookieName) {

  if (getCookieValue (cookieName)) writePersistentCookie (cookieName,"Pending delete","years", -1);  
  return true;     
}


