var loaded = false;
function trapint(form_name,formField) {
	frm = document.forms[form_name];
	var field = frm.elements[formField];
	if (field.value.length == 0) {
		if (event.keyCode==45 || (event.keyCode>46 && event.keyCode<58)) {
			return true;
		} else {
			event.returnValue = false;
			return false;
		}
	} else {
		if (event.keyCode>46 && event.keyCode<58) {
			return true;
		} else {
			event.returnValue = false;
			return false;
		}
	}
}
function trapfloat() {
	if (event.keyCode==13 || event.keyCode==8 || (event.keyCode>45 && event.keyCode<58)) {
		return true;
	} else {
		event.returnValue = false;
		return false;
	}
}
var str = "left=0,screenX=0,top=0,screenY=0";

if (window.screen) {
  var ah = 500;
  var aw = 650;
  str += ",height=" + ah;
  str += ",innerHeight=" + ah;
  str += ",width=" + aw;
  str += ",innerWidth=" + aw;
  str += ",scrollbars=yes";
  str += ",status=yes";
  str += ",resizable";
} else {
  str += ",resizable"; // so the user can resize the window manually
}

function launch(newURL, newName, newFeatures, orgName) {
	var PopWin = window.open(newURL, newName, newFeatures);
	if ((!PopWin) || (PopWin.opener == null)) {
		alert('Warning, a popup was blocked.  Please disable popup blocking for this request.')
		PopWin.opener = window;
		PopWin.opener.name = orgName;
	}
	return PopWin;
}

function launchPop(url) {
	if (!window.myPop || window.myPop.closed) {
		myPop = launch(url, "Popchild", str, "PopParent");
		myPop.focus();
	} else {
		myPop.location.href = url;
		myPop.focus();
	}
}

function save_maybes(){
	opener.location.href='index.html?action=login&save_maybes=true';
	self.close();
}

function closer(){
	opener.focus();
	self.close();
}
function MakeArray(n) {
	this.length = n;
	for (var i = 1; i <= n; i++) {
		this[i] = 0;
	}
	return this;
}
function pickSelectedId(elId, elVal) {
	var el = window.opener.document.getElementById(elId);
	for (i = 0; i < el.options.length; i++) {
		if (elVal == el.options[i].value) {
			el.selectedIndex = i;
		}
	}
	window.opener.focus();
	self.close();
}
function pickSelected(form,formField,Index){
	var frm = window.opener.document.forms[form];
	var field = frm.elements[formField];
	field.selectedIndex = Index;
	window.opener.focus();
	self.close();
}
var loadedStates = new Array();
var stateObj;
var updateStateRunning = false;
function updateStates(stateId, countryId) {
	if (true == updateStateRunning) {
		setTimeout('updateStates("'+stateId+'","'+countryId+'")',100);
		return;
	}
	if (false == window.loaded) {
		setTimeout('updateStates("'+stateId+'","'+countryId+'")',10);
		return;
	}
	updateStateRunning = true;
	countryObj = document.getElementById(countryId);
	var selectedCountry = countryObj.options[countryObj.selectedIndex].value;
	stateObj = countryObj.form[stateId];
	var numOpts = stateObj.options.length;
	if (numOpts) {
		stateObj.options[0].selected = true;
		stateObj.options[0].innerHTML = 'Loading...';
		for (var i = numOpts; i > 0; i--) {
			stateObj.options[i] = null;
		}
	}
	if (loadedStates[selectedCountry]) {
		setStateOptions(selectedCountry);
	} else {
		var stateScript = document.body.appendChild(document.createElement('iframe'));
		stateScript.setAttribute('height', 0);
		stateScript.setAttribute('width', 0);
		stateScript.setAttribute('src', '/jsrpc.html?action=loadStates&countryCode='+selectedCountry+'&stateId='+stateId);
		stateScript.setAttribute('id', 'loadStates'+selectedCountry);
	}
}
function setStateOptions(selectedCountry) {
	var opt;
	var selected;
	if (loadedStates[selectedCountry]) {
		eval('selected = '+stateObj.id+';');
		for (var key in loadedStates[selectedCountry]) {
			opt = document.createElement('option');
			opt.setAttribute('value', key);
			if (key == selected) {
				opt.setAttribute('selected', true);
			}
			opt.innerHTML = loadedStates[selectedCountry][key];
			stateObj.appendChild(opt);
		}
		stateObj.options[0].innerHTML = 'Select State';
	} else {
		stateObj.options[0].innerHTML = 'No Known States for '+selectedCountry;
	}
	updateStateRunning = false;
	return false;
}
function show_calendar(id) {
	url = "/calendar.html?id=" + id;
	size = 190;
	win = window.open(url, 'calendar', 'innerHeight='+size+',width='+size+',status=no');
	win.moveTo((screen.width-size)/2, (screen.height-size)/2);
	return win;
}
function erase(p_item){
	frm = document.getElementById(p_item);
	frm.value='';
}
function strpos(haystack, needle) {
	nlen = needle.length;
	for (var i = 0; i < haystack.length; i++)
	if (haystack.substring(i, i+nlen) == needle) return i;
	return -1;
}
function checkEmail(element) {
	val = element.value;
	if (val.length) {
		fs = document.body.appendChild(document.createElement('iframe'));
		fs.setAttribute('height', 0);
		fs.setAttribute('width', 0);
		fs.setAttribute('src', '/jsrpc.html?action=checkEmail&email='+val+'&domid='+element.id);
		fs.setAttribute('id', 'checkEmail');
	}
}
function in_array(n, h) {
	for (var i=0; i<h.length; i++) { if (n == h[i]) { return true; } } return false;
}
function canManipulateImages() {
	if (document.images)
		return true;
	else
		return false;
}
function loadSlide(imageURL) {
	if (gImageCapableBrowser) {
		document.slide.src = imageURL;
		return false;
	}
	else {
		return true;
	}
}
function nextSlide() {
	gCurrentImage = (gCurrentImage + 1) % gNumberOfImages;
	loadSlide(gImages[gCurrentImage]);
}

function showMethod(contactMethod,action) {
if(contactMethod == 'phone'){
document.getElementById('method').src="images/ct_methodnav.gif";
document.getElementById('headerr').innerHTML="PHONE";
document.getElementById('message').innerHTML="You have chosen the phone option.";
if(action == 'North America'){
document.getElementById('submessage').innerHTML='Please call us at 770.277.2577';
}else{
document.getElementById('submessage').innerHTML='Please call us at 886.2.2563 0301';
}
}
if(contactMethod == 'email'){
document.getElementById('method').src="images/ct_methodnav.gif";
document.getElementById('headerr').innerHTML="E-MAIL";
document.getElementById('message').innerHTML="You have chosen the email option.";
if(action == 'North America'){
document.getElementById('submessage').innerHTML='Please email us at chairworks@chairworksamerica.com';
}else{
document.getElementById('submessage').innerHTML='Please email us at chairworks@chairworks.com.tw';
}
}
if(contactMethod == 'fax'){
document.getElementById('method').src="images/ct_methodnav.gif";
document.getElementById('headerr').innerHTML="FAX";
document.getElementById('message').innerHTML="You have chosen the fax option.";
if(action == 'North America'){
document.getElementById('submessage').innerHTML='Please fax us at 770.277.2578';
}else{
document.getElementById('submessage').innerHTML='Please fax us at 886.2.2581 2925';
}
}
document.getElementById('methodGif').src="images/green_ball.png";
}