
function replaceSubstring(inputString, fromString, toString) {
	// Goes through the inputString and replaces every occurrence of fromString with toString
	var temp = inputString;
	if (fromString == "") {
		return inputString;
	}
	if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
	while (temp.indexOf(fromString) != -1) {
		var toTheLeft = temp.substring(0, temp.indexOf(fromString));
		var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
		temp = toTheLeft + toString + toTheRight;
	}
	} else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
	var midStrings = new Array("~", "`", "_", "^", "#");
	var midStringLen = 1;
	var midString = "";
	// Find a string that doesn't exist in the inputString to be used
	// as an "inbetween" string
	while (midString == "") {
		for (var i=0; i < midStrings.length; i++) {
			var tempMidString = "";
			for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
			if (fromString.indexOf(tempMidString) == -1) {
				midString = tempMidString;
				i = midStrings.length + 1;
			}
		}
	} // Keep on going until we build an "inbetween" string that doesn't exist
	// Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
	while (temp.indexOf(fromString) != -1) {
		var toTheLeft = temp.substring(0, temp.indexOf(fromString));
		var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
		temp = toTheLeft + midString + toTheRight;
	}
	// Next, replace the "inbetween" string with the "toString"
	while (temp.indexOf(midString) != -1) {
		var toTheLeft = temp.substring(0, temp.indexOf(midString));
		var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
		temp = toTheLeft + toString + toTheRight;
	}
	} // Ends the check to see if the string being replaced is part of the replacement string or not
	return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function

/*
Script Name: Javascript Cookie Script
Author: Public Domain, with some modifications
Script Source URI: http://techpatterns.com/downloads/javascript_cookies.php
Version 1.0.0
Last Update: 30 May 2004

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
*/

// this function gets the cookie, if it exists
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 ) );
}

/*
only the first 2 parameters are required, the cookie name, the cookie
value. Cookie time is in milliseconds, so the below expires will make the 
number you pass in the Set_Cookie function call the number of days the cookie
lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

Generally you don't need to worry about domain, path or secure for most applications
so unless you need that, leave those parameters blank in the function call.
*/
function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	//alert("about to set cookie "+name+"="+value);
	if ( !expires )
	    (expires=1);
	   
	
		expires = expires * 1000 * 60 * 60 * 24;
	
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

//var  B_NS = BrowserCode.indexOf('Netscape')!=-1;
//var  B_IE = navigator.appVersion.indexOf('MSIE')!=-1;

//First things first, set up our array that we are going to use.
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + //all caps
"abcdefghijklmnopqrstuvwxyz" + //all lowercase
"0123456789+/="; // all numbers plus +/=

//Heres the encode function
function encode64(inp)
{
	var out = ""; //This is the output
	var chr1, chr2, chr3 = ""; //These are the 3 bytes to be encoded
	var enc1, enc2, enc3, enc4 = ""; //These are the 4 encoded bytes
	var i = 0; //Position counter

	do { //Set up the loop here
	chr1 = inp.charCodeAt(i++); //Grab the first byte
	chr2 = inp.charCodeAt(i++); //Grab the second byte
	chr3 = inp.charCodeAt(i++); //Grab the third byte

	//Here is the actual base64 encode part.
	//There really is only one way to do it.
	enc1 = chr1 >> 2;
	enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
	enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
	enc4 = chr3 & 63;

	if (isNaN(chr2)) {
		enc3 = enc4 = 64;
	} else if (isNaN(chr3)) {
		enc4 = 64;
	}

	//Lets spit out the 4 encoded bytes
	out = out + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) +
	keyStr.charAt(enc4);

	// OK, now clean out the variables used.
	chr1 = chr2 = chr3 = "";
	enc1 = enc2 = enc3 = enc4 = "";

	} while (i < inp.length); //And finish off the loop

	//Now return the encoded values.
	return out;
}

