function openInWindow(URL, winDisplay, toolBar, Location, directories, status, menuBar, scrollBar, reSizable, winWidth, winHeight){
	//'/demos/cgwm/', 'displayWindow', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 800, 600
	window.open(URL, winDisplay, "'toolbar=' + toolBar +', location=' + Location + ', directories=' + directories + ', status=' + status + ', menubar=' + menuBar + ', scrollbars=' + scrollBar + ', resizable=' + reSizable + ', width=' + winWidth + ', height=' + winHeight + '"); return false;
}

function openWMDemo(){
	window.open('/demos/cgwm/', 'displayWindow', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 800, 600); return false;
}

var Underlay = "Underlay";
var CTAcheckboxVal = 0;

function checkLoginFields(){
	
	var usernameValue = document.getElementById('usernameField').value;
	var passwordValue = document.getElementById('passwordField').value;
	
	if(usernameValue=='username' || usernameValue == "" || passwordValue == 'password' || passwordValue == ""){
		$('LoginError_Text').update('Welcome back, please fill in your correct username and password to login.');
		$('LoginErrorContainer').appear({duration: 0.2});
	}
	else {
		$('LoginErrorContainer').appear({duration: 0.2});
		$('LoginError_ContactUsBtn').appear(0);
		$('LoginError_Text').update('The login info you have entered appears to be incorrect. For further assistance, give us a call at <strong>617.338.8922</strong> and we&acute;ll help you out!');
	}
	//document.getElementById('Underlay').style.display = 'block';
}

function closeLoginError(){
	//document.getElementById('Underlay').style.display = 'none';
	$('LoginError_ContactUsBtn').fade();
	$('LoginErrorContainer').fade({duration: 0.2});
}

function closePopup(){
	//document.getElementById('Underlay').style.display = 'none';
	$('CTAContainer').fade({duration: 0.2});
	$('LoginPopupContainer').fade({duration: 0.2});
	$('LoginErrorContainer').fade({duration: 0.2});
}

function closeCTA(){
	//document.getElementById('Underlay').style.display = 'none';
	$('CTAContainer').fade({duration: 0.2});
}

function closeCTA2(){
	//document.getElementById('Underlay').style.display = 'none';
	$('CTAContainer').fade({duration: 0.2});
	
	var ajaxRequest = new Ajax.Request('/_commongoal/CTAprompt_ajax.cfc?method=CTACookieState', {
		method:       'post', 
		parameters:   {fakeParam:'No Deal'}, 
		asynchronous: true,
		onComplete:   responseClose,
    	onFailure: 	closeCTA2_failRespose
	});
}

function responseClose(xmlHttpRequest, responseHeader) {
    //alert(xmlHttpRequest.responseText);
	if(xmlHttpRequest.responseText != "0.00"){
		//alert(xmlHttpRequest.responseText);
		showCTA.delay(xmlHttpRequest.responseText);
		closeCTA();
	}
}
function closeCTA2_failRespose(xmlHttpRequest, responseHeader) {
	alert("closeCTA2_failRespose - failed");
}

function showCTA(){
	//document.getElementById('Underlay').style.display = 'block';
	$('CTAContainer').appear({duration: 0.2});
}

function submitCTA(){
	var errorText = "";
	
	if ($('FindCTAIrritating').value != 1) {
		if ($('CTA_Name').value == "") { errorText+="Please enter your name.\r\n"; }
		if ($('CTA_Phone').value == "") { errorText+="Please enter your phone number.\r\n"; }
	}
	
	if (errorText != "") {
		alert(errorText);
		return false;
	}
	
	var ajaxRequest = new Ajax.Request('/_commongoal/CTAprompt_ajax.cfc?method=processCTA', {
		method:       'post', 
		parameters:   {CTA_Name:$('CTA_Name').value, CTA_Phone:$('CTA_Phone').value, CTA_Thoughts:$('CTA_Thoughts').value, FindCTAIrritating:$('FindCTAIrritating').value}, 
		asynchronous: true,
		onComplete:   showResponse
	});
}

function showResponse(xmlHttpRequest, responseHeader) {
    closeCTA();
}

function toggleCTA_NoThanks(){
	$('FindCTAIrritating').value = 1;
	if (popupTimer)	window.clearTimeout(popupTimer);
	submitCTA();
}




