// used in mytownoogle.php
function hideAndShow(table) {
	// hide all tables
	document.getElementById('MyAccount').style.display		= 'none';
	document.getElementById('MyPassword').style.display		= 'none';
	document.getElementById('MyOrgs').style.display			= 'none';
	document.getElementById('MyEvents').style.display		= 'none';
	document.getElementById('MyClassifieds').style.display	= 'none';
	document.getElementById('MyPromotions').style.display	= 'none';
	// show active table
	showTable(table);
}
// used by the drop-down form elements that redirect to another page
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
// preload images in body tag
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
MM_preloadImages('../assets/tabcorners-redtl.gif', '../assets/tabcorners-redtr.gif', '../assets/tabcorners-redbl.gif', '../assets/tabcorners-redbr.gif');

function checkChar(e, PageName) { //e is event object passed from function invocation
	var characterCode; //literal character code will be stored in this variable

	if (e && e.which) { //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	} else {
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}

	if (characterCode == 13) { //if generated character code is equal to ascii 13 (if enter key)
//		document.forms[0].submit(); //submit the form
		setSearch(PageName);
	}
}
function enterKeyword(e, page, cat_group_id, location_id, search_value, keyword) {
	var qstring = "?Keyword=" + keyword;
	qstring    += search_value != "" ? "&SV=" + search_value : "";
	qstring    += location_id  != "" ? "&L="  + location_id  : "";
	qstring    += cat_group_id != "" ? "&CG=" + cat_group_id : "";

	var characterCode;
	if (e && e.which) {
		e = e;
		characterCode = e.which;
	} else {
		e = event;
		characterCode = e.keyCode;
	}
	if (characterCode == 13) {
		if (keyword.length < 3)
			alert("Oops! Keyword must be at least 3 characters.");
		else
			window.location = page + qstring;
	}
}
function switchFont(id, color) {
	if (document.getElementById(id))
		document.getElementById(id).style.color = color;
}
function switchImg(id, image) {
	document.getElementById(id).src = image;
}
// this function will (a) show a table if it was hidden or (b) hide a table if it was visible
function showTable(table) {
	if (document.getElementById(table)) {
		if (document.getElementById(table).style.display == '')
			document.getElementById(table).style.display = 'none';
		else
			document.getElementById(table).style.display = '';
	}
}
function clearText(id, text) {
	if (document.getElementById(id).value == text) {
		document.getElementById(id).value = '';
		document.getElementById(id).style.color = '#000000';
	}
}
function resetText(id, text) {
	if (document.getElementById(id).value == "") {
		document.getElementById(id).value		= text;
		document.getElementById(id).style.color	= '#666';
	}
}
function setSearch(PageName) {
	var SearchVal = document.getElementById('SearchVal').value
	if (SearchVal.length > 0 && SearchVal.length < 3)
		alert("Oops! Keyword must be at least 3 characters.");
	else {
		if (SearchVal != "" && SearchVal != "Find Listings | Enter Name Here") {
			if (PageName=='mytownoogle' || PageName=='orgedit' || PageName=='orgnew1' || PageName=='orgnew2' || PageName=='orgnew3' || PageName=='login' || PageName=='register' || PageName=='lostpw' || PageName=='activateresend' || PageName=='thankyou')
				window.location = "../listings.php?SV=" + SearchVal;
			else
				window.location = "listings.php?SV=" + SearchVal;
		} else
			alert("Oops! Please enter a Name to search.");
	}
}
function checkLimit(limit, id) {
	var num		= 0;
	var length	= document.getElementById(id).length;
	for (i = 0; i < length; i++) {
		if (document.form1.elements[id][i].selected) {
			// if limit is selected, disable the others
			if (num++ == limit-1) {
				for (j = 0; j < length; j++) {
					if (document.form1.elements[id][j].selected == false)
						document.form1.elements[id][j].disabled = true;
				}
			} else {
				// else if below limit, enable all
				if (num < limit) {
					for (j = 0; j < length; j++)
						document.form1.elements[id][j].disabled = false;
				// else if > limit has been selected, unselect all and enable all
				} else {
					for (j = 0; j < length; j++) {
						document.form1.elements[id][j].selected = false;
						document.form1.elements[id][j].disabled = false;
					}
				}
			}
		}
	}
	setNumSelected(id);
}
function setNumSelected(id) {
	var num		= 0;
	var length	= document.getElementById(id).length;
	for (i = 0; i < length; i++) {
		if (document.form1.elements[id][i].selected) {
			num++;
		}
	}
	document.getElementById(id+'Selected').value = "(" + num + " selected)";
}
function changeGroup(ReturnPage, OrgId) {
	var QString = OrgId != "" ? "OrgId="+OrgId : "";

	// add groups
	if (document.getElementById('CatGroupId1').value != '')
		QString+="&"+document.getElementById('CatGroupId1').value;
	if (document.getElementById('CatGroupId2').value != '')
		QString+="&"+document.getElementById('CatGroupId2').value;
	if (document.getElementById('CatGroupId3').value != '')
		QString+="&"+document.getElementById('CatGroupId3').value;

	// add cats
	var Category = new Array("CategoryId1","CategoryId2","CategoryId3");
	for (idx = 0; idx < 3; idx++) {
		if (document.getElementById(Category[idx]).value != '') {
			var cats	= '';
			var num		= 0;
			var length	= document.getElementById(Category[idx]).length;
			for (i = 0; i < length; i++) {
				if (document.form1.elements[Category[idx]][i].selected)
					cats += document.form1.elements[Category[idx]][i].value + '|';
			}
			QString += "&" + Category[idx] + "=" + cats;
		}
	}
/*
	// add other fields
	if (document.getElementById('CompanyName') && document.getElementById('CompanyName').value != '')
		QString += "&CompanyName="+document.getElementById('CompanyName').value;
	if (document.getElementById('Address1') && document.getElementById('Address1').value != '')
		QString += "&Address1="+document.getElementById('Address1').value;
	if (document.getElementById('Address2') && document.getElementById('Address2').value != '')
		QString += "&Address2="+document.getElementById('Address2').value;
	if (document.getElementById('City') && document.getElementById('City').value != '')
		QString += "&City="+document.getElementById('City').value;
	if (document.getElementById('State') && document.getElementById('State').value != '')
		QString += "&State="+document.getElementById('State').value;
	if (document.getElementById('Zipcode') && document.getElementById('Zipcode').value != '')
		QString += "&Zipcode="+document.getElementById('Zipcode').value;
	if (document.getElementById('Phone') && document.getElementById('Phone').value != '')
		QString += "&Phone="+document.getElementById('Phone').value;
	if (document.getElementById('Cell') && document.getElementById('Cell').value != '')
		QString += "&Cell="+document.getElementById('Cell').value;
	if (document.getElementById('Fax') && document.getElementById('Fax').value != '')
		QString += "&Fax="+document.getElementById('Fax').value;
	if (document.getElementById('Email') && document.getElementById('Email').value != '')
		QString += "&Email="+document.getElementById('Email').value;
	if (document.getElementById('Website') && document.getElementById('Website').value != '')
		QString += "&Website="+document.getElementById('Website').value;
	if (document.getElementById('LogoURL') && document.getElementById('LogoURL').value != '')
		QString += "&LogoURL="+document.getElementById('LogoURL').value;
	if (document.getElementById('ShortDescr') && document.getElementById('ShortDescr').value != '')
		QString += "&ShortDescr="+document.getElementById('ShortDescr').value;
	if (document.getElementById('Descr') && document.getElementById('Descr').value != '')
		QString += "&Descr="+document.getElementById('Descr').value;
	if (document.getElementById('SponsorTitle') && document.getElementById('SponsorTitle').value != '')
		QString += "&SponsorTitle="+document.getElementById('SponsorTitle').value;
	if (document.getElementById('SponsorLine1') && document.getElementById('SponsorLine1').value != '')
		QString += "&SponsorLine1="+document.getElementById('SponsorLine1').value;
	if (document.getElementById('SponsorLine2') && document.getElementById('SponsorLine2').value != '')
		QString += "&SponsorLine2="+document.getElementById('SponsorLine2').value;
	if (document.getElementById('SponsorLine3') && document.getElementById('SponsorLine3').value != '')
		QString += "&SponsorLine3="+document.getElementById('SponsorLine3').value;
	if (document.getElementById('LocationId') && document.getElementById('LocationId').value != '')
		QString += "&LocationId="+document.getElementById('LocationId').value;
*/
	window.location = ReturnPage+"?"+QString;
}
function checkEnter(e) {			//e is event object passed from function invocation
	var characterCode;				// literal character code will be stored in this variable
	if (e && e.which) {				//if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; 	//character code is contained in NN4's which property
	} else {
		e = event;
		characterCode = e.keyCode;	//character code is contained in IE's keyCode property
	}
	if (characterCode == 13) {		//if generated character code is equal to ascii 13 (if enter key)
		setZip();
	}
}
function isEnter(e) {			//e is event object passed from function invocation
	var characterCode;				// literal character code will be stored in this variable
	if (e && e.which) {				//if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; 	//character code is contained in NN4's which property
	} else {
		e = event;
		characterCode = e.keyCode;	//character code is contained in IE's keyCode property
	}
	//if generated character code is equal to ascii 13 (if enter key)
	return characterCode == 13 ? true : false;
}
function intOnly(i) {
	if (i.value != "Enter Zipcode") {
		// only allow integers
		if (i.value.length > 0)
			i.value = i.value.replace(/[^\d]+/g, ''); 
	}
}
function setZip() {
	var City	= document.getElementById('SetCity').value;
	var State	= document.getElementById('SetState').value;
	var Zipcode = document.getElementById('SetZipcode').value;
	if (City == "Enter City" && State == "" && Zipcode == "Enter Zipcode")
		alert("Oops! Please enter City, State and/or Zipcode first.");
	else
		window.location = 'setzip.php?C='+City+'&S='+State+'&Z='+Zipcode;
/*	if (Zipcode != "Enter Zipcode" && Zipcode != "")
		window.location = 'setzip.php?Z=' + Zipcode;
	else {
		if (City != "Enter City" && City != "" && State != "")
			window.location = 'setzip.php?C=' + City + '&S=' + State;
		else
			alert("Please enter a City and State or Zipcode and try again.");
	}*/
}
function setCharCount(id,value,length){
	var maxValue = length;

	// if value > maxValue, only return the first maxValue characters
	if (value >= maxValue)
		document.getElementById(id).value = document.getElementById(id).value.substring(0,maxValue);

	// set the count display
	document.getElementById('Count'+id).value = '['+document.getElementById(id).value.length+' of '+maxValue+' characters]';
}
function setDropColor(id, text) {
	if (document.getElementById(id)) {
		if (document.getElementById(id).value == text)
			document.getElementById(id).style.color = '#666666';
		else
			document.getElementById(id).style.color = '#000000';
	}
}
function OOGLEizer(totalNum) {
	// get a random number
	if (document.getElementById('OOGLEizedOrgId').value != "" && totalNum > 1) {
		currentRandNum = document.getElementById('OOGLEizedOrgId').value;
		do {
			var randNum = Math.floor(Math.random()*totalNum+1);
		} while (currentRandNum == randNum);
	} else
		var randNum = Math.floor(Math.random()*totalNum+1);

	// get data from random sponsor listing & copy it to the OOGLE-ized Sponsor
	document.getElementById('OOGLEizedOrgId').value				= randNum;
	document.getElementById('OOGLEizedLink').href				= "profile.php?OrgId=" + document.getElementById('Sponsor'+randNum+'OrgId').value;
	document.getElementById('OOGLEizedCompanyName').value		= document.getElementById('Sponsor'+randNum+'CompanyName').value;
	if (document.getElementById('Sponsor'+randNum+'ShortDescr').value != '') {
		document.getElementById('OOGLEizedShortDescr').value	= document.getElementById('Sponsor'+randNum+'ShortDescr').value;
	} else
		document.getElementById('OOGLEizedShortDescr').value	= '';
	if (document.getElementById('Sponsor'+randNum+'Address').value != '')
		document.getElementById('OOGLEizedAddress').value		= document.getElementById('Sponsor'+randNum+'Address').value;	
	else
		document.getElementById('OOGLEizedAddress').value		= '';

	// show the OOGLEizer table
	document.getElementById('OOGLEizerTable').style.display = '';
}
// this function will only hide a table
function hideOneTable(id) {
	if (document.getElementById(id))
		document.getElementById(id).style.display = 'none';
}
// this function will only show a table
function showOneTable(id) {
	if (document.getElementById(id))
		document.getElementById(id).style.display = '';
}
// change between plus and minus button for minimize and maximize look
function switchPlusMinus(id) {
	if (document.getElementById(id)) {
		if (document.getElementById(id).style.display == 'none')
			document.getElementById('Image'+id).src = 'assets/b_plus.gif';
		else
			document.getElementById('Image'+id).src = 'assets/b_minus.gif';
	}
}
// change font color of id
function setPageColor(id, color) {
	if (document.getElementById(id))
		document.getElementById(id).style.color = color;	
}
// used on listings.php for the "prev" links
function prevPage(totalPages) {
	for (idx=0; idx<=totalPages; idx++) {
		if (document.getElementById('Page'+idx).style.display == '')
			var showPageNum											= idx-1;		// get page # of next page
		if (showPageNum!=-1) {
			document.getElementById('Page'+idx).style.display		= 'none';		// hide all pages
			setPageColor('PageColor'+idx,'#000');									// set color back to black
		}
	}
	if (showPageNum == 0) {
		document.getElementById('PrevPage').style.color				= '#aaa';
		document.getElementById('PrevPage').style.cursor			= 'default';
	}
	if (document.getElementById('Page'+showPageNum)) {
		document.getElementById('NextPage').style.color				= '#000';		// next page to black
		document.getElementById('NextPage').style.cursor			= 'pointer';	// next page to pointer
		document.getElementById('Page'+showPageNum).style.display	= '';			// show next page
		document.getElementById('CurrentPage').value				= showPageNum;
		setPageColor('PageColor'+showPageNum,'#ff0000');								// set color to red
	}
}
// used on listings.php for the "next" links
function nextPage(totalPages) {
	for (idx=0; idx<totalPages; idx++) {
		if (document.getElementById('Page'+idx).style.display == '')
			var showPageNum											= idx+1;		// get page # of next page
		document.getElementById('Page'+idx).style.display			= 'none';		// hide all pages
		setPageColor('PageColor'+idx,'#000');										// set color back to black
	}
	if (showPageNum == totalPages) {
		document.getElementById('NextPage').style.color				= '#aaa';
		document.getElementById('NextPage').style.cursor			= 'default';
	}
	if (document.getElementById('Page'+showPageNum)) {
		document.getElementById('PrevPage').style.color				= '#000';		// prev page to black
		document.getElementById('PrevPage').style.cursor			= 'pointer';	// prev page to pointer
		document.getElementById('Page'+showPageNum).style.display	= '';			// show next page
		document.getElementById('CurrentPage').value				= showPageNum;
		setPageColor('PageColor'+showPageNum,'#ff0000');							// set color to red
	}
}
// show/hide the search box (enter city state zipcode area)
function showSearchBox(id) {
	// first hide all tables
	document.getElementById('ShowSearch').style.display = 'none';
	document.getElementById('HideSearch').style.display = 'none';

	if (document.getElementById(id).style.display == '')
		document.getElementById(id).style.display = 'none';
	else
		document.getElementById(id).style.display = '';
}
// show/hide X num of hour fields (depends on how the datestart and dateend span)
function showTimeFields() {
	if (document.getElementById('DateStart') && document.getElementById('DateEnd') && document.getElementById('DateStart').value != '' && document.getElementById('DateEnd').value != '') {
		var TempStart	= document.getElementById('DateStart').value;
		var TempEnd		= document.getElementById('DateEnd').value;
		var DateStart	= new Date(TempStart.substring(6,10), TempStart.substring(0,2)-1, TempStart.substring(3,5));
		var DateEnd		= new Date(TempEnd.substring(6,10),   TempEnd.substring(0,2)-1,   TempEnd.substring(3,5));
		var one_day		= 1000*60*60*24	// set 1 day in milliseconds
		var NumDays		= Math.ceil((DateEnd.getTime()-DateStart.getTime())/(one_day)) + 1;	// add 1 because this returns the # of days btw

		// show the hour fields or show err msg
		if (NumDays >= 1 && NumDays <= 7) {
			// first hide all the tables incase this was already used (because in that case, fields would be visible)
			document.getElementById('HourError').value					= '';
			document.getElementById('HourErrorTable').style.display 	= 'none';
			for (idx=1;idx<=7;idx++)
				document.getElementById('HourTable'+idx).style.display	= 'none';

			// now show the neccessary amount of hour tables
			for (idx=1;idx<=NumDays;idx++) {
				document.getElementById('StartTime'+idx).value			= new Date(DateStart.getTime() + (idx-1)*24*60*60*1000).toDateString();
				document.getElementById('HourTable'+idx).style.display	= '';
			}
		} else {
			// first hide all the tables incase this was already used (because in that case, fields would be visible)
			for (idx=1;idx<=7;idx++)
				document.getElementById('HourTable'+idx).style.display	= 'none';

			// now show the error msg
			if (NumDays <= 0)
				document.getElementById('HourError').value				= "Oops! Date span cannot be negative.";
			else
				document.getElementById('HourError').value				= "Oops! Date span can only be 1 week.";
			document.getElementById('HourErrorTable').style.display		= '';
		}
	} else {
		// if datestart && dateend fields exist, show err msg
		if (document.getElementById('DateStart') && document.getElementById('DateEnd')) {		
			// first hide all the tables incase this was already used (because in that case, fields would be visible)
			for (idx=1;idx<=7;idx++)
				document.getElementById('HourTable'+idx).style.display	= 'none';
	
			// now show the error msg
			document.getElementById('HourError').value					= "First select a Start Date & End Date.";
			document.getElementById('HourErrorTable').style.display		= '';
		}
	}
}
// when the first start & end times are set, change the rest to match
function setTimeFields(type, value) {
	for (idx=1;idx<=7;idx++) {
		document.getElementById(type+idx).value = value;
	}
}

<!-- AJAX USING PROTOTYPE.JS -->
/*
// Set promotional code entered during check out.
function set_promo_code(promo_code) {
	document.getElementById('promo_code_msg').innerHTML = '';
	var promo_code = document.getElementById('PromoCode').value;
	new Ajax.Request('../account/checkoutpromo.php', {
		method: 'post',
		parameters: {PromoCode: promo_code},
		onSuccess: function(transport) {
			var promo_code_msg = transport.responseText;
//			alert(promo_code_msg);
			document.getElementById('promo_code_msg').innerHTML = promo_code_msg;
		}
	});
}
*/













