/*
<!--- AUTHOR: Davin Leier --->
<!--- DATE CREATED: 2007.11.02 --->
<!--- PURPOSE: Common Javascript functions and methods used throughout the site --->
<!--- REVISIONS: 
--->
*/

function openWindow(winURL, winName, failMessage) {
	if (!winURL) winURL = '/';
	if (!winName) winName = 'newWin';
	if (!failMessage) failMessage = 'You must allow popups in order to print this offer';
	winWidth = 750;
	winHeight = 600;
	winX = 10;
	winY = 10;		
	boolScrollBars = 0;
    
	newWinObject = window.open(winURL, winName,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=' + boolScrollBars + ',resizable=1,width=' + winWidth + ',height=' + winHeight + ',left=' +  winX + ',top=' + winY);

	if (newWinObject)	{
    // popup successfully created
		newWinObject.focus();
	} else {
	// popup was not created.
		alert(failMessage);
	}
	return newWinObject;
}

function authorizeUser() {
	var usn = document.getElementById("frmUsername").value;
	var pwd = document.getElementById("frmPassword").value;
	
	DWREngine._execute(_cfscriptLocation, null, 'validateUser', usn, pwd, showLoginMessage);
}
function showLoginMessage(objAjaxResponse){
	var boolIsValid = objAjaxResponse.BOOLRETURNVALUE;
	var message = objAjaxResponse.MESSAGE;
	var html = objAjaxResponse.HTML;
	if(boolIsValid == "true" || boolIsValid == "lockout"){
		replaceLoginForm(html);
	}else if(boolIsValid == "false"){
		document.getElementById("frmPassword").value = "";
	}
	alert(message);
}
function logout(){
	DWREngine._execute(_cfscriptLocation, null, 'logoutUser', showLogoutMessage);
}
function showLogoutMessage(objAjaxResponse){
	var boolIsValid = objAjaxResponse.BOOLRETURNVALUE;
	var message = objAjaxResponse.MESSAGE;
	var html = objAjaxResponse.HTML;
	alert(message);
	goTo('/');
}
function replaceLoginForm(replacementHTML){
	document.getElementById("memberLoginArea").innerHTML = replacementHTML;
}

function goTo(newURL){
	window.location = newURL;
}

function placeFocus() {
	if (document.forms.length > 0) {
		var field = document.forms[0];
		for (i = 0; i < field.length; i++) {
			if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")){
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}
}
