var req = createXMLHttpRequest();
var str = '';

function createXMLHttpRequest() 
{
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // this should work for all browsers except IE6 and older
  try
  {
    // try to create XMLHttpRequest object
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    // assume IE6 or older
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
    // try every prog id until one works
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
    {
      try 
      { 
        // try to create XMLHttpRequest object
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {}
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

function overlay2() 
{
	var docHeight = document.height || document.body.offsetHeight;
	
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}

	el = document.getElementById("overlay");
	el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
	el2 = document.getElementById("lightbox");
	el2.style.visibility = (el2.style.visibility == "visible") ? "hidden" : "visible";
	if(el.style.visibility == "visible")
	{
		el.style.display="block";
		document.getElementById("overlay").style.height=yWithScroll+"px";	
		document.getElementById("lightbox").style.top=document.documentElement.scrollTop + 20 + "px";
		
	}
	else
	{
		el.style.display="none";
		//document.body.style.overflow="auto";
		document.getElementById("overlay").style.height="100%";
		document.getElementById("outerContainer").style.width="350px";
		document.getElementById("outerContainer").style.height="150px";
	}
	
	if(el2.style.visibility == "visible")
	{
		el2.style.display="block";
	}
	else
	{
		el2.style.display="none";
	}
	
}

function tellFriend()
{
	var tmp='';
	
	tmp = '<table border="0" cellpadding="1" cellspacing="1" width="100%">';
	tmp += '<tr valign="top">';
	tmp += '<td align="left" style="padding-top:8px;padding-left:6px;border-bottom:1px solid #353535;">';
	tmp += '<font style="font-size:12px;"><b>Tell A Friend</b></font>';
	tmp += '</td>';
	tmp += '</tr>';
	tmp += '<tr valign="top">';
	tmp += '<td align="left" style="padding-top:8px;padding-left:8px;">';
	tmp += 'Please fill in the information below.';
	tmp += '</td>';
	tmp += '</tr>';
	tmp += '<tr valign="top">';
	tmp += '<td align="left" style="padding-top:8px;padding-left:8px;">';
		tmp += '<table border="0" cellpadding="2" cellspacing="0">';
		tmp += '<tr valign="top">';
		tmp += '<td align="left" valign="middle">';
		tmp += '<b>Your Name:</b>';
		tmp += '</td>';
		tmp += '<td align="left" style="padding-left:8px;">';
		tmp += '<input type="text" id="name" name="name" size="30">';
		tmp += '</td>';
		tmp += '</tr>';
		tmp += '<tr valign="top">';
		tmp += '<td align="left" valign="middle">';
		tmp += '<b>Your Email:</b>';
		tmp += '</td>';
		tmp += '<td align="left" style="padding-left:8px;">';
		tmp += '<input type="text" id="email1" name="email1" size="30">';
		tmp += '</td>';
		tmp += '</tr>';
		tmp += '<tr valign="top">';
		tmp += '<td align="left" valign="middle">';
		tmp += '<b>Friends Email:</b>';
		tmp += '</td>';
		tmp += '<td align="left" style="padding-left:8px;">';
		tmp += '<input type="text" id="email2" name="email2" size="30">';
		tmp += '</td>';
		tmp += '</tr>';
		tmp += '<tr valign="top">';
		tmp += '<td align="left">';
		tmp += '<b>Comments:</b>';
		tmp += '</td>';
		tmp += '<td align="left" style="padding-left:8px;">';
		tmp += '<textarea id="comments" name="comments" cols="25" rows="6"></textarea>';
		tmp += '</td>';
		tmp += '</tr>';
		tmp += '</table>';
	tmp += '</td>';
	tmp += '</tr>';
	tmp += '<tr valign="top">';
	tmp += '<td align="center" style="padding-top:8px;">';
	tmp += '<input type="button" name="cancelbtn" id="cancelbtn" value=" Cancel " onclick="overlay2();">&nbsp;';
	tmp += '<input type="button" name="sendbtn" id="sendbtn" value=" Send " onclick="tellFriendAction();">&nbsp;';
	tmp += '</td>';
	tmp += '</tr>';
	tmp += '</table>';	
	
	overlay2();
	
	document.getElementById("outerContainer").style.width="400px";
	document.getElementById("outerContainer").style.height="300px";
	document.getElementById("innerContainer").innerHTML=tmp;
}
function tellFriendAction()
{
	var name1=document.getElementById("name");
	var email1=document.getElementById("email1");
	var email2=document.getElementById("email2");
	var cmts=document.getElementById("comments");
	
	if(name1.value == '')
	{
		alert('Please enter your name!')
		name1.focus();
		return false;
	}
	else if(email1.value == '')
	{
		alert('Please enter your email address!')
		email1.focus();
		return false;
	}
	else if(email2.value == '')
	{
		alert('Please enter a recipient email address!')
		email2.focus();
		return false;
	}
	else
	{
		if (req)
		{
			// try to connect to the server
			try
			{
				// make asynchronous HTTP request to retrieve new message
				params = "n="+encodeURIComponent(name1.value)+"&e1="+encodeURIComponent(email1.value)+"&e2="+encodeURIComponent(email2.value)+"&c="+encodeURIComponent(cmts.value);
				req.open("POST", "tellFriend.php", true);
				req.setRequestHeader("Content-Type", 
	                                 "application/x-www-form-urlencoded");
				req.onreadystatechange = handletellFriend;
				req.send(params);
				//alert(params);
			}
			catch(e)
			{
				alert(e.toString());
			}
		}
	}	
}

function handletellFriend() 
{
	// when readyState is 4, we are ready to read the server response
	if (req.readyState == 4) 
	{
		// continue only if HTTP status is "OK"
		if (req.status == 200) 
		{
			try
			{
				// do something with the response from the server
				gettellFriend();
			}
			catch(e)
			{
				// display error message
				alert(e.toString());
			}
		}	 
		else
		{
			// display error message
			alert(req.statusText);   
		}
	}
}

function gettellFriend()
{
	var response = req.responseText;

	overlay2();
	document.getElementById("innerContainer").innerHTML=response;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function addBookmark(title,url) {
if (window.sidebar) { 
window.sidebar.addPanel(title, url,""); 
} else if( document.all ) {
window.external.AddFavorite( url, title);
} else if( window.opera && window.print ) {
return true;
}
}


function loginCk()
{
	if (document.form2.Username.value=='')
	{
		alert("Please enter a username.");
		document.form2.Username.focus();
		return false;
	}
	else if (document.form2.Passwd.value=='')
	{
		alert("Please enter a password.");
		document.form2.Passwd.focus();
		return false;
	}
	else 
	{	
		document.form2.submit();
	}
}

function checkSearch() {
	if((document.getElementById("Csearch1").value=='') || (document.getElementById("Csearch1").value=='Enter City Name/Zip Code'))
	{
	alert("Please enter a City Name or Zip Code.");
	document.getElementById("Csearch1").focus();
	return false;
	}
	else
	{
		//document.form1.submit();
		page(document.getElementById("Csearch1").value,"41",0);
	}
}
 
function checkSearch2() 
{
	if ((document.formS.category.value==''))
	{
		alert("Please select a category.");
		document.formS.category.focus();
		return false;
	}
	if((document.formS.Csearch.value=='') || (document.formS.Csearch.value=='Enter City Name/Zip Code'))
	{
	alert("Please enter a City Name or Zip Code.");
	document.formS.Csearch.focus();
	return false;
	}
	else
	{
		document.formS.submit();
	}
}

function doClear(theText) {
     if (theText.value == theText.defaultValue) {
         theText.value = ""
     }
 }

//Temporary function to enable "Enter" keypress to submit seach form. - cdy

function submitViaEnter(evt) {
    evt = (evt) ? evt : event;
    var target = (evt.target) ? evt.target : evt.srcElement;
    var form = target.form;
    var charCode = (evt.charCode) ? evt.charCode :
        ((evt.which) ? evt.which : evt.keyCode);
    if (charCode == 13) {
            return checkSearch();
            return false;
    }
    return true;
}

