function $(id) { return document.getElementById(id); }

function fetch(url, id)
{
	var http; 
	http=GetXmlHttpObject();
	http.onreadystatechange = function()
	{ 
		if(http.readyState == 4)
		{
			if(http.status == 200) 
			{
				if(http.responseText != "")
					{
						$(id).style.visibility="visible"; 
						$(id).innerHTML = http.responseText;
					}
				else { $(id).style.visibility="hidden"; }
			}
			else
			{
				$(id).style.visibility="hidden";
			}
		}
	};
	http.open('GET', url, true); 
	http.send(null); 
}

function getCityState(zipid, cityid, stateid)
{
//document.write(zipid + $(zipid).value + $(cityid).innerText  + $(stateid).innerText );
	//if (($(zipid).value).length == 5)
	//{
	var xmlHttp;
	var url;
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange = function()
	
	{ $('progress').className = "waiting"; 

		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			if(xmlHttp.status == 200) 
			{
				response  = xmlHttp.responseXML.documentElement;
				
                city = response.getElementsByTagName('CITY')[0].firstChild.data;
                state = response.getElementsByTagName('STATE')[0].firstChild.data;
                $(cityid).value  = city;
                $(stateid).value  = state;
                $('progress').className = "notWaiting";
			}
			else {}
		} 
	};
	url = 'zip.aspx?zip=' + $(zipid).value;
	xmlHttp.open('GET', url, true); 
	xmlHttp.send(null); 
//}
}

function validate_for_integers(inputfield, inputevent) {
	var key;
	var keychar;

	if (window.event) {
		key = window.event.keyCode;
	} else if (inputevent) {
		key = inputevent.which;
	} else {
		return true;
	}
	
	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) ||
    		(key==9) || (key==13) || (key==27)) {
		return true;

	// numbers
	} else if (("0123456789").indexOf(keychar) > -1) {
		return true;
		
	} else {
		return false;
	}
} // end of validate_for_integers()

function GetXmlHttpObject()
{ 
 var objXMLHttp = window.XMLHttpRequest ? new XMLHttpRequest() : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : null);
 return objXMLHttp;
} 


function suggest()
{
	var curleft = curtop = 0;
	var obj = $('thesearchbox');
	if (obj.offsetParent)
	{
		do
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
		while (obj = obj.offsetParent);
		curtop = curtop + $('thesearchbox').offsetHeight;
		$('suggestbox').style.top = curtop + 'px';
		$('suggestbox').style.left = curleft + 'px';	
	}
	var str = escape($('thesearchbox').value);
	fetch('getBrand.aspx?brand=' + str, 'suggestbox');
}

function suggest2()
{
	var curleft = curtop = 0;
	var obj = $('txtBrand');
	if (obj.offsetParent)
	{
		do
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
		while (obj = obj.offsetParent);
		curtop = curtop + $('txtBrand').offsetHeight;
		$('suggestbox').style.top = curtop + 'px';
		$('suggestbox').style.left = curleft + 'px';	
	}
	var str = $('txtBrand').value;
	fetch('getBrands.aspx?brand=' + str, 'suggestbox');
}

//function selectBrand(brand) {$('thesearchbox').value = brand;}

 function selectCigar(id) {
 //Document.Write(id);
 location.href="cigardetail.aspx?cid="+id;
 }
 
 function comment(id, length)
 {
 var obj = $(id);
 if ((obj.value).length > 0)
 {
    $('commentCount').innerHTML = (length - (obj.value).length + " remaining");
 }
   else { $('commentCount').innerHTML = ""; }
   return true;
 }
 function comment2(id, length)
 {
 var obj = $(id);
 if ((obj.value).length >= length)
 {
   event.returnValue=false;
   }
 }   