function ajaxFunction(type, arg1, offset, cid){

	var ajaxRequest = null;  // The variable that makes Ajax possible!

   try {
   netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
   } catch (e) {

   try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("This feature was disabled by your browser.");
				return false;
			}
		}
	}
	}

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
//    ajaxRequest.setRequestHeader("Content-Type","application/x-javascript; charset:ISO-8859-1");			
		if(ajaxRequest.readyState==4 || ajaxRequest.readyState=="complete"){
          if (type == 'search')
		  {
			var ajaxDisplay = document.getElementById('fuzzysearch');
			var ajaxDisplay2 = document.getElementById('fuzzyHead');			
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
	        ajaxDisplay.className="visible";			
	        ajaxDisplay2.className="visible";			
//            ajaxDisplay.style.display="block";
//            ajaxDisplay.style.style.zIndex = "999";			
            if (ajaxRequest.responseText.length > 500)
			{
			  ajaxDisplay.style.height = '300px';
			  ajaxDisplay.style.overflow = 'auto';			  
			} else
			{
			  ajaxDisplay.style.height = '300px';
			  ajaxDisplay.style.background = '#FFFFFF';			  
			  ajaxDisplay.style.overflow = "visible";				  
			}	
		 }
		 if (type == 'tellAFriend')
		 {
//	       alert(ajaxRequest.responseText);	
		   document.getElementById('caja_form').style.display = "none";
		   document.getElementById('caja_success').style.display = "";		   		   
//		   document.getElementById('caja').style.display = "none";		   
		 }
      }
	}

    if (type == 'search'){
	  var rowsPerPage = 10;
	  if (cid == 'confirmedFriends')
	    rowsPerPage = 25;
	  if ((cid == 'groups')||(cid == 'images'))
	    rowsPerPage = 5;		
      var queryString = "?searchText=" + document.getElementById('search').value; 
//	  alert(queryString);
	  if (document.getElementById('search').value.length >= 3)
	  {
        ajaxRequest.open("GET", "includes/ajaxFunctions.php" + queryString, true);
//        ajaxRequest.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
	    ajaxRequest.send(null);	
//  	    element('fuzzysearch').className="hidden";	 	  
	  } else
	  {
  	    document.getElementById('fuzzysearch').className="hidden";	  
  	    document.getElementById('fuzzyHead').className="hidden";	
      }
	}	
    if (type == 'tellAFriend'){
//	  alert("hi");		
      var tellAFriendEmail = document.getElementById('share_input_bottom').value;
	  var tellAFriendSender = document.getElementById('share_input_top').value;
      if (tellAFriendSender && tellAFriendEmail && (tellAFriendSender != "Your Name") && (tellAFriendEmail != "Your Friend's Email"))
	  {
      var queryString = "?tellAFriendEmail=" + document.getElementById('share_input_bottom').value +  "&tellAFriendSender=" + document.getElementById('share_input_top').value; 

      ajaxRequest.open("GET", "includes/ajaxTellAFriend.php" + queryString, true);
	  ajaxRequest.send(null);	
	  } else
	  {
 	    document.getElementById('caja_form').style.display = "none";
		document.getElementById('caja_fail').style.display = "";		  
	  }
 	}		
}

function validatestate()
{
// Lets make sure a State is selected:
var state = document.form1.state.value;
document.form1.statename.value=document.form1.state.options[document.form1.state.selectedIndex].text;
if (state == "")
{
alert("Please select a State to continue.");
document.form1.state.focus();
return false;
}
return true;

}

function validatezip()
{
// Lets make sure a Zip Code is entered:
var zip = document.form2.zip.value;
if (zip == "")
{
alert("Please enter a Zip Code or Postal Code to continue.");
document.form2.zip.focus();
return false;
}
return true;
}

function validatecity()
{
// Lets make sure a City is entered:
var city = document.form3.city.value;

if (city == "")
{
alert("Please enter a City Name to continue.");
document.form3.city.focus();
return false;
}
return true;
}

function validatename()
{
// Lets make sure a Name is entered:
var name = document.form4.name.value;

if (name == "")
{
alert("Please enter a Name to continue.");
document.form4.name.focus();
return false;
}
return true;
}

