var price_slider;

try {
    var $$$ = Ext.getDom;
  }
catch (e) {
  function $$$() {
    var elements = new Array();
  
    for (var i=0, tmpIdx=arguments.length; i<tmpIdx ; i++) {
      var element = arguments[i];
      if (typeof element == 'string')
        element = document.getElementById(element);
      if (arguments.length == 1)
        return element;
      elements.push(element);
    }
    return elements;
  }
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}

function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function PadDigits(n, totalDigits) { 
  n = n.toString(); 
  var pd = ''; 
  if (totalDigits > n.length) { 
    for (i=0; i<(totalDigits-n.length); i++) { 
      pd += '0'; 
    } 
  } 
  return pd + n.toString(); 
} 

function printf(S, L) {
	var nS = "";
	var tS = S.split("%s");
	if (tS.length != L.length+1) throw "Input error";
 
	for(var i=0; i<L.length; i++)
	nS += tS[i] + L[i];
	return nS + tS[tS.length-1];
}

function autoTab(input,len, e) {
	var isNN = false;
	var keyCode = (isNN) ? e.which : e.keyCode;
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
}

function ValidateInt(Value)	{
	var regExpInt = new RegExp("^[0-9]+$");
	var arr = regExpInt.exec(Value);
	try {
		var idx = arr.index;
		return(true);
	} catch(e) {
		return(false);
	}
}

function containsElement(arr, ele) {
	var found = false, index = 0;
	while (!found && index < arr.length) {
		if (arr[index] == ele) {
			found = true;
		} else {
			index++;
		}
	}
	return found;
}


function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1) {
		if (input.form[i] == input) {
			index = i;
		} else {
			i++;
		}
	}
	return index;
}


function getNodeText(inNode) {
	if (inNode) {
		return inNode.nodeValue
	} else {
		return "";
	}
}


function replaceHtml(el, html) {
	var oldEl = (typeof el === "string" ? document.getElementById(el) : el);
	/*@cc_on // Pure innerHTML is slightly faster in IE
		oldEl.innerHTML = html;
		return oldEl;
	@*/
	var newEl = oldEl.cloneNode(false);
	newEl.innerHTML = html;
	oldEl.parentNode.replaceChild(newEl, oldEl);
	/* Since we just removed the old element from the DOM, return a reference
	to the new element, which can be used to restore variable references. */
	return newEl;
};

function pausecomp(millis) {
  var date = new Date();
  var curDate = null;

  do { curDate = new Date(); }
    while(curDate-date < millis);
}

function $alert(inMsg, inTitle, inType) {
  if (inType == undefined) {
    msgIcon = Ext.MessageBox.WARNING;
  } else {
    switch (inType) {
      case 'info':
        msgIcon = Ext.MessageBox.INFO;
        break;
      case 'question':
        msgIcon = Ext.MessageBox.QUESTION;
        break;
      case 'error':
        msgIcon = Ext.MessageBox.ERROR;
        break;
      default:
        msgIcon = Ext.MessageBox.WARNING;
        break;
    }
  }
  if (inTitle == undefined) { inTitle = 'Alert'; } 
  Ext.MessageBox.show ({
    title: inTitle,
    msg: inMsg,
    buttons: Ext.MessageBox.OK,
    icon: msgIcon
  });
}


function str_repeat ( input, multiplier ) {
  // http://kevin.vanzonneveld.net
  // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // *     example 1: str_repeat('-=', 10);
  // *     returns 1: '-=-=-=-=-=-=-=-=-=-='

  var buf = '';

  for (i=0; i < multiplier; i++){
      buf += input;
  }

  return buf;
}

function iif (inCondition, inTrue, inFalse) {
  if (inCondition) {
    return inTrue;
  } else {
    return inFalse;
  }
}


function checkForFirebug() {
  if (window.console && window.console.firebug) {
    alert ('You have enabled Firebug for this site.\n Firebug is a debug tool. We dont\'t think you want to debug our service!\n\n Please disable firebug and try again.');
  };
}


function openPage(inID) {
  var width  = 600;
  var height = 450;
  var left   = (screen.width  - width)/2;
  var top    = (screen.height - height)/2;
  var params = 'width='+width+',height='+height;
  //params += ', top='+top+', left='+left;
  params += ',directories=no';
  params += ',location=no';
  params += ',menubar=no';
  params += ',resizable=yes';
  params += ',scrollbars=yes';
  params += ',status=no';
  params += ',toolbar=no';
  var url = 'pages.php?id=' + inID;
  newwin = window.open(url,'roomview',params);
  if (window.focus) {newwin.focus()}
  return false;
}


function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}


function RGB2HTML(red, green, blue) {
  //var decColor = red + 256 * green + 65536 * blue;
  (red   == 0) ? redC    = '00' : redC   = red.toString(16);
  (green == 0) ? greenC  = '00' : greenC = green.toString(16);
  (blue  == 0) ? blueC   = '00' : blueC  = blue.toString(16); 
  return  redC + greenC + blueC;
}
