//hilight row
function hilight_row(obj, color) {
	obj.bgColor = color;
}
//ask delete
function askDelete(text) {
	var begin_text  = 'Are you sure you want to delete:';
	var confirmed = confirm(begin_text + '\n' + text);
	if (confirmed) {
		return true;
	}
	else {
		return false;
	}
}
//check contact fields
function verifyContact() {
	var company    	= document.getElementById('company');
	var contact  	= document.getElementById('contact');
	var phone  		= document.getElementById('phone');
	var email 		= document.getElementById('email');
	var address		= document.getElementById('address');
	var enquiry		= document.getElementById('enquiry');
	var pattern 	= new RegExp("^[0-9A-Za-z_.-]+@[A-Za-z0-9_.-]+\.[A-Za-z]{2,4}$", "i");
	var ok 			= 0;
	if (!company.value.length && !contact.value.length && !phone.value.length && !email.value.length && !address.value.length && !enquiry.value.length) {
		return false;
	}
	else {
		if (!company.value.length) {
			ok = 1;
			alert('You forgot to fill in the company name!');
		}
		if (!contact.value.length) {
			ok = 1;
			alert('You forgot to fill in the contact name!');
		}
		if (!phone.value.length) {
			ok = 1;
			alert('You forgot to fill in the phone number!');
		}
		if (!pattern.test(email.value)) {
			ok = 1;
			alert('Email address is incorrect!');
		}
		if (!address.value.length) {
			ok = 1;
			alert('You forgot to fill in your address!');
		}
		if (!enquiry.value.length) {
			ok = 1;
			alert('Please let us know your question!');
		}
		if (ok == 1) {
			return false;
		}
		else {
			return true;
		}
	}
}
//check trade fields
function verifyTrade() {
	var name    	= document.getElementById('name');
	var business    = document.getElementById('business');
	var website   	= document.getElementById('website');
	var contact  	= document.getElementById('contact_name');
	var businessa   = document.getElementById('businessa');
	var phone   	= document.getElementById('phone2');
	var email 		= document.getElementById('email2');

	var pattern 	= new RegExp("^[0-9A-Za-z_.-]+@[A-Za-z0-9_.-]+\.[A-Za-z]{2,4}$", "i");
	var ok 			= 0;
	if (!name.value.length	&& !website.value.length && !business.value.length	&& !contact.value.length && !businessa.value.length && !phone.value.length	&& !email.value.length/*	&& !hear.value.length*/) {
		return false;
	}
	else {
		if (!name.value.length) {
			ok = 1;
			alert('You forgot to fill in the company name!');
		}
		if (!website.value.length) {
			ok = 1;
			alert('You forgot to fill in the website address!');
		}
		if (!business.value.length) {
			ok = 1;
			alert('You forgot to describe your type of business!');
		}
		if (!contact.value.length) {
			ok = 1;
			alert('You forgot to fill in the contact name!');
		}
		if (!businessa.value.length) {
			ok = 1;
			alert('You forgot to fill in the business address!');
		}
		if (!phone.value.length) {
			ok = 1;
			alert('You forgot to fill in the phone number!');
		}
		if (!pattern.test(email.value)) {
			ok = 1;
			alert('Email address is incorrect!');
		}
//		if (!hear.value.length) {
//			ok = 1;
//			alert('You forgot to fill \'How did you hear about us?\' field!');
//		}
		if (ok == 1) {
			return false;
		}
		else {
			return true;
		}
	}
}

function changePicture(side, code) {
	if(window.XMLHttpRequest) {
		x = new XMLHttpRequest();
	} else {
		x = new ActiveXObject("Microsoft.XMLHTTP");
	}
	x.open("GET", "/js/getPicture.php?side=" + side + "&code=" + code);
	x.onreadystatechange = response;
	x.send(null);
}

function response() {
	if(x.readyState == 1) {
		document.getElementById("image").innerHTML = "<img src=\"/images/white.gif\" border=\"0\">";
	}
	else if(x.readyState == 4 && x.status == 200) {
		document.getElementById("image").innerHTML = x.responseText;
	}
}
function map1(){
	window.open("/map/map1.html","MAP","resizable=no,toolbar=no,scrollbars=no,menubar=no,status=no,directories=no,width=520,height=598");
}
function map2(){
	window.open("/map/map2.html","MAP","resizable=no,toolbar=no,scrollbars=no,menubar=no,status=no,directories=no,width=520,height=518");
}
function map3(){
	window.open("/map/map3.html","MAP","resizable=no,toolbar=no,scrollbars=no,menubar=no,status=no,directories=no,width=530,height=448");
}
function showFinish(code){
	window.open("/finishes/show_picture.php?code="+code,"Wooden","resizable=no,toolbar=no,scrollbars=no,menubar=no,status=no,directories=no,width=305,height=350");
}
function print(){
	window.open("/js/print.php","Print","resizable=no,toolbar=no,scrollbars=no,menubar=no,status=no,directories=no,width=207,height=291,left=200;top=100");
}

var i=1;
var timerId=0;
var timer=0;
var ftimer=0;
var utimer=0;
var atimer=0;

function show_hide(timer,div){
	if (timer == 1) {
		timerId = ftimer;
	}
	else if (timer == 2) {
		timerId = utimer;
	}
	else {
		timerId = atimer;
	}
	var elm = document.getElementById(div);
	if (elm.style.visibility == "hidden") {
		clearTimeout(timerId);
		elm.style.visibility = "visible";
	}
	else {
		elm.style.visibility = "hidden";
	}
}

function wait(timer,div) {
	if (timer == 1) {
		timerId = ftimer;
	}
	else if (timer == 2) {
		timerId = utimer;
	}
	else {
		timerId = atimer;
	}
	i++;
	if (i > 1) {
		clearTimeout(timerId);
		i = 0;
		if (timer == 1) {
			show_hide(1,div);
		}
		else if (timer == 2) {
			show_hide(2,div);
		}
		else {
			show_hide(3,div);
		}
	}
	else {
		if (timer == 1) {
			ftimer = setTimeout("wait(1,'" + div +"')", 250);
		}
		else if (timer == 2) {
			utimer = setTimeout("wait(2,'" + div +"')", 250);
		}
		else {
			atimer = setTimeout("wait(3,'" + div +"')", 250);
		}
	}
}
function clearTimer(timer,div) {
	if (timer == 1) {
		timerId = ftimer;
	}
	else if (timer == 2) {
		timerId = utimer;
	}
	else {
		timerId = atimer;
	}
	var elm = document.getElementById(div);
	clearTimeout(timerId);
	elm.style.visibility = "visible";
}
function show(timer,div) {
	if (timer == 1) {
		timerId = ftimer;
		clearTimeout(timerId);
		show_hide(1,div);
	}
	else if (timer == 2) {
		timerId = utimer;
		clearTimeout(timerId);
		show_hide(2,div);
	}
	else {
		timerId = atimer;
		clearTimeout(timerId);
		show_hide(3,div);
	}
}