function setSelectionRange(input, selectionStart, selectionEnd) {
  if (input.setSelectionRange) {
    input.focus();
    input.setSelectionRange(selectionStart, selectionEnd);
  }
  else if (input.createTextRange) {
    var range = input.createTextRange();
    range.collapse(true);
    range.moveEnd('character', selectionEnd);
    range.moveStart('character', selectionStart);
    range.select();
  }
}
function setCaretToEnd (input) {
  setSelectionRange(input, input.value.length, input.value.length);
}


function allow_url_http(id){
	var the_text;
	the_text = document.getElementById(id).value.replace(/^\s+|\s+$/g,"");
	
	if(the_text==""){
		document.getElementById(id).value = "http://";
		setCaretToEnd(document.getElementById(id));
		document.getElementById("save").value = "حفظ وإضافة موقع";
	}else if(the_text=="http://"){
		document.getElementById(id).value = "";
		document.getElementById("save").value = "حفظ";
	}
}


function allow_url_http_blur(id){
	var the_text;
	the_text = document.getElementById(id).value.replace(/^\s+|\s+$/g,"");
	document.getElementById(id).value = the_text;
	
	if(the_text==""){
		document.getElementById(id).value = "";
		document.getElementById("save").value = "حفظ";
	}else if(the_text=="http://"){
		document.getElementById(id).value = "";
		document.getElementById("save").value = "حفظ";
	}else if(the_text.substring(7,0) != "http://"){
		document.getElementById(id).value = "";
		document.getElementById("save").value = "حفظ";
	}
}
