/************************************************
* ereserve.js                                   *
* written by jonnieboy and andy                 *
* 11/6/2009                                     *
*************************************************/

function amendWindowTitle(title) {
		document.title=title;
}

function getWindowTitleParameters(parameter, parentFlag) {
		var title = '';
		if (parentFlag == 1) {
			title = sessvars.myObj.address;
		} else {
			title = sessvars.myObj.radius;
		}
		return title;
}

function initStoreLocator() {
	//alert(window.frames["StoreLocatorIframe"].addressInput.value);
	//window.frames["StoreLocatorIframe"].searchLocations();
}

var qsParm = new Array();
function qs() {
	var query = document.location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			qsParm[key] = val;
		}
	}
} 

function isNumeric(x) {
// I use this function like this: if (isNumeric(myVar)) { } 
// regular expression that validates a value is numeric 
var RegExp = /^(-)?(\d*)(\.?)(\d*)$/; // Note: this WILL allow a number that ends in a decimal: -452. 
// compare the argument to the RegEx 
// the 'match' function returns 0 if the value didn't match 
var result = x.match(RegExp);
return result;
}


function globalReplace(str, searchStr, replaceStr) {
	var intIndexOfMatch = str.indexOf( searchStr );
	while (intIndexOfMatch != -1){
		// Relace out the current instance.
		str = str.replace( searchStr, replaceStr )
 		
		
		// Get the index of any next matching substring.
		intIndexOfMatch = str.indexOf( searchStr );
	}
 

	// Return the updated string with ALL the target strings
	// replaced out with the new substring.
	return( str );
}


function removeCtrls(str) {
	str=globalReplace(str, "%27", "");  //this replaces '
	str=globalReplace(str, "'", "");
    str=globalReplace(str, "%20", " ");	//this replaces space
	str=globalReplace(str, "%E9", "e");	//this replaces e acute
    str=globalReplace(str, "%E8", "e");	//this replaces e the other funny one
	str=globalReplace(str, "%E7", "c");	//this replaces c cedila
	str=globalReplace(str, "%E2", "a");	//this replaces a hat
	str=globalReplace(str, "%EA", "e");	//this replaces e hat
	str=globalReplace(str, "%F4", "o");	//this replaces o hat
return (str);
}

function writeImage(fullPath) {
	document.write("fullPath is " + fullPath);
}
		// Function CheckAll for leads.admin to check all boxes written by jonnytastic

function leadsCheckAll(f1) {
	len=f1.length;
		for (i=0; i<len;i++) {
		if (f1[i].id.toString().indexOf('approve')>0) {	
		
			f1[i].checked = f1.checkAll.checked;
		}
	}
}

// Function to save email contact information written by jonnytastic
function setCookie(inputForm){
	eraseCookie("chambresdhotes_org_contact_name");
    eraseCookie("chambresdhotes_org_contact_mail");
    eraseCookie("chambresdhotes_org_contact_comments");
	createCookie("chambresdhotes_org_contact_name", inputForm.Form_Contact_Name.value, 2);
	createCookie("chambresdhotes_org_contact_mail", inputForm.Form_Contact_Email.value, 2);
	createCookie("chambresdhotes_org_contact_comments", inputForm.Comments.value, 2);
}

function populateFields(inputForm){
	inputForm.Form_Contact_Name.value = readCookie("chambresdhotes_org_contact_name");
	inputForm.Form_Contact_Email.value = readCookie("chambresdhotes_org_contact_mail");
	inputForm.Comments.value = readCookie("chambresdhotes_org_contact_comments");
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) {
			var rtnStr = c.substring(nameEQ.length,c.length);
			return rtnStr;
		}
	}
	return '';

}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function openContactOwner(ownerId) {
		var conButId = '#conBut' +  ownerId;
		$(conButId).focus();
		$(conButId).click();
}
