pathPrefix = window.location.hostname;
if (pathPrefix == "localhost"){
	pathPrefix = "http://" + pathPrefix + "/FreshandEasy2009/";
}
else {
	if (window.location.href.indexOf("_qa") != -1) {
		pathPrefix = "http://" + pathPrefix + "/FreshandEasy_qa/";
	}
	else if (window.location.href.indexOf("_dev") != -1) {
		pathPrefix = "http://" + pathPrefix + "/FreshandEasy_dev/";
	}
	else {
		pathPrefix = "http://" + pathPrefix + "/";
	}
}

function global_urlEncode (inString) {
	var outString = inString;
	outString = outString.replace(/%22/g,'"'); // This is undo previous escapes necessary to get the string passed in the first place.
	outString = outString.replace(/%/g,'%25');
	outString = outString.replace(/&/g,'%26');
	outString = outString.replace(/\?/g,'%3F');
	outString = outString.replace(/"/g,'%22');
	outString = outString.replace(/\+/g,'%2B');
	return outString;
}

function privacyPop(){
 	screenwidth = screen.availWidth;
	screenheight = screen.availHeight;
	thisWidth = 550;
	thisHeight = 450;
	thisLeft = ((screenwidth - thisWidth)/2);
	thisTop = ((screenheight - thisHeight)/2);
	optionString = ('width=' + thisWidth + ',height=' + thisHeight + ',top=' + thisTop + ',left=' + thisLeft + ',status=no,menubar=no,resizable=no,scrollbars=yes,toolbar=no');
	window.open(pathPrefix + "Content/static_html/privacy.html",'privacy',optionString);
}

function SelectActiveMoreIdeasTab( img )
{	
	if(img == 'imgBreakfast')
	{ document.getElementById(img).src = 'images/moreIdeas/topNav_breakfast_on.gif'; }
	if(img == 'imgLunch')
	{ document.getElementById(img).src = 'images/moreIdeas/topNav_lunch_on.gif'; }
	if(img == 'imgSalad')
	{ document.getElementById(img).src = 'images/moreIdeas/topNav_salad_on.gif'; }
	if(img == 'imgDesserts')
	{ document.getElementById(img).src = 'images/moreIdeas/topNav_desserts_on.gif'; }
	if(img == 'imgEnter')
	{ document.getElementById(img).src = 'images/moreIdeas/topNav_enter_on.gif'; }
	if(img == 'imgFeature')
	{ document.getElementById(img).src = 'images/moreIdeas/topNav_feature_on.gif'; }
	if(img == 'imgGrill')
	{ document.getElementById(img).src = 'images/moreIdeas/topNav_grill_on.gif'; }
	if(img == 'imgBeverages')
	{ document.getElementById(img).src = 'images/moreIdeas/topNav_beverages_on.gif'; }
	if(img == 'imgKid')
	{ document.getElementById(img).src = 'images/moreIdeas/topNav_kid_on.gif'; }
	//alert(a + img);
}

function newsPop(article){
 	screenwidth = screen.availWidth;
	screenheight = screen.availHeight;
	thisWidth = 550;
	thisHeight = 450;
	thisLeft = ((screenwidth - thisWidth)/2);
	thisTop = ((screenheight - thisHeight)/2);
	optionString = ('width=' + thisWidth + ',height=' + thisHeight + ',top=' + thisTop + ',left=' + thisLeft + ',status=no,menubar=no,resizable=no,scrollbars=yes,toolbar=no');
	window.open(pathPrefix + article + ".html",'news',optionString);
}

function termsPop(){
 	screenwidth = screen.availWidth;
	screenheight = screen.availHeight;
	thisWidth = 550;
	thisHeight = 450;
	thisLeft = ((screenwidth - thisWidth)/2);
	thisTop = ((screenheight - thisHeight)/2);
	optionString = ('width=' + thisWidth + ',height=' + thisHeight + ',top=' + thisTop + ',left=' + thisLeft + ',status=no,menubar=no,resizable=no,scrollbars=yes,toolbar=no');
	window.open(pathPrefix + "Content/static_html/terms.html",'terms',optionString);
}

function getPDF(pdfName){
	//optionString = ('width=' + thisWidth + ',height=' + thisHeight + ',top=' + thisTop + ',left=' + thisLeft + ',status=no,menubar=no,resizable=no,scrollbars=no,toolbar=no');
	optionString = "";
	window.open(pathPrefix + "pdf/" + pdfName + ".pdf",'PDF',optionString);
}

function isDigits(stringToSearch){
	var pattern = /[^0-9]/;
	if (stringToSearch.match(pattern)){
		return false;
	}
	else {
		return true;
	}
}

function isValidDateFormat(stringToSearch){
	var pattern = /\d{2}[\/-]\d{2}[\/-s]\d{4}/;
	if (stringToSearch.match(pattern)){
		return true;
	}
	else {
		return false;
	}
}

function isValidEmailFormat(stringToSearch){
	//var pattern = /[\w\d.]+[@]{1}[\w\d-]+[.]{1}\w{2,4}/;
	var pattern = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	if (stringToSearch.match(pattern)){
		return true;
	}
	else {
		return false;
	}
}

// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2005;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function validate(){
	//variables
	var undefined;
	var formcode = "";
	var firstname = "";
	var lastname = "";
	var address1 = "";
	var address2 = "";
	var company = "";
	var city = "";
	var state = "";
	var zip = "";
	var phone = "";
	var email = "";
	var whoareyou = "";
	var naturecomment = "";
	var errors = 0;
	var errortext = "There were some errors with your submission:\n";
	
	//check firstname - required
	firstname = document.forms[0].firstname.value;
	if ((firstname == "") || (firstname == undefined) || (firstname.length > 50)){
		errors += 1;
		errortext += "* You must enter your First Name, and it must be fifty(50) characters or less.\n";
	}
	//check lastname - required
	lastname = document.forms[0].lastname.value;
	if ((lastname == "") || (lastname == undefined) || (lastname.length > 50)){
		errors += 1;
		errortext += "* You must enter your Last Name, and it must be fifty(50) characters or less.\n";
	}
	//check email - required
	email = document.forms[0].email.value;
	if ((email == "") || (email == undefined) || (email.length > 100) || (!isValidEmailFormat(email))){
		errors += 1;
		errortext += "* You must enter your E-mail, it must be one-hundred(100) characters or less, and be of the format: 'user@domain.com'.\n";
	}
	//check whoareyou - required
	whoareyou = document.forms[0].whoareyou.value;
	if ((whoareyou == "") || (whoareyou == undefined) || (whoareyou.length > 50)){
		errors += 1;
		errortext += "* You must let us know who you are by selecting the appropriate category from the dropdown list.\n";
	}
	//check topic - required
	topic = document.getElementById('selectedTopic').value;
	if ((topic == "") || (topic == undefined)){
		errors += 1;
		errortext += "* You must let us know which topic your comment is about by clicking on a \"Choose A Topic\" radio button.\n";
	}
	//check nature of comment - required ONLY if "I'm a customer is selected"
	if (whoareyou == "customer") {
		naturecomment = document.forms[0].natureComment.value;
		if ((naturecomment == "") || (naturecomment == undefined) || (naturecomment.length > 50)){
			errors += 1;
			errortext += "* You must let us know the nature of your comment by selecting a choice from the dropdown list.\n";
		}
	}
	
	//alert(formcode+"/"+firstname+"/"+lastname+"/"+zip+"/"+email+"/"+whoareyou);
	if (errors > 0){
		alert(errortext);
		return false;
	}
	else {
		document.forms[0].submit();
		return true;
	}
}

//rollover functions for left nav
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function rollOver(imageRolled, status){
	eval("document." + imageRolled + ".src = " + imageRolled + "_" + status + ".src");
}


var BrowserDetect = {
	// Browser name: BrowserDetect.browser
	// Browser version: BrowserDetect.version
	// OS name: BrowserDetect.OS
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

