function display(element) {
	var but = document.getElementById(element);
	but.style.display = 'block';
}
function hide(element) {
	var but = document.getElementById(element);
	but.style.display = 'none';
}
function enable(element) {
	var inp = document.getElementById(element);
	inp.disabled = false;
}
function disable(element) {
	var inp = document.getElementById(element);
	inp.disabled = true;
}
function visibleFlash(){
	var obj = top.document.getElementsByTagName("object");
	var emb = top.document.getElementsByTagName("embed");
	obj.style.visibility = 'visible';
	emb.style.visibility = 'visible';
}
function resizeHeight(altezza,id){
	var TotAltezza = altezza;
	var thisOne = document.getElementById(id);
	thisOne.style.height = TotAltezza + "px";
}
function resizeWidth(larghezza,id){
	var TotLarghezza = larghezza;
	var thisOne = document.getElementById(id);
	thisOne.style.width = TotLarghezza + "px";
}
function setMarginLeft(margin,id){
	var margine = margin;
	var thisOne = document.getElementById(id);
	thisOne.style.marginLeft = margine + "px";
}
function setTop(altezza,id){
	var TotAltezza = altezza;
	document.getElementById(id).style.top = TotAltezza + "px";
}
function linkInTopFrame(link,frame){
        top.frames[frame].location.href = link;
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
function changeLabel(id,newLabel){
	var idLab = document.getElementById(id);
	idLab.innerHTML = newLabel;
}
/* Numbers */
function numToDB(number){
	return number.replace(",","");
}
function number_format (number, decimals, dec_point, thousands_sep){
  var exponent = "";
  var numberstr = number.toString ();
  var eindex = numberstr.indexOf ("e");
  if (eindex > -1){
    exponent = numberstr.substring (eindex);
    number = parseFloat (numberstr.substring (0, eindex));
  }

  if (decimals != null){
    var temp = Math.pow (10, decimals);
    number = Math.round (number * temp) / temp;
  }
  var sign = number < 0 ? "-" : "";
  var integer = (number > 0 ?
      Math.floor (number) : Math.abs (Math.ceil (number))).toString ();

  var fractional = number.toString ().substring (integer.length + sign.length);
  dec_point = dec_point != null ? dec_point : ".";
  fractional = decimals != null && decimals > 0 || fractional.length > 1 ?
               (dec_point + fractional.substring (1)) : "";
  if (decimals != null && decimals > 0){
    for (i = fractional.length - 1, z = decimals; i < z; ++i)
      fractional += "0";
  }

  thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ?
                  thousands_sep : null;
  if (thousands_sep != null && thousands_sep != ""){
	for (i = integer.length - 3; i > 0; i -= 3)
      integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
  }

  return sign + integer + fractional + exponent;
}
function checkSearch(formname){
	var problems = 0;

	if(document.forms[formname].elements['SEARCH_city'].value == 'City' || document.forms[formname].elements['SEARCH_city'].value == '') problems++;
	if(document.forms[formname].elements['SEARCH_state'].value.length < 1) problems++;
	if(document.forms[formname].elements['SEARCH_zip'].value == 'Zip Code' || document.forms[formname].elements['SEARCH_zip'].value == '') problems++;
	if(document.forms[formname].elements['SEARCH_name'].value == 'Store Name' || document.forms[formname].elements['SEARCH_name'].value == '') problems++;
	if(document.forms[formname].elements['SEARCH_keyword'].value == 'Keyword' || document.forms[formname].elements['SEARCH_keyword'].value == '') problems++;

	if(problems >= 5){
		alert("You should enter at least one item in order to search!");
		return false;
	}
	if(document.forms[formname].elements['SEARCH_city'].value == 'City') document.forms[formname].elements['SEARCH_city'].value='';
	if(document.forms[formname].elements['SEARCH_state'].value.length < 1) document.forms[formname].elements['SEARCH_state'].value='';
	if(document.forms[formname].elements['SEARCH_zip'].value == 'Zip Code') document.forms[formname].elements['SEARCH_zip'].value='';
	if(document.forms[formname].elements['SEARCH_name'].value == 'Store Name') document.forms[formname].elements['SEARCH_name'].value='';
	if(document.forms[formname].elements['SEARCH_keyword'].value == 'Keyword') document.forms[formname].elements['SEARCH_keyword'].value='';
	return true;
}
function checkStore(formname){
	var problems = '';
	var mailExp = new RegExp("^[a-zA-Z0-9_.-]{1,}\@[a-zA-Z0-9.-]{2,}\\.[a-zA-Z]{1,}$");

	if(document.forms[formname].elements['form_first_name'].value.length < 1) problems += '- Missing First Name\n';
	if(document.forms[formname].elements['form_last_name'].value.length < 1) problems += '- Missing Last Name\n';
	
 	if(document.forms[formname].elements['form_name'].value.length < 1) problems += '- Missing Store Name\n';
 	
	if(document.forms[formname].elements['form_address'].value.length < 1) problems += '- Missing Store Address\n';
	
	if(document.forms[formname].elements['form_city'].value.length < 1) problems += '- Missing Store City\n';
	if(document.forms[formname].elements['form_state'].value.length < 1) problems += '- Missing Store State\n';
	if(document.forms[formname].elements['form_zip'].value.length < 1) problems += '- Missing Store Zip Code\n';
	if(document.forms[formname].elements['form_phone'].value.length < 1) problems += '- Missing Store Phone\n';
	
	if(!mailExp.test(document.forms[formname].elements['form_email'].value)) problems += '- Invalid E-Mail format\n';
	
	if(document.forms[formname].elements['form_userdb'].value.length < 8) problems += '- Missing or Invalid Username (Must be at least 8 Char)\n';
	if(document.forms[formname].elements['form_passdb'].value.length < 8) problems += '- Missing or Invalid Password (Must be at least 8 Char)\n';
	
	if(problems.length > 0){
		alert(problems);
		return false;
	}
	return true;
}
function checkStoreMod(formname){
	var problems = '';
	var mailExp = new RegExp("^[a-zA-Z0-9_.-]{1,}\@[a-zA-Z0-9.-]{2,}\\.[a-zA-Z]{1,}$");

	if(document.forms[formname].elements['form_first_name'].value.length < 1) problems += '- Missing First Name\n';
	if(document.forms[formname].elements['form_last_name'].value.length < 1) problems += '- Missing Last Name\n';

	if(document.forms[formname].elements['form_name'].value.length < 1) problems += '- Missing Store Name\n';
	if(document.forms[formname].elements['form_address'].value.length < 1) problems += '- Missing Store Address\n';
	if(document.forms[formname].elements['form_phone'].value.length < 1) problems += '- Missing Store Phone\n';
	if(!mailExp.test(document.forms[formname].elements['form_email'].value)) problems += '- Invalid E-Mail format\n';
	if(document.forms[formname].elements['form_city'].value.length < 1) problems += '- Missing Store City\n';
	if(document.forms[formname].elements['form_state'].value.length < 1) problems += '- Missing Store State\n';
	if(document.forms[formname].elements['form_zip'].value.length < 1) problems += '- Missing Store Zip Code\n';

	if(document.forms[formname].elements['form_passdb'].value.length > 0){
		if(document.forms[formname].elements['form_passdb'].value.length < 8) problems += '- Missing or Invalid Password (Must be at least 8 Char)\n';
	}

	if(problems.length > 0){
		alert(problems);
		return false;
	}
	return true;
}
function checkPanelForm(formname){
	var problems = '';
	var mailExp = new RegExp("^[a-zA-Z0-9_.-]{1,}\@[a-zA-Z0-9.-]{2,}\\.[a-zA-Z]{1,}$");
	if(document.forms[formname].elements['firstname'].value.length < 1) problems += '- Missing First Name\n';
	if(document.forms[formname].elements['lastname'].value.length < 1) problems += '- Missing Last Name\n';
	if(!mailExp.test(document.forms[formname].elements['email'].value)) problems += '- Invalid E-Mail format\n';

	if(problems.length > 0){
		alert(problems);
		return false;
	}
	return true;
}