function searchFocus() 	{ document.getElementById('top_search_txt').style.backgroundPosition = "0 -22px"; }
function searchBlur() 	{ document.getElementById('top_search_txt').style.backgroundPosition = "0 0"; }
function cropText(id, limit) {if (document.getElementById(id).innerHTML.length >= limit) {document.getElementById(id).innerHTML = document.getElementById(id).innerHTML.substring(0,limit) + '&hellip;';}}
function checkErrorDiv() {if (document.getElementById('error_div_inner')) { if (document.getElementById('error_div_inner').innerHTML.length > 0) {document.getElementById('error_div').style.display = "block";}}}
function validate_submit(formName) {if (validate_this(formName)) { document.forms[formName].submit(); }}
function hideshow(id,hideshow) {document.getElementById(id).style.display = hideshow;}
function hideshowsmart(id) {
	if (document.getElementById(id).style.display == 'block')	document.getElementById(id).style.display = 'none';
	else 														document.getElementById(id).style.display = 'block';
}
function textClear (input) { if ( input.value == input.defaultValue ) { input.value = "";}}
function textRestore (input) {if ( input.value == "" ) {input.value = input.defaultValue;}}
function textLimit2(field, maxlen) {
	if (field.value.length > maxlen) {
		field.value = field.value.substring(0, maxlen);
		alert('Your input has been truncated! There is a limit of 2000 characters.');
	}
}

function loadjscssfile(filename, filetype){
	if (filetype=="js"){ //if filename is a external JavaScript file
		var fileref=document.createElement('script')
		fileref.setAttribute("type","text/javascript")
		fileref.setAttribute("src", filename)
	} else if (filetype=="css"){ //if filename is an external CSS file
		var fileref=document.createElement("link")
		fileref.setAttribute("rel", "stylesheet")
		fileref.setAttribute("type", "text/css")
		fileref.setAttribute("href", filename)
	}
	if (typeof fileref!="undefined")
		document.getElementsByTagName("head")[0].appendChild(fileref)
}

function goToByScroll(id,speed){
	$('html,body').animate({scrollTop: $("#"+id).offset().top},speed);
}

/** ONLOAD FUNCTIONS **/
window.onload=function() {
	checkErrorDiv();
	if (document.getElementById('prdd_accessories_content')) {if (document.getElementById('prdd_accessories_content').innerHTML.length > 0) { hideshow('prdd_accessories','block'); }}
	if (document.getElementById('prdd_recommender_content')) {if (document.getElementById('prdd_recommender_content').innerHTML.length > 31) { hideshow('prdd_recommender','block'); }}
	if (document.getElementById('shopcart_recommender_content')) { if (document.getElementById('shopcart_recommender_content').innerHTML.length > 50) { hideshow('shopcart_recommender','block'); }}	
	if (document.getElementById('errorDivInner')) { if (document.getElementById('errorDivInner').innerHTML.length > 0) { hideshow('errorDiv','block'); }}
	if (document.getElementById('prdd_recommender_prodrec')) {if (document.getElementById('prdd_recommender_prodrec').innerHTML.length < 300) {hideshow('prdd_recommender_prodrec','none');}}
	if (document.getElementById('prdd_recommender_prodrec2')) {if (document.getElementById('prdd_recommender_prodrec2').innerHTML.length < 300) {hideshow('prdd_recommender_prodrec2','none');}}
}
