function clearText(thisText){
	if (thisText.value == thisText.defaultValue){
		thisText.value = "";
	}
}
function resetText(thisText){
	if (thisText.value == ""){
		thisText.value = thisText.defaultValue;
	}
}
function hideMail(){
	document.getElementById("emailForm").innerHTML = "<center><p>Thank you for your inquiry.<br />Your message is currently being transmitted.<p />You will receive a notification when the message has been sent.</center>";
}
function validateMail(doSend){
	//validate message length
	if (document.getElementById("txtMessage").value.length < 5) {
		alert("Please enter a message of at least 5 characters before sending.")
		document.getElementById("txtMessage").focus();
		return false;
	}
	//validate email address
	with (document.getElementById('txtFrom')){
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2) {
			alert("Please enter a valid email address before sending.");
			return false;
		}
	}
	//send mail?
	if (doSend == true) sendMail();
}
//SEND REQUEST
function sendMail(){
	requestString = "mailTo=" + document.getElementById("txtTo").value;
	requestString += "&mailFrom=" + document.getElementById("txtFrom").value;
	if (document.getElementById("txtSubject").value != "") requestString += "&mailSubject=Mail from www.turbochem.com - " + document.getElementById("txtSubject").value;
	else requestString += "&mailSubject=Mail from www.turbochem.com - No Subject";
	requestString += "&mailBody=" + escape(document.getElementById("txtMessage").value);
	frames['sendMailFrame'].location.href = "http://houston.turbochem.com/scripts/sendMail.php?"+requestString;
	hideMail();
	//req.open('GET', 'http://houston.turbochem.com/scripts/sendMail.php');
	//req.onreadystatechange = handleSendMailResponse;
	//req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	//req.setRequestHeader('Content-Type', 'text/xml');
	//req.send(requestString);
}
function handleSendMailResponse(){
	if(req.readyState == 4){
		if (req.status == 200){
			if (req.responseText == "Finished") {
				hideMail();
				alert("Your message has been sent.");
			}
		}
		//}else if (req.status == 404)
		//	alert("Request URL does not exist");
		//else
		//	alert("Error: status code is " + req.status);
	}else{
		/* Status Update */
	}
}
//AJAX CONNECTION
function createXMLHttpRequest() {
	var ua;
	if(window.XMLHttpRequest) {
		try {
			ua = new XMLHttpRequest();
		}catch(e) {
			ua = false;
		}
	}else if(window.ActiveXObject) {
		try{
			ua = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e) {
			ua = false;
		}
	}
	return ua;
}
var req = createXMLHttpRequest();	
			
