function popHelpOnce(navurl,cookieName){
	var tempName = cookieName;
	var temp1 = getCookie(cookieName);
	//alert("cookie is " + temp1);
	if (temp1 == "true"){
		// do nothing
	}else{
		setCookie(tempName,'true');
		var newwin = window.open(navurl,"","height=425,width=500,scrollbars=yes,left=5,top=5");
	}
}


function setCookie(name, value, expires, path, domain, secure) {
path = "/"
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}



function deleteCookie(name,value) {
  var exp = new Date();
  exp.setTime(exp.getTime() - 1);
  var cookieVal = getCookie(name);
  if (cookieVal != null)
  		//alert("deleting cookie: "+name);
			var expires = "; expires=Thu, 2 Aug 2001 20:47:11 UTC";
			document.cookie=name+"="+value+expires+"; path=/";
 

}

function setCookieFnaff() {
  if (document.cookie){
  	//alert("there is a cookie");
  	var cookieValue = getCookie('fnaff');
  	//alert("the cookie's value is: "+ cookieValue);
  } 
  if (cookieValue && (cookieValue != '---' || location.search.search(/fnodeals/) == -1 )){
	  //alert("fnaff exists not setting cookie");
	  return;
  } else {
	  var expiry = new Date ();
	  var name = 'fnaff';
	  var value = '---';
	  var matches = location.search.substring(1).match(/^(fn[0-9a-z]+)/);
	  if (!matches) matches = location.search.substring(1).match(/\bfn=(fn[0-9a-z]+)/);
	  if (matches && matches[1]) {
		  value = matches[1];
		  // 1 year
		  expiry.setTime (expiry.getTime() + (24 * 60 * 60 * 1000 * 365));
	  } else {
		  // 3 months
	  	  expiry.setTime (expiry.getTime() + (24 * 60 * 60 * 1000 * 91));
	  }
	  // alert(name + "=" + value + "; expires=" + expiry.toGMTString() +  "; path=/");
	  document.cookie = name + "=" + value + "; expires=" + expiry.toGMTString() +  "; path=/";
  }
}

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function validate_fno_search(form){
//  ("State_local = " + form.State_local.selectedIndex + " and S_date_mo = " + form.S_date_mo.selectedIndex);
    if ( form.miles && form.miles.selectedIndex > 0 ) {
      if (form.State_local && form.State_local.type == 'select-one') form.State_local.selectedIndex=0;
      if (form.State && form.State.type == 'select-one') form.State.selectedIndex=0;
      if (matches = form.zip.value.match(/^ *([A-Z][0-9][A-Z])[ -]?([0-9][A-Z][0-9]) *$/i)) form.zip.value = matches[1].toUpperCase()+' '+matches[2].toUpperCase();
      if (form.zip.value == "" || form.zip.value == "Zip" || !form.zip.value.match(/^[0-9]{5}|[A-Z][0-9][A-Z] [0-9][A-Z][0-9]$/i)) {
         alert("Please enter a 5-digit zip code or A0A 0A0 type Canadian code for the radius search."); return false;
      }
    }
    if ( form.zip && form.zip.value != "" && form.zip.value != "Zip" ) {
      if (form.State_local && form.State_local.type == 'select-one') form.State_local.selectedIndex=0;
      if (form.State && form.State.type == 'select-one') form.State.selectedIndex=0;
      if (form.miles.selectedIndex == 0) {
         alert("Please select a distance for the zip radius search."); return false;
      } else if(!form.Type) {
       if (form.S_date_mo.selectedIndex == 0 && form.miles[form.miles.selectedIndex].value > 200) {
         alert("Please select a month for this radius search distance."); return false;
       }
      }
    }
    if (form.Type) {
	    // I would like to remove the state and month requirement here, http://bfdnet.net/home_and_garden.html
	    // We need to keep the requirement that they enter a zip if a distance is selected.
    } else if (form.State && form.State.type == 'select-one' || form.State_local && form.State_local.type == 'select-one')  {
	    if (form.State_local && form.State_local.selectedIndex || form.State && form.State.selectedIndex || form.S_date_mo.selectedIndex) {
	    } else {
	     if (form.zip && ( form.zip.value == "" || form.zip.value == "Zip") && form.miles.selectedIndex == 0) {
		alert("Please select a State or Month and State or Zip/Distance."); return false;
	     }
	    }
	    if ((form.State_local && form.State_local.selectedIndex == 0 || form.State && form.State.selectedIndex == 0)
		&& form.S_date_mo.selectedIndex !=0 && form.zip && (form.zip.value == "" || form.zip.value == "Zip")) {
		    alert("Please select a State or Month and State or Zip/Distance."); return false;
	    }
	    if (!form.zip && form.State_local && form.S_date_mo && (form.State_local.selectedIndex == 0 || form.S_date_mo.selectedIndex == 0)) {
		//fno_help_cp_myCalendar
		alert("Please select a State and Month."); return false;
	    }
    } else {
	    // hidden state field in state specific pages
	    if (form.City_local && (!form.City_local || form.City_local.value == "") && form.S_date_mo.selectedIndex == 0 && (form.zip.value == "" || form.zip.value == "Zip")) {
// They can search making no selections except zip search above
//		    alert("Please select "+(form.City_local && form.City_local.type != 'hidden' ? "City or ":"")+"a Month or Zip/Distance."); return false;
	    }
    }
    if (form.zip && form.zip.value == "Zip") form.zip.value = "";
    return true;
}

function validate_loginForm(form) {
var invalid = " "; // Invalid character is a space
if (form.userid.value == '') {
	alert("Please enter User ID.");
	form.userid.focus();
	return false;
}
if (form.pw.value == '') {
	alert("Please enter password.");
	form.pw.focus();
	return false;
}
// check for spaces
if (form.userid.value.indexOf(invalid) > -1) {
	alert("Sorry, spaces are not allowed in your User ID.");
	form.userid.focus();
	return false;
}
if (form.pw.value.indexOf(invalid) > -1) {
	alert("Sorry, spaces are not allowed in your Password.");
	form.pw.focus();
	return false;
}
return login_form_submitted(form);
}

var fno_form_to_submit;
/*
function get_iframeDoc(iframe) {
	var iframeDoc;
	if (iframe.contentDocument) {
	iframeDoc = iframe.contentDocument;
	} else if (iframe.contentWindow) {
	iframeDoc = iframe.contentWindow.document;
	} else if (window.frames[iframe.name]) {
	iframeDoc = window.frames[iframe.name].document;
	}
	return iframeDoc;
}

function jr_iframe_loaded() {
	var iframe = document.getElementById('iframe0');
	var iframeDoc = get_iframeDoc(iframe);
	//  <h2>» Invalid Username / Password - Please try again</h2>
	var msg = '';
	var h2s = iframeDoc.getElementsByTagName('h2');
	for (i=0; i<h2s.length; i++) {
		msg += h2s[i].innerHTML;
	}
	if (msg != '') {
		alert("FNO login: "+msg);
	}
	fno_form_to_submit.submit();


} 

function login_form_submitted_brokenFF2(form) {
fno_form_to_submit = form;
var iframe = createIframe ('iframe0', 3, 3);
if (iframe) {
	iframe.id = 'iframe0';
	document.body.appendChild(iframe);
	var iframeDoc = get_iframeDoc(iframe);
	if (iframeDoc) {
		iframeDoc.open();
		iframeDoc.write( '<html><body><form method="post" target="_self" action="/fno/login.php" name="jr_login_form" id="jr_login_form"><input type="text" name="jm_user" value=""><input type="password" name="jm_pass" value=""></form><\/body><\/html>');
		iframeDoc.close();
		iframeDoc.jr_login_form.jm_user.value = form.userid.value;
		iframeDoc.jr_login_form.jm_pass.value = form.pw.value;
		iframeDoc.jr_login_form.submit();
		if (iframe.addEventListener) {
			//"DOMContentLoaded"
			iframe.addEventListener("load", jr_iframe_loaded, false);
		} else if(iframe.attachEvent) {
			iframe.attachEvent("onload", jr_iframe_loaded);
		} else {
			alert("Can't login into JamRoom - javascript problem with your browser.");
			return true;
		}
		if(form.login2) {
			form.login2.value='Wait..';
		} else {
			form.login.value='Wait..';
		}
	}
}
	return false;
}
*/

