// JavaScript Document
var $jq = jQuery.noConflict();

$jq(window).load(function(){
	$jq('#shorts ul li').click(function(){
		$jq('#shorts-s p').css('display', 'none');
		var ELE = $jq(this).attr('id').replace('-li', '-p');
		$jq('#'+ELE).css('display', 'block');
	});
	if ($jq('#enquiryoverlay')){
		$jq('#enquiryoverlay').click(function(){
			$jq('#enquiryoverlay').fadeOut(1000);
			$jq('#theenquiryform').fadeOut(1000);
		});
	}
	
});
function socialshareme(ID){
	var url=window.location.href;
	var title=document.title;
	switch(ID){
		case"facebook":
			window.open("http://www.facebook.com/sharer.php?u="+url+"&t="+title);
			break;
		case"linkedin":
			window.open("http://www.linkedin.com/shareArticle?mini=true&url="+url+"&title="+title);
			break;
		case"twitter":
			window.open("http://twitter.com/home/?status="+title+" ("+url+")");
			break;
		case"digg":
			window.open("http://digg.com/submit?url="+url+"&title="+title);
			break;
		case"reddit":
			window.open("http://reddit.com/submit?url="+url+"&title="+title);
			break;
		case"email":
			window.location.href="mailto:?subject="+title+"&body="+url;
			break;
	}
}

function showenquiryform(TYPE){
	$jq.post("enquiryform_get.html", {"type": TYPE}, function(data){
		$jq('#theenquiryform').html(data);
		$jq('#enquiryoverlay').fadeTo(1000, 0.6);
		$jq('#theenquiryform').fadeTo(1000, 1);
  	});
}
function closeenquiry(){
	$jq('#enquiryoverlay').fadeTo(1000, 0);
	$jq('#theenquiryform').fadeTo(1000, 0);
}

function checkform_global(){
	ERROR = "";
	if ($jq('#email').val().length < 1)ERROR += "Missing your email address.\n";
	else if ($jq('#email').val() !== $jq('#email2').val())ERROR += "Email addresses do not match.\n";
	if ($jq('#name').val() == "")ERROR += "Missing your name.\n";
	return ERROR;	
}
function togglefield(FIELD, VAL){
	if (VAL == "Yes")$jq('#' + FIELD).parent().show();
	else $jq('#' + FIELD).parent().hide();
}
function checknumber(VAL, FIELD){
	ERROR = "";
	if (VAL.length < 1){
		ERROR += "Missing "+FIELD+".\n";
	} else if (!VAL.match(/^[0-9]*\.?[0-9]+$/)){
		ERROR += "Invalid characters found in "+FIELD+", 0 to 9 and . only permitted.\n";
	}
	return ERROR;
}
function checkform_jibcrane(){
	ERROR = "";
	ERROR += checknumber($jq('#swl').val(), "SWL");
	ERROR += checknumber($jq('#arm').val(), "Arm Radius");
	ERROR += checknumber($jq('#overheight').val(), "Overall Height");
	ERROR += checknumber($jq('#underheight').val(), "Overall Height");
	
	if ($jq('#needhoist').val() == "")ERROR += "Please indicate if you require a Hoist.\n";
	if ($jq('#needhoist').val() == "Yes" && $jq('#hoist_req').val().length < 1)ERROR += "Please enter your hoist requirements.\n";
	if ($jq('#mounted').val() == "")ERROR += "Please select your mounting option.\n";
	if ($jq('#elec_required').val() == "")ERROR += "Please select if electrics are required.\n";
	if ($jq('#givequote').val() == "")ERROR += "Please select if you require a quote for installation.\n";
	
	ERROR += checkform_global();
	
	if (ERROR == ""){
		return true;
	} else {
		alert("Errors were found with your submission, please check the following: \n" + ERROR);
		return false;
	}	
}
function checkform_aframe(){
	ERROR = "";
	ERROR += checknumber($jq('#swl').val(), "SWL");
	ERROR += checknumber($jq('#height_under_beam').val(), "under beam height");
	ERROR += checknumber($jq('#span_between_legs').val(), "span between legs");
	
	if ($jq('#parking_jacks').val() == "")ERROR += "Please select if parking jacks are required.\n";

	ERROR += checkform_global();
	
	if (ERROR == ""){
		return true;
	} else {
		alert("Errors were found with your submission, please check the following: \n" + ERROR);
		return false;
	}	
}
