String.prototype.trim=function(){ return this.replace(/^\s*|\s*$/g,''); }
String.prototype.ltrim=function(){ return this.replace(/^\s*/g,''); }
String.prototype.rtrim=function(){ return this.replace(/\s*$/g,''); }
function $(id){ return document.getElementById(id) }
function $show(id){ $(id).style.display = ''; }
function $hide(id){ $(id).style.display = 'none'; }
function $showhide(id){ $(id).style.display = ($(id).style.display == 'none') ? '' : 'none'; }


//main functions
function removeParent(link){
	var getName = link.parentNode;
	link.parentNode.parentNode.removeChild(getName);
}

/* Form Validation */
function formValidation(f){
	aEle = f.elements;
	fAlert = false;
	msg = "Sorry, it looks like you've left some required fields blank [*] ";
	msg += "\n\nPlease check the highlighted fields and try again.";
	hColor = "#FFFEB8";

	for(i=0;i<aEle.length;i++){
		ele = aEle[i];
		ele.style.background = "";

		if(ele.className.indexOf("js_req") > -1){

			// Text boxes //
			if((ele.type == "text" || ele.type == "textarea" || ele.type == "password") && ele.value.length == 0){
				ele.style.background = hColor; fAlert = true;
			}

			// Radio buttons //
			if(ele.type == "radio" || ele.type == "checkbox"){
				aRad = f.elements[ele.name];
				fChecked = false;
				
				for(n=0;n<aRad.length;n++) if(aRad[n].checked == true) fChecked = true;
	
				if(fChecked == false){ ele.parentNode.parentNode.style.background = hColor; fAlert = true; }
				else ele.parentNode.parentNode.style.background = "";
				
				i += aRad.length-1;
			}

		}

		// Email Check //
		if(ele.className.indexOf("js_eReq") > -1 && (ele.value.length < 8 || ele.value.indexOf("@") < 2 || ele.value.lastIndexOf(".") > (ele.value.length-1))){
			msg = msg.replace("[*]", "or entered an invalid email address. ");
			ele.style.background = hColor; fAlert = true;
		}
			
	}
	if(fAlert == true){ alert(msg.replace("[*]", "")); return false; }
	else{ return true;}
}




function enquireAbout(type){
	if(type == "sales"){
		$hide('samples');
		$('txtSamples').className = "";
		$('txtSamples').value = "";
		$('lnkSales').style.fontWeight = "bold";
		$('lnkSample').style.fontWeight = "normal";
	}
	else{
		$show('samples');
		$('txtSamples').className = "js_req";
		$('lnkSales').style.fontWeight = "normal";
		$('lnkSample').style.fontWeight = "bold";
	}
}

function submitContact(){
	if(formValidation($('frmContact'))){
		$('frmContact').submit();
	}
	else{
		return false;			
	}
}