/*
 * Copyright 2006 SitePoint Pty. Ltd, www.sitepoint.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS;
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

function Ajax() {
  this.req = null;
  this.url = null;
  this.status = null;
  this.statusText = '';
  this.method = 'GET';
  this.async = true;
  this.dataPayload = null;
  this.readyState = null;
  this.responseText = null;
  this.responseXML = null;
  this.handleRespPar = null;
  this.handleResp = null;
  this.responseFormat = 'text', // 'text', 'xml', 'object'
  this.mimeType = null;
  this.headers = [];

  
  this.init = function() {
    var i = 0;
    var reqTry = [ 
      function() { return new XMLHttpRequest(); },
      function() { return new ActiveXObject('Msxml2.XMLHTTP') },
      function() { return new ActiveXObject('Microsoft.XMLHTTP' )} ];
      
    while (!this.req && (i < reqTry.length)) {
      try { 
        this.req = reqTry[i++]();
      } 
      catch(e) {}
    }
    return true;
  };
  this.doGet = function(url, hand, par, format) {
    this.url = url;
    this.handleRespPar = par;
    this.handleResp = hand;
    this.responseFormat = format || 'text';
    this.doReq();
  };
  this.doPost = function(url, dataPayload, hand, par, format) {
    this.url = url;
    this.dataPayload = dataPayload;
    this.handleRespPar = par;
    this.handleResp = hand;
    this.responseFormat = format || 'text';
    this.method = 'POST';
    this.doReq();
  };
  this.doReq = function() {
    var self = null;
    var req = null;
    var headArr = [];
    
    if (!this.init()) {
      alert('Could not create XMLHttpRequest object.');
      return;
    }
    req = this.req;
    req.open(this.method, this.url, this.async);
    if (this.method == "POST") {
      this.req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    }
    if (this.method == 'POST') {
      req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    }
    self = this;
    req.onreadystatechange = function() {
      var resp = null;
      self.readyState = req.readyState;
      if (req.readyState == 4) {
        
        self.status = req.status;
        self.statusText = req.statusText;
        self.responseText = req.responseText;
        self.responseXML = req.responseXML;
        
        switch(self.responseFormat) {
          case 'text':
            resp = self.responseText;
            break;
          case 'xml':
            resp = self.responseXML;
            break;
          case 'object':
            resp = req;
            break;
        }
        
        if (self.status > 199 && self.status < 300) {
          if (!self.handleResp) {
            alert('No response handler defined ' +
              'for this XMLHttpRequest object.');
            return;
          }
          else {
            self.handleResp(self.handleRespPar, resp);
          }
        }
        
        else {
          self.handleErr(resp);
        }
      }
    }
    req.send(this.dataPayload);
  };
  this.abort = function() {
    if (this.req) {
      this.req.onreadystatechange = function() { };
      this.req.abort();
      this.req = null;
    }
  };
  this.handleErr = function() {
    var errorWin;
    // Create new window and display error
    try {
      errorWin = window.open('', 'errorWin');
      errorWin.document.body.innerHTML = this.responseText;
    }
    // If pop-up gets blocked, inform user
    catch(e) {
      alert('An error occurred, but the error message cannot be' +
      ' displayed because of your browser\'s pop-up blocker.\n' +
      'Please allow pop-ups from this Web site.');
    }
  };
  this.setMimeType = function(mimeType) {
    this.mimeType = mimeType;
  };
  this.setHandlerResp = function(funcRef) {
    this.handleResp = funcRef;
  };
  this.setHandlerErr = function(funcRef) {
    this.handleErr = funcRef; 
  };
  this.setHandlerBoth = function(funcRef) {
    this.handleResp = funcRef;
    this.handleErr = funcRef;
  };
  this.setRequestHeader = function(headerName, headerValue) {
    this.headers.push(headerName + ': ' + headerValue);
  };
  
}

/* END
 * Copyright 2006 SitePoint Pty. Ltd, www.sitepoint.com
 *
*/


function login_form_ajax_response(f,str) {
	var msg = '';
	var matches = str.match(/<h2>([^<]*)/i);
	if (matches && matches[1]) msg += matches[1];
	if(fno_form_to_submit.login2) {
		fno_form_to_submit.login2.value=fno_form_to_submit.login2.defaultValue;
	} else {
		fno_form_to_submit.login.value=fno_form_to_submit.login.defaultValue;
	}
	if (msg != '') {
		var span = document.createElement('span');
		span.innerHTML = msg;
		alert("FNO login: "+span.innerHTML);
	}
	fno_form_to_submit.submit();
}

function login_form_submitted(form) {
	return true;
	fno_form_to_submit = form;
	var ajax = new Ajax();
	if(form.login2) {
		form.login2.value='Wait..';
	} else {
		form.login.value='Wait..';
	}
	ajax.doPost('/fno/login.php','jm_user='+escape(form.userid.value)+'&jm_pass='+escape(form.pw.value),login_form_ajax_response, '', 'text');
	return false;
}

function logout_form_ajax_response(f,str) {
	var msg = '';
	var matches = str.match(/<h2>([^<]*)/i);
	if (matches && matches[1]) msg += matches[1];
	fno_form_to_submit.logout2.value=fno_form_to_submit.logout2.defaultValue;
	if (msg != '') {
		var span = document.createElement('span');
		span.innerHTML = msg;
		alert("FNO logout: "+span.innerHTML);
	}
	fno_form_to_submit.submit();
}

function logout_form_submitted(form) {
	return true;
	fno_form_to_submit = form;
	var ajax = new Ajax();
	form.logout2.value='Wait..';
	ajax.doGet('/fno/index.php?mode=logout',logout_form_ajax_response, '', 'text');
	return false;
}

/*
function createIframe (iframeName, width, height) {
	var iframe;
	if (document.createElement && (iframe = document.createElement('iframe'))) {
		iframe.name = iframe.id = iframeName;
		iframe.width = width;
		iframe.height = height;
		iframe.style.display = 'none';
		iframe.src = 'about:blank';
		document.body.appendChild(iframe);
	}
	return iframe;
}

function logout_form_submitted(form) {
fno_form_to_submit = form;
var iframe = createIframe ('iframe0', 3, 3);
if (iframe) {
	var iframeDoc = get_iframeDoc(iframe);
	if (iframeDoc) {
		iframeDoc.open();
		iframeDoc.write( '<html><body><form method="get" target="_self" action="/fno/index.php" name="jr_logout_form" id="jr_logout_form"><input type="text" name="mode" value="logout"></form><\/body><\/html>');
		iframeDoc.close();
		iframeDoc.jr_logout_form.submit();
		if (iframe.addEventListener) {
			iframe.addEventListener("load", jr_iframe_loaded, false);
		} else if(iframe.attachEvent) {
			iframe.attachEvent("onload", jr_iframe_loaded);
		} else {
			alert("Can't logout out of JamRoom - javascript problem with your browser.");
			return true;
		}
		form.logout.value='Wait..';
	}
}
	return false;
}
*/

var w=null;
function popHelp(navurl)
{
var newwin = window.open(navurl,"","height=550,width=720,scrollbars=yes,left=5,top=5");
}
function popHelp2(navurl)
{
var newwin = window.open(navurl,"","height=475,width=670,scrollbars=yes,left=5,top=5");
}
function float_page(navurl)
{
var newwin = window.open(navurl,"w_float","height=465,width=750,toolbar=yes,location=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,left=5,top=5");
}

function print_page() {
	onerror=null;
	if (el=document.getElementById('printable')) {
		document.body.innerHTML=el.innerHTML;
	}
	for (i=0; i<5; i++) {
		if (el=document.getElementById('printable'+i)) {
			el.style.display='';
		}
		if (el=document.getElementById('nonprintable'+i)) {
			el.style.display='none';
		}
	}
	window.print();
}

function urlencode(str) {
str = escape(str);
str = str.replace(/\+/g, '%2B');
//str = str.replace(/%20/g, '+');
str = str.replace(/\*/g, '%2A');
str = str.replace(/\//g, '%2F');
str = str.replace(/@/g, '%40');
return str;
}

function urldecode(str) {
str = str.replace(/\\+/g, ' ');
str = unescape(str);
return str;
}

var alerted = false;
function tooLongDelayed(ta) {
    setTimeout(function(){tooLong(ta); ta = null}, 10);
}
function tooLong(ta) {
    var l = ta.value.length;
    if (document.getElementById('Description_length')) document.getElementById('Description_length').innerHTML = l;
    var max_length = document.getElementById('Description_max_length') ? parseInt(document.getElementById('Description_max_length').innerHTML) : 450;
    if (l > max_length) {
	    if (!alerted) {
		    alerted = true;
		    alert('Please limit your description to '+max_length+' characters. \n Do not use all CAPS or quotes " ".');
	    }
	    ta.value = ta.value.substring(0, max_length);
	    if (document.getElementById('Description_length')) document.getElementById('Description_length').innerHTML = String(max_length);
	    ta.focus();
    }
}

function showHideDescription(Fest_biz_search_Yes) {
    d = document.getElementById('Description_all'); 
    if (d) {
	d.style.display = Fest_biz_search_Yes.checked ? '':'none';
    }
}
// create an instance of the Date object
var now = new Date();
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);

// get affiliate num
setCookieFnaff();
