/*	Validates the user login form			*/
function validateLogin(blnGadget) {
	var prefix;
	if(blnGadget==true) {prefix="Login";} else {prefix="MF";}
	if($get(prefix+"Login").value=="") {
		alert("Please enter your user-name or email address.");
		$get(prefix+"Login").focus();
		return false;}
	if($get(prefix+"Password").value=="") {
		alert("Please enter your password.");
		$get(prefix+"Password").focus();
		return false;}
	return true;
}

/*	Opens the password window				*/
function EmailPassword() {
	EmailPasswordWindow=window.open("http://www.taverntrove.com/password.asp","EmailPasswordWindow","toolbar=no, directories=no, location=no, status=no, menubar=no, resizable=no, scrollbars=no");
   	if (window.focus) {EmailPasswordWindow.focus()}
}

/*	Opens Event Window						*/
function ViewEvent(EventId) {
	EventWindow=window.open('event.asp?EventId='+EventId,'EventDetails','width=600,height=500,scrollbars=yes,resizable=yes');
	if (window.focus) {EventWindow.focus();}
}

/*	Moves to specific page of recordset 	*/
function goToPage(intPageNumber,intTotalPages) {
	var digits="0123456789";
	for (var i=0;i<intPageNumber.length;i++) {
		if (digits.indexOf(intPageNumber.substring(i,i+1))==-1) {
			alert("Please enter a valid page number.");
			return false;}
	}
	if(intPageNumber > intTotalPages || intPageNumber == 0) {
		alert("Please enter a valid page number.");}
	else {
		$get("intPageNumber").value = intPageNumber;
		$get("frmSearchCriteria").submit();}
}
function P7_limit(a,b){ //v1.1.2 by PVII-www.projectseven.com
	document.p7limit=a;document.p7min=b;
 	if(document.getElementById&&navigator.appVersion.indexOf("MSIE")>-1&&!window.opera){
 	if(window.attachEvent){window.attachEvent("onresize",P7_setMinWidth);
 	window.attachEvent("onload",P7_setMinWidth);}else{onload=P7_setMinWidth;
 	onresize=P7_setMinWidth;}}
}
P7_limit('wrapper',790);
function P7_setMinWidth(){ //v1.1.2 by PVII-www.projectseven.com
 	var cw,w,pl,pr,ml,mr,br,bl,ad,theDiv=document.p7limit;
 	var g=$get(theDiv);
	w=parseInt(document.p7min);
 	if(g&&document.body&&document.body.clientWidth){
		gs=g.currentStyle;
 		cw=parseInt(document.body.clientWidth);
		pl=parseInt(gs.paddingLeft);
 		pr=parseInt(gs.paddingRight);
		ml=parseInt(gs.marginLeft);
		mr=parseInt(gs.marginRight);
 		bl=parseInt(gs.borderLeftWidth);
		br=parseInt(gs.borderRightWidth);
		ml=ml?ml:0;
 		mr=mr?mr:0;
		pl=pl?pl:0;
		pr=pr?pr:0;
		bl=bl?bl:0;
		br=br?br:0;
		ad=pl+pr+ml+mr+bl+br;
		if(cw<=w){
			w-=ad;
			g.style.width=w+"px";
		}else{
			g.style.width="auto";
		}
	}
}
function toggleInternational() {
	if($get("CountryRow").style.display=="none") {
		$get("CountryRow").style.display="";
		$get("Country").value="";
		$get("StateRow").style.display="";
		$get("StateSelectRow").style.display="none";
		$get("InternationalButton").value = "U.S. Address";
		$get("Country").focus();
	}
	else{
		$get("Country").value="USA";
		$get("CountryRow").style.display="none";
		$get("StateRow").style.display="none";
		$get("StateSelectRow").style.display="";
		$get("InternationalButton").value = "International Address";
		$get("Street1").focus();
	}
}
function initInternational() {
	if($get("Country").value!="USA") {
		$get("CountryRow").style.display="";
		$get("StateRow").style.display="";
		$get("StateSelectRow").style.display="none";
		$get("InternationalButton").value = "U.S. Address";
		$get("Country").focus();
	}
}

function $get(str) { return document.getElementById(str); }
function getHTTPObject() {
	var xmlhttp;
 	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    	try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; }
	}
	else {
		try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e) {
			try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }	catch (E) { xmlhttp = false; }
		}
 	}
	return xmlhttp;
}

var http = null;
function refreshStates() {
  		http = getHTTPObject();
  		if(http != null) {
		var strQS = '?CountryID=' + $get('intCountryId').value;
		http.open("GET", "/ajax.asp" + strQS, true);
     			http.onreadystatechange = function (aEvt) {
         			if(http.readyState == 4) {
             			if(http.status == "200") {
                 			var xmlDoc;
        			var strHTMLCounties;
                 			if(window.ActiveXObject) { // IE
                 			    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                 			    xmlDoc.async = false;
                 			    xmlDoc.loadXML(http.responseText);
                 			}
                 			else if(document.implementation && document.implementation.createDocument) // Mozilla
                 			    xmlDoc = http.responseXML;
					var stateList = xmlDoc.documentElement.getElementsByTagName("state");
				    strHTMLStates =  '<select name="intStateId" id="intStateId" class="FormInput" style="width:160px;">\r\n';
					strHTMLStates += '  <option value="">-- All States --\r\n';
                 			for (var i = 0; i < stateList.length; i++)
                 			    strHTMLStates += '  <option value="' + stateList[i].getAttribute("id") + '" >' + stateList[i].getAttribute("name") + '\r\n';
                 			strHTMLStates += '</select>\r\n'
                 			$get('divState').innerHTML = strHTMLStates;
               	}
           	}
       	};
       	http.send(null);
	}
}
