// EXTERNAL JAVASCRIPT LIBRARY FILE (c) Bob Gilmour (2009) :: http://bobgilmour.info

// SHOW PAGE ELEMENTS
function show(page,element){
	
	switch(page){
	
	case 'home':
		
		document.getElementById('comment').style.display='none';
		document.getElementById('bio').style.display='none';
		document.getElementById('websites').style.display='none';
		document.getElementById('woodworks').style.display='none';
		document.getElementById('woodworks_info').style.display='none';
		//document.getElementById('woodworks_credit').style.display='none';
		document.getElementById('contact').style.display='none';
		
		document.getElementById('woodworks_credit').style.display='block';
		
		document.getElementById('link_comment').style.color='#8e8e8e';
		document.getElementById('link_bio').style.color='#8e8e8e';
		document.getElementById('link_websites').style.color='#8e8e8e';	
		document.getElementById('link_woodworks').style.color='#8e8e8e';	
		document.getElementById('link_contact').style.color='#8e8e8e';		
		
		document.getElementById(element).style.display='block';
		document.getElementById('link_' + element).style.color='#4b4b4b';
		break;
		
	case 'news':
		break;
		} // end switch
	} // end function show


// WRITE THE CONTACT FORM
function contact(page,element,sefPath){

	contactStr = "<form id=\"form_email\" class=\"content_sml\" method=\"POST\" name=\"form_email\" action=\"http://biz70.inmotionhosting.com/~bobgil5/sendmail/sendmail.php\"  onSubmit=\"return validateEmail()\">";	
	contactStr += "<input type=\"hidden\" name=\"env_report\" value=\"REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER\" />";
	contactStr += "<input type=\"hidden\" name=\"recipients\" value=\"emailmeX1WVX7Bbobgilmour.info\" />"; //X1WVX7B - sendmail script
	contactStr += "<input type=\"hidden\" name=\"good_url\" value=\"http://www.bobgilmour.info/thankyou/\">"; //value=\"http://www.bobgilmour.info/thankyou/\"
	contactStr += "<input type=\"hidden\" name=\"bad_url\" value=\"\" />";
	contactStr += "<input type=\"hidden\" name=\"required\" value=\"email:Your email address,realname:Your name\" />";
	contactStr += "<input type=\"hidden\" name=\"subject\" value=\"ENQUIRY FROM WEBSITE || BOB GILMOUR INFO\" />";
	contactStr += "<table id=\"formDetails\">";
	contactStr += "<tr><td class=\"detailsTag\">To:</td><td class=\"detailsInput\">BOB GILMOUR</td></tr>";
	contactStr += "<tr><td class=\"detailsTag\">Subj:</td><td class=\"detailsInput\">ENQUIRY FROM WEBSITE || BOB GILMOUR INFO</td></tr>";
	contactStr += "<tr style=\"height: 50px; vertical-align: bottom;\"><td class=\"detailsTag\">Your name:</td><td class=\"detailsInput\"><input class=\"detailsInputField\" type=\"text\" id=\"realname\" name=\"realname\"></input></td></tr>";
	contactStr += "<tr><td class=\"detailsTag\">Your email:</td><td class=\"detailsInput\"><input class=\"detailsInputField\" type=\"text\" id=\"email\" name=\"email\"></input></td></tr>";
	contactStr += "<tr><td class=\"detailsTag\">Message:</td><td class=\"detailsInput\"><textarea class=\"detailsMessage\" id=\"message\" name=\"message\"></textarea></td></tr>";
	
	contactStr += "<tr><td>";
	  
	  contactStr += "<div id=\"security_catch\">";
	  contactStr += "<div class=\"captcha_msg\" id=\"captchaMsg\">Please enter the security code and click SUBMIT CODE ... and then click the SEND button.</div>";
	  contactStr += "<div class=\"captcha_img\" id=\"captchaImg\"><img src=\"" + sefPath + "includes/CaptchaSecurityImages.php?width=100&height=40&characters=5\" /></div>";
	  contactStr += "<div class=\"captcha_input\"><input style=\"width: 80px;\" id=\"security_code\" name=\"security_code\" type=\"text\" /></div>";
	  contactStr += "<input class=\"captcha_button\" type=\"button\" value=\"SUBMIT CODE\" id=\"button_capcha\" onclick=\"captchaCheck('" + sefPath + "')\" />";
	  contactStr += "</div>";
	  contactStr += "</td></tr>";
	
	contactStr += "</table>";
	contactStr += "<input class=\"detailsButtonSend\" type=\"submit\" value=\"SEND\" id=\"buttonSend\" />";
	contactStr += "</form>";
	
	document.getElementById('contact').innerHTML = contactStr;
	show('home','contact');
	} // end contact


//AJAX :: CAPCHA CHECK CONTACT
function captchaCheck(sefPath){

// send the security code up to the server for checking by AJAX
var codeData = 'secCode=' + document.form_email.security_code.value;
	
var AJAX = null;
if (window.XMLHttpRequest) {
 AJAX=new XMLHttpRequest();
} else {
  AJAX=new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (AJAX==null) {
  alert("Your browser doesn't support AJAX.");
  return false
  } else {
	   AJAX.open("POST", "" + sefPath + "includes/cap_chk.php", true);
    AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    AJAX.onreadystatechange = function() {
    if (AJAX.readyState==4 || AJAX.readyState=="complete") {
			var responseStr = AJAX.responseText;
			if (responseStr=="success"){
			document.getElementById('security_catch').innerHTML	= "<span style=\"margin-top: 25px; float: right; margin-right: 20px; color: #FF8C00;\">SUCCESS --> Click Send Button</span>";
			document.form_email.buttonSend.style.display='block';
			} else {
				var randomnumber=Math.floor(Math.random()*1000001);
				document.getElementById('captchaMsg').innerHTML = "<span style=\"color: #FF8C00;\">FAILURE - Please re-enter the security code</span>";
				document.getElementById('captchaImg').innerHTML = "<img src=\"" + sefPath + "includes/CaptchaSecurityImages.php?width=100&height=40&characters=5&" + randomnumber + "\" />"; // the random number is to bypass firefox cache
				}
			}
		}
AJAX.send(codeData);
			 
}
} // end captchaCheck

//VALIDATES EMAIL FORM
function validateEmail() {
	
  // check for empty fields	
	if (document.form_email.realname.value=="") {
    	alert('Please enter your name');
    	return false;
		}
    	
	if (document.form_email.email.value==""){
    	alert('Please enter your email address');
    	return false;
		}
	} // end validateEmail