function validatecountry()
{
// Lets make sure a Country is selected:
var country = document.form5.country.value;
document.form5.countryname.value=document.form5.country.options[document.form5.country.selectedIndex].text;
if (country == "")
{
alert("Please select a Country to continue.");
document.form5.country.focus();
return false;
}
return true;
}
 
function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function MM_openBrWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}


function hideThis(thisDiv){
	var hDiv = document.getElementById(thisDiv);
	hDiv.style.display = "none";
}

function showThis(thisDiv){
	var sDiv = document.getElementById(thisDiv);
	sDiv.style.display = "block";
}

function element( elementId )
{
   if ( document.getElementById )
   {
      return document.getElementById( elementId )
   }
   else if ( document.all )
   {
      return document.all[elementId]
   }
   else if ( document.layers ) 
   {
      return document[ elementId ]
   }
   else
   {
      //alert( "no element: " + elementId )
   }
}

function activeSearch() {
	element('searchField').className="activeSearch";
	element('searchField').value="";
	element('fuzzysearch').className="visible";
}

function closeSearch() {
	element('fuzzysearch').className="hidden";
	element('fuzzyHead').className="hidden";	
}

function clearDefault(el, value) {
if ((el.defaultValue==el.value)||(value == el.value)) el.value = ""
}

var IE = document.all?true:false

var tempX = 0
var tempY = 0	

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX - document.getElementById("wrapper").offsetLeft;
    tempY = event.clientY - document.getElementById("wrapper").offsetTop;
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX - document.getElementById("wrapper").offsetLeft;
    tempY = e.pageY - document.getElementById("wrapper").offsetTop;
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
//  document.Show.MouseX.value = tempX
//  document.Show.MouseY.value = tempY
  return true
}


divOne = document.getElementById('layout');
//divOne.onmousemove = displayDivMouseCoords;

function getMouseCoordsWithinEventTarget(event)
{
        var coords = { x: 0, y: 0};

        if(!event) // then we have a non-DOM (probably IE) browser
        {
                event = window.event;
                coords.x = event.offsetX;
                coords.y = event.offsetY;
        }
        else       // we assume DOM modeled javascript
        {
                var Element = event.target ;
                var CalculatedTotalOffsetLeft = 0;
                var CalculatedTotalOffsetTop = 0 ;

                while (Element.offsetParent)
                {
                        CalculatedTotalOffsetLeft += Element.offsetLeft ;     
                        CalculatedTotalOffsetTop += Element.offsetTop ;
                        Element = Element.offsetParent ;
                }

                coords.x = event.pageX - CalculatedTotalOffsetLeft ;
                coords.y = event.pageY - CalculatedTotalOffsetTop ;
        }
  		tempX = coords.x;
        tempY = coords.y;
        return true;
}

function getPageCoords(emt)
{
    var coords = {x: 0, y: 0};
    while (emt)
    {
            coords.x += emt.offsetLeft;
            coords.y += emt.offsetTop;
            emt = emt.offsetParent;
        }
    return coords;
}

function isElement(node)
{ return (node.nodeType == 1); }

function closeDoMore() {

//  alert("hi");
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
//coords = getMouseCoordsWithinEventTarget(e);
document.onmousemove = getMouseXY;
//document.onmousemove = getMouseCoordsWithinEventTarget;
//tempX = coords.x;
//tempY = coords.y;
  
/*  if ((tempX > 0)&&(tempY > 0)&&(tempX <= 132 || tempX > 310 || tempY < 230 || tempY >= 390))
  {
//    alert(tempX+', '+tempY);	  
    if (document.getElementById('flex_box'))
      document.getElementById('flex_box').style.display='none';
  }
//  else
//    alert(tempX+', '+tempY);	    */
  if ((tempX > 0)&&(tempY > 0)&&(tempX <= 600 || tempX > 860 || tempY < 200 || tempY >= 540))
  {
//    alert(tempX+', '+tempY);	  
    closeSearch();
  }  
//  else	
//    alert(tempX+', '+tempY);	

}