//Heres the decode function
function decode64(inp)
{
	var out = ""; //This is the output
	var chr1, chr2, chr3 = ""; //These are the 3 decoded bytes
	var enc1, enc2, enc3, enc4 = ""; //These are the 4 bytes to be decoded
	var i = 0; //Position counter

	// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
	var base64test = /[^A-Za-z0-9\+\/\=]/g;

	if (base64test.exec(inp)) { //Do some error checking
	alert("There were invalid base64 characters in the input text.\n" +
	"Valid base64 characters are A-Z, a-z, 0-9, ?+?, ?/?, and ?=?\n" +
	"Expect errors in decoding.");
	}
	inp = inp.replace(/[^A-Za-z0-9\+\/\=]/g, "");

	do { //Here’s the decode loop.

	//Grab 4 bytes of encoded content.
	enc1 = keyStr.indexOf(inp.charAt(i++));
	enc2 = keyStr.indexOf(inp.charAt(i++));
	enc3 = keyStr.indexOf(inp.charAt(i++));
	enc4 = keyStr.indexOf(inp.charAt(i++));

	//Heres the decode part. There’s really only one way to do it.
	chr1 = (enc1 << 2) | (enc2 >> 4);
	chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
	chr3 = ((enc3 & 3) << 6) | enc4;

	//Start to output decoded content
	out = out + String.fromCharCode(chr1);

	if (enc3 != 64) {
		out = out + String.fromCharCode(chr2);
	}
	if (enc4 != 64) {
		out = out + String.fromCharCode(chr3);
	}

	//now clean out the variables used
	chr1 = chr2 = chr3 = "";
	enc1 = enc2 = enc3 = enc4 = "";

	} while (i < inp.length); //finish off the loop

	//Now return the decoded values.
	return out;
}


function GetElement(sName)
{

	var b;
	var  B_IE = navigator.appVersion.indexOf('MSIE')!=-1;
	if (B_IE)
	{
		return document.getElementById(sName);
	}


	for (var j=0;j < document.forms.length;j++)
	{

		for (var i=0;i < document.forms[j].elements.length;i++)
		if  (document.forms[j].elements[i].name==sName || document.forms[j].elements[i].id==sName)
		return document.forms[j].elements[i];

	}


}
function GetFormElement(sName,theForm)
{
	var b;

    
	for (var i=0;i < theForm.elements.length;i++)
	if  (theForm.elements[i].name==sName || theForm.elements[i].id==sName)
	return theForm.elements[i];


}
function InsertWithSep(haystack,needle,sep,nodup)
{
  if (!sep)
     sep=",";
  //if (!dup)
    // dup=true;
     
  if (nodup)
  {
  	if (!fnValueIn(haystack,needle,sep))
  	{
       if (haystack == "")
          return needle;
       return haystack +sep+needle;
  	}
  	else
  	   return haystack;
   
  }
  else
  {  
    if (haystack == "")
       return needle;
    return haystack +sep+needle;
  }
  
}



function FindMyObject(sName)
{
	try
	{
	//	alert(sName);
		if (eval(sName))
		{
			
			s="  my = "+sName+";"
			eval(s);
			if (my)
			return my;
		}
	}

	catch(e)
	{
		return null;
	}




}

function ShowCalendar(sField,bTime)
{

	var myt=  document.getElementById(sField);

	if (myt)
	{
		var mycal = new calendar2(myt);
		if (mycal)
		{
			mycal.yearscroll=true;
			mycal.time_comp = bTime;
			mycal.popup();
		}

	}
	return false;
}

function fnCallToServer(url,sFrame)
{
 // document.location.replace(url);
   // url = "http://click.linksynergy.com/fs-bin/click?id=2zlhq/XW1XM&offerid=60821.10000071&type=3&subid=0";
  var newwin = window.open(url,'sFrame');
}


