﻿function escapeJs(s) {
	s = s.replace(new RegExp('\\\\', 'g'), '\\\\');
	s = s.replace(new RegExp('"', 'g'), '\\"');
	s = s.replace(new RegExp("'", 'g'), "\\'");
	return s;
}

var stopReloader = false;
function reloadPage() {
	if (stopReloader == true) return;
	window.setTimeout(reloadOnTimer, 1500);
}

function reloadOnTimer() {
	var href = window.location.href;
	window.location.href = href;
}

String.prototype.trim = function() {
	return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""));
}
String.prototype.endsWith = function(str) {
	return (this.match(str + "$") == str);
}
String.prototype.endsWith = function(str) {
	return (this.match(str + "$") == str);
}

function onHintTextBoxFocus(input) {
	if (input.value.trim() == input.title) 
		input.value = '';
}

function onHintTextBoxBlur(input) {
	if (input.value.trim().length == 0) 
		input.value = input.title;
}

function getParameterByName(name, url) {
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	if (url == null) url = window.location.href;
	var results = regex.exec(url);
	if (results == null) return "";
	else return results[1];
}

$.fn.extend({
insertAtCaret: function(myValue){
  this.each(function(i) {
    if (document.selection) {
      this.focus();
      sel = document.selection.createRange();
      sel.text = myValue;
      this.focus();
    }
    else if (this.selectionStart || this.selectionStart == '0') {
      var startPos = this.selectionStart;
      var endPos = this.selectionEnd;
      var scrollTop = this.scrollTop;
      this.value = this.value.substring(0, startPos)+myValue+this.value.substring(endPos,this.value.length);
      this.focus();
      this.selectionStart = startPos + myValue.length;
      this.selectionEnd = startPos + myValue.length;
      this.scrollTop = scrollTop;
    } else {
      this.value += myValue;
      this.focus();
    }
  })
}
})
