var _global = this;
var browser = navigator.appName;

// function for popups
function doStep(num){
	windowprops = "width=808,height=800,resizable=yes, scrollbars=yes, location=yes, left=20,top=20";
	theUrl='torders-s'+num+'.cfm';
	theStep=window.open(theUrl, 'theStep', windowprops);
	theStep.focus();
}

//function to show warning about pop-up blockers
_global.popUpWarningOn=false;
function popUpWarningInvisible(){
	for(i=1; i<6; i++){
		if(document.getElementById('popUpWarningDiv'+i))document.getElementById('popUpWarningDiv'+i).style.visibility='hidden';
	}
	_global.popUpWarningOn=false;
}
function showPopUpWarning(theObj, theStep){
	if(_global.popUpWarningOn==false){
		_global.popUpWarningOn=true;
		theWarning=document.getElementById('popUpWarningDiv'+theStep);
		theWarning.innerHTML='If nothing happens when you click this button, please make sure pop-up blockers are not blocking RiverCitySports.com.';
		theWarning.style.visibility='visible';
		setTimeout("popUpWarningInvisible()",3500);
	}
}

//function to close step pop-up window
function closeThisStep(){
	if(this.window.opener && !this.window.opener.closed){
		this.window.close();
		window.opener.focus();
	}
	else{
		location='torders.cfm';
	}
}

//trim whitespace from start and end of any string.
function trim(strText){
	strText=strText.replace(/^\s+/, '');
	strText=strText.replace(/\s+$/, '');
	return strText;
}

//function to open/close message window div
function msg(vis){
	if(vis == 0) document.getElementById('messageWin').style.visibility="hidden";
	else if(vis == 1) document.getElementById('messageWin').style.visibility="visible";
	else document.getElementById('messageWin').innerHTML=vis;
}

//function to close step pop-up window
function closeThisStep(){
	if(this.window.opener && !this.window.opener.closed){
		this.window.close();
		window.opener.focus();
	}
	else{
		location='torders.cfm';
	}
}

//unsynchonous http request for extras prefs submission *******************************
var finishRo;
function handleContactsResponse(){
	if(finishRo.readyState == 4){
		var response = trim(finishRo.responseText);
		if(finishRo.status == 200 && finishRo.responseText.indexOf('title06.gif') == -1 && finishRo.responseText.indexOf('messageheader.gif') == -1){
			msg(1);
			msg(response);
			setTimeout("msg(0)",10000);
		}
		else{
			msg(1);
			msg("We're sorry - an error ocurred.<BR>Click to close message.");
			setTimeout("msg(0)",10000);
		}
	}
}

//function to send email
function finish(){
	msg(1);
	msg('Sending...');
	if(browser == "Microsoft Internet Explorer") finishRo = new ActiveXObject("Microsoft.XMLHTTP");
	else finishRo = new XMLHttpRequest();
	finishRo.open('post', 'torders-finish-req.cfm');
	queryString='pageFunction=sendEmail';
	finishRo.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
    finishRo.send(queryString);
	finishRo.onreadystatechange = handleContactsResponse;
}