function showLoading(eleName, type){
	if (type == 1){
		$(eleName).set('html','<img src="/img/loading_arrow_small.gif" alt="loading..." />');
	}
}

function toggleElement(eleName){
	if ($(eleName).getStyle('display') == 'none'){
		$(eleName).setStyle('display','block');	
	}else {
		$(eleName).setStyle('display','none');	
	}
}

function toggleLoginBox(option, element, value, isPassword){
	addClass(element, 'loginBoxFocus');
	if (option == 0 && element.value == value){
		element.value = '';
	
	}else if (option == 1 && element.value == ''){
		removeClass(element, 'loginBoxFocus');
		element.value = value;
	}
}

function toggleSearchBox(option, element, value){
	addClass(element, 'searchBoxHighlight');
	if (option == 0 && element.value == value){
		element.value = '';
	
	}else if (option == 1 && element.value == ''){
		element.value = value;
		removeClass(element, 'searchBoxHighlight');
	}
}

function toggleTextarea(option, element, value){
	addClass(element, 'textareaHighlight');
	if (option == 0 && element.value == value){
		element.value = '';
	
	}else if (option == 1 && element.value == ''){
		element.value = value;
		removeClass(element, 'textareaHighlight');
	}
}

function toggleSelectBox(element){
	if (element.value == ''){
		removeClass(element, 'searchBoxHighlight');
	}else {
		addClass(element, 'searchBoxHighlight');
	}
}

function toggleSearchCheckBox(element, checkbox){
	if (checkbox.checked){
		addClass(element, 'searchCheckBoxHighlight');
	}else {
		removeClass(element, 'searchCheckBoxHighlight');
	}
}

function showPasswordBox(){
	$('passDisplay').setStyle('display','none');
	$('password').setStyle('display','inline-block');
	$('password').focus();
}

function showImage(rootUrl, imageUrl){
	new MooDialog.Iframe(rootUrl+"/home/showImage/"+imageUrl, {
		size: {width:800,height:600}
	});
}

function viewProductDetails(rootUrl, salesproductid){
	new MooDialog.Iframe(rootUrl+"/shop/viewProductDetails/"+salesproductid, {
		size: {width:500,height:600}
	});
}

function searchByGear(gearid){
	$('searchGearid').value=gearid;
	$('searchGearForm').submit();
}

/* --------------- */
/* utilities       */
/* --------------- */
var delimiter1 = "@|%~";

if(typeof String.prototype.trim !== 'function') {
	  String.prototype.trim = function() {
	    return this.replace(/^\s+|\s+$/g, ''); 
	  }
}

function convertKeyValue(inputStr){
	var keys = new Array;
	var values = new Array;
	var splitOne = inputStr.split("&");
	splitOne.each(function(item, index){
		var splitTwo = item.split("=");
		if (splitTwo.length == 2){
			keys.push(splitTwo[0]);
			values.push(splitTwo[1]);
		}
	});
	return values.associate(keys);
}

function func_htmlspecialchars(string, quote_style) {

   string = string.toString();

   string = string.replace(/&/g, '&amp;');
   string = string.replace(/</g, '&lt;');
   string = string.replace(/>/g, '&gt;');

   if (quote_style == 'ENT_QUOTES') {
       string = string.replace(/"/g, '&quot;');
       string = string.replace(/\'/g, '&#039;');
   } else if (quote_style != 'ENT_NOQUOTES') {
       string = string.replace(/"/g, '&quot;');
   }
  
   return string;
}

function func_htmlspecialchars_decode(string, quote_style) {

   string = string.toString();
  
   string = string.replace(/&amp;/g, '&');
   string = string.replace(/&lt;/g, '<');
   string = string.replace(/&gt;/g, '>');
  
   if (quote_style == 'ENT_QUOTES') {
       string = string.replace(/&quot;/g, '"');
       string = string.replace(/&#039;/g, '\'');
   } else if (quote_style != 'ENT_NOQUOTES') {
       string = string.replace(/&quot;/g, '"');
   }
  
   return string;
}

function func_stripTag(value) {
	return value.replace(/(<([^>]+)>)/ig,"");
}

function limitText(limitField, limitNum) {
	if ($(limitField).value.length > limitNum) {
		$(limitField).value = $(limitField).value.substring(0, limitNum);
	} 
}

function addClass(element, className){
	if (element.className.indexOf(className) == -1){
		element.className += " " + className;
	}
}

function removeClass(element, className){
	var pos = element.className.indexOf(className);
	if (pos != -1){
		element.className = element.className.substr(0,pos) + element.className.substr(pos+className.length);
	}
}