function callToServer(url,sFrame) 
{
 // if (!document.createElement) {return true};
  var IFrameDoc;

  if (!sFrame)
     sFrame='myFrame';
  //alert(url);
     
  IFrameObj = FindMyObject(sFrame);

  if (!IFrameObj)
      return;
      
  var URL = url;//buildQueryString('theFormName');
  /*
  if (!IFrameObj && document.createElement) {
    // create the IFrame and assign a reference to the
    // object to our global variable IFrameObj.
    // this will only happen the first time 
    // callToServer() is called
    
   try {
   	 
      var tempIFrame=document.createElement('iframe');
      tempIFrame.setAttribute('id','RSIFrame');
      tempIFrame.style.border='0px';
      tempIFrame.style.width='0px';
      tempIFrame.style.height='0px';
      IFrameObj = document.body.appendChild(tempIFrame);
      
      if (document.frames) {
        // this is for IE5 Mac, because it will only
        // allow access to the document object
        // of the IFrame if we access it through
        // the document.frames array
        IFrameObj = document.frames['RSIFrame'];
      }
    } catch(exception) 
     {
      // This is for IE5 PC, which does not allow dynamic creation
      // and manipulation of an iframe object. Instead, we'll fake
      // it up by creating our own objects.
      iframeHTML='\<iframe id="RSIFrame" style="';
      iframeHTML+='border:0px;';
      iframeHTML+='width:0px;';
      iframeHTML+='height:0px;';
      iframeHTML+='"><\/iframe>';
      document.body.innerHTML+=iframeHTML;
      IFrameObj = new Object();
      IFrameObj.document = new Object();
      IFrameObj.document.location = new Object();
      IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
      IFrameObj.document.location.replace = function(location) {
        this.iframe.src = location;
      }
    }
    
  }
  
  if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) 
  {
    // we have to give NS6 a fraction of a second
    // to recognize the new IFrame
    setTimeout('callToServer()',10);
    return false;
  }
  */
  
  if (IFrameObj.contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument; 
  } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
  } else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
  } else {
    return true;
  }

  		//myDiv.style.left = e.clientX + document.body.scrollLeft+10;
		
		//myDiv.style.top = e.clientY + document.body.scrollTop-10;

  IFrameDoc.location.replace(URL);
  return false;
}


function fnValueIn(str,subject,sep)
{
  if (!sep || sep=="")
     sep=",";
     
  if (str=="")
     return false;
     
  var aStr = str.split(sep);
  for (var i=0; i<aStr.length;i++)
  {
  	//alert(aStr[i]+"[=]"+subject);
  	 if (aStr[i]==subject)
  	 {
  	 	
  	    return true;
  	 }
  }
  return false;
}


function fnResizeMe(iWidth,iHeight,iTop,iLeft)
{
	
	
	var oframe = parent.document.getElementById("frameLookups");

	oframe.className = "frameShow";
	oframe.style.top = iTop;
	oframe.style.left = iLeft;
	oframe.style.height = iHeight;
	oframe.style.width = iWidth;
}

function fnCloseFrame(sName)
{
	
	var oframe = document.getElementById(sName);
	//alert(oframe.width);
	oframe.style.width = 1;// "frameHide";
	oframe.style.height = 1;// "frameHide";
    return false;
}

function switchImage(ctl,sbase,flag)
{
	var sdir = "images/temp/";
	//alert(ctl.src);
	var sURL = sdir + sbase+"_"+flag+".png";
	//alert(sURL);
	ctl.src = sURL;
	
	return;
	
   if (flag=='over')
	  document.images[id].src = "images/temp/" + id + "_over.png";
   else
   if (flag=='out')
	  document.images[id].src = "images/temp/" + id + "_over.png";
   	  
	//alert(document.images[id].src);
}



function MergeWithSep(haystack,needle,sep)
{
 if (!sep)
    sep = ",";
    
 if (!haystack  || haystack=="")
   return needle;
   
 return haystack  + sep + needle;
   
}