function deCryptMail(address){
	var charCode = 0;
	var returnAddress = "";
	for (var i=0; i< address.length; i++){
		charCode = address.charCodeAt(i);
		if (charCode >= 8364){
			charCode = 128;
		}
		returnAddress += String.fromCharCode(charCode -2);
	}
	return returnAddress;
}
function linkMail(address){
	location.href=deCryptMail(address);
}
function rTrim(address){
	return String(address).substring(7);
}
var cardData = "";
var cardCell1 = "";
var cardCell2 = "";
var cardCell3 = "";
var cardCell4 = "";
function showCard(name, title, location){
	switch(location){
		case "Lafayette":
			cardCell1 = 'Office: 337-235-3098 <br> U.S. Wats: 800-259-7838';
			cardCell2 = '<b>' +name + '</b><br>' + title;
			cardCell3 = 'P.O. Box 60383<br>Lafayette, LA 70596';
			cardCell4 = 'Fax: 337-235-3186';
			break;
		case "Houston":
			cardCell1 = 'Office: 713-526-8172 <br> U.S. Wats: 800-259-7838';
			cardCell2 = '<b>' +name + '</b><br>' + title;
			cardCell3 = '401 Studewood, Suite 206<br>Houston, TX 77007';
			cardCell4 = 'Fax: 713-526-8189';
			break;
		case "Corpus":
			cardCell1 = 'Office: 361-289-7431 <br> U.S. Wats: 800-259-7838';
			cardCell2 = '<b>' +name + '</b><br>' + title;
			cardCell3 = '6749 Leopard St.<br>Corpus Christi, TX';
			cardCell4 = 'Fax: 361-289-7436';
			break;
		case "Oklahoma":
			cardCell1 = 'Office: (337)-235-3098 <br> U.S. Wats: 800-259-7838';
			cardCell2 = '<b>' +name + '</b><br>' + title;
			cardCell3 = '409 South Pioneer, Elk City, OK 73644';
			cardCell4 = '<br>Fax: (337)-235-3186';
			break;
		case "International":
			cardCell1 = 'Office: (62 21) 798 9140, 798 9146';
			cardCell2 = '<b>' +name + '</b><br>' + title;
			cardCell3 = 'Gedung Tetra Pak, Suite 100 • Jl. Buncit Raya Kav. 100, Jakarta  12510';
			cardCell4 = '<br>Fax: (62 21) 717 93006';
			break;
		case "midcont":
			cardCell1 = 'Dallas: (972)-956-0092 <br> Tulsa: (918)-919-4763 <br> Oklahoma City: (405)-283-4764';
			cardCell2 = '<b>' +name + '</b><br>' + title;
			cardCell3 = '3900 Grapevine Mills Parkway • #3424 • Grapevine, TX 76051';
			cardCell4 = '<br>Fax: (800)-552-2713';
			break;
	}
	var cardData = '<table border="0" width="400" class="businesscard"><tr><td valign="top" align="left">'+cardCell1+'</td><td valign="top" align="center">'+cardCell2+'</td></tr><tr><td colspan="2" width="400" align="center"><img src="./images/cardlogo.gif"><br><b>ENVIRONMENTALLY SAFE DRILLING CHEMICALS<br>FROM THE WELLBORE STABILITY SPECIALISTS</b></td></tr><tr><td>'+cardCell3+'</td><td align="right">'+cardCell4+'</td></table>';
	
	showtip(cardData, 400);
}
//
var currentID = 0;
var resizing = false;
var cSize = 190;
function hideLoc() {
	document.getElementById("splash").style.display='inline';
	//UN-comment locationoverlay for faster resize on slower machines
	//document.getElementById("locationoverlay").style.display='none';
	switch(currentID){
		case 0:
			document.getElementById("locationstart").style.display='none';
			break;
		case 1:
			document.getElementById("lafayette").style.display='none';
			document.getElementById("loc1").style.backgroundImage='url(images/locoff.gif)';
			break;
		case 2:
			document.getElementById("houston").style.display='none';
			document.getElementById("loc2").style.backgroundImage='url(images/locoff.gif)';
			break;
		case 3:
			document.getElementById("corpus").style.display='none';
			document.getElementById("loc3").style.backgroundImage='url(images/locoff.gif)';
			break;
		case 4:
			document.getElementById("oklahoma").style.display='none';
			document.getElementById("loc4").style.backgroundImage='url(images/locoff.gif)';
			break;
		case 5:
			document.getElementById("international").style.display='none';
			document.getElementById("loc5").style.backgroundImage='url(images/locoff.gif)';
			break;
		case 6:
			document.getElementById("directory").style.display='none';
			document.getElementById("loc6").style.backgroundImage='url(images/locoff.gif)';
			break;
		case 7:
			document.getElementById("midcont").style.display='none';
			document.getElementById("loc7").style.backgroundImage='url(images/locoff.gif)';
			break;
	}
}

function showLoc(id) {
	document.getElementById("splash").style.display='none';
	//UN-comment locationoverlay for faster resize on slower machines
	//document.getElementById("locationoverlay").style.display='inline';
	switch (id) {
		case 1:
			currentID=1;
			document.getElementById("lafayette").style.display='block';
			document.getElementById("loc1").style.backgroundImage='url(images/locon.gif)';
			break;
		case 2:
			currentID = 2;
			document.getElementById("houston").style.display='inline';
			document.getElementById("loc2").style.backgroundImage='url(images/locon.gif)';
			break;
		case 3:
			currentID = 3;
			document.getElementById("corpus").style.display='inline';
			document.getElementById("loc3").style.backgroundImage='url(images/locon.gif)';
			break;
		case 4:
			currentID = 4;
			document.getElementById("oklahoma").style.display='inline';
			document.getElementById("loc4").style.backgroundImage='url(images/locon.gif)';
			break;
		case 5:
			currentID = 5;
			document.getElementById("international").style.display='inline';
			document.getElementById("loc5").style.backgroundImage='url(images/locon.gif)';
			break;
		case 6:
			currentID = 6;
			document.getElementById("directory").style.display='block';
			document.getElementById("loc6").style.backgroundImage='url(images/locon.gif)';
			break;
		case 7: 
			currentID = 7;
			document.getElementById("midcont").style.display='block';
			document.getElementById("loc7").style.backgroundImage='url(images/locon.gif)';
			break;
	}
}
function reSize(nSize, id){
	if (!resizing){
		resizing = true;
		goSize(nSize, id);
	}
}
function goSize(nSize, id){
	if (cSize < nSize){
			cSize += 10;
			document.getElementById("locations").style.height=cSize+'px';
			//comment locationoverlay for faster resize on slower machines
			document.getElementById("locationoverlay").style.height=cSize+'px';
			setTimeout("goSize("+nSize+','+id+')',30);
	} else if (cSize > nSize) {
			cSize -= 10;
			document.getElementById("locations").style.height=cSize+'px';
			//comment locationoverlay for faster resize on slower machines
			document.getElementById("locationoverlay").style.height=cSize+'px';
			setTimeout("goSize("+nSize+','+id+')',30);
	
	} else {
		document.getElementById("locationoverlay").style.height=cSize+'px';
		showLoc(id);
		resizing = false;
	}
}