function Trim(TRIM_VALUE){
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function


 function fnLoadGoogleMap(gpslat,gpslon,gpsmag) 
    {
    	//alert("got here2");
      if (GBrowserIsCompatible()) 
      {
        var map = new GMap2(document.getElementById("map2"));
        map.setCenter(new GLatLng(gpslat, gpslon), gpsmag);
      }
    }

function fnGMark(gpslat,gpslon,gpsmag,gmessage) 
{
  if (GBrowserIsCompatible()) 
  {
   var map = new GMap2(document.getElementById("map2"));
   map.setCenter(new GLatLng(gpslat, gpslon), gpsmag);
   //map.openInfoWindow(map.getCenter(), document.createTextNode(gmessage));
   var point = new GLatLng(gpslat, gpslon);
   map.addOverlay(new GMarker(point));
  }
}

function fnGetHttp()
{
      http_request = false;
      if (window.XMLHttpRequest) 
      { // Mozilla, Safari,...
          http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } 
      else if (window.ActiveXObject) 
      { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) 
         {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) 
      {
         alert('Cannot create XMLHTTP instance');
         return false;
      }	
      return http_request;
}

function function_exists(func)
{
	var str =String.format(" var bTest=('function' == typeof window.{0});",func);
	eval(str);
	return bTest;
}

function get_class(classname)
{
	if (function_exists(classname))
	{
	 var str =String.format(" var cTest=(window.{0});",classname);
	 eval(str);
	 return cTest;
	}
}

function fnNumeric(x) 
{ 
// I usually use the this function like this: if (isNumeric(myVar)) { } 
// regular expression that validates a value is numeric 
var RegExp = /^(-)?(\d*)(\.?)(\d*)$/; 
// Note: this WILL allow a number that ends in a decimal: -452. 
// compare the argument to the RegEx 
// the 'match' function returns 0 if the value didn't match 
var result = x.match(RegExp); 
return result; 
}

function fnDivPosition(myDiv,obj)
 {
	  var xy=findPos(obj);
	  if (myDiv)
	  {
		//myDiv.className = 'gDivCalendar';		
		//myDiv.innerHTML = html;
		//alert(myDiv.id);
		myDiv.style.left = xy[0];//e.offsetX+200;
		myDiv.style.top = xy[1]+21;// e.offsetY +200;
		
	 }	
}
	
function fnMessageBox(title,html)
{

	var testFrame = document.getElementById("popFrame");
	var doc = testFrame.contentDocument;
   // ret = this.fnCalShow();
	if (doc == undefined || doc == null)
	{
        doc = testFrame.contentWindow.document.getElementById("popDiv");
        doc_title = testFrame.contentWindow.document.getElementById("frameTitle");
		testFrame.className="gFrame";
		testFrame.contentWindow.thisFrame=testFrame;
		//testFrame.contentWindow.targetObj=this.targetObj;
		//testFrame.contentWindow.parentWindow=window;
		//testFrame.contentWindow.testObject=this;	
		if (doc_title)
           doc_title.innerHTML = title;		
	}		
	doc.innerHTML = html;
	
	testFrame.style.left =Math.floor(screenW/2)-100;
	testFrame.style.top = Math.floor(screenH/2)-100;
}

var screenW = 640, screenH = 480;
if (parseInt(navigator.appVersion)>3) 
{
 screenW = screen.width;
 screenH = screen.height;
}
else if (navigator.appName == "Netscape" 
    && parseInt(navigator.appVersion)==3
    && navigator.javaEnabled()
   ) 
{
 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
 var jScreenSize = jToolkit.getScreenSize();
 screenW = jScreenSize.width;
 screenH = jScreenSize.height;
}

function fnUppercase(str)
{
if (str && str!="")
    return str.toUpperCase();
 return str;
 
}

function fnLowercase(str)
{
if (str && str!="")
    return str.toLowerCase();
 return str;
 
}

function fnSaveSettings(cArray,cInfo,sep1,sep2)
{
  var aInfo = cInfo.split(sep1);
  for (var i =0; i<aInfo.length;i++)
  {
   var chunks = aInfo[i].split(sep2);
   cArray[chunks[0]] = chunks[1];
  }
 
}


function fnShowMessage(str)
{
	alert(str);
	return false;
}

	

