var errorMsg0 = 'Заполнены не все поля';
var errorMsg1 = 'Это же не число!';
var errorMsg2 = ' здесь не подходит';
var errorMsg3 = 'Select country, please';
var errorMsg4 = 'Select resort, please';
var errorMsg5 = 'Select correctly star rank, please';
/**
 * Displays an error message if an element of a form hasn't been completed and
 * should be
 *
 * @param   object   the form
 * @param   string   the name of the form field to put the focus on
 *
 * @return  boolean  whether the form field is empty or not
 */
function emptyFormElements(theForm, theFieldName)
{
    var isEmpty  = 1;
    var theField = theForm.elements[theFieldName];
    // Whether the replace function (js1.2) is supported or not
    var isRegExp = (typeof(theField.value.replace) != 'undefined');

    if (!isRegExp) {
        isEmpty      = (theField.value == '') ? 1 : 0;
    } else {
        var space_re = new RegExp('\\s+');
        isEmpty      = (theField.value.replace(space_re, '') == '') ? 1 : 0;
    }
    if (isEmpty) {
//        theForm.reset();
        theField.select();
        alert(errorMsg0);
        theField.focus();
        return false;
    }

    return true;
} // end of the 'emptyFormElements()' function
/**
 * Ensures a value submitted in a form is numeric and is in a range
 *
 * @param   object   the form
 * @param   string   the name of the form field to check
 * @param   integer  the minimum authorized value
 * @param   integer  the maximum authorized value
 *
 * @return  boolean  whether a valid number has been submitted or not
 */
function checkFormElementInRange(theForm, theFieldName, min, max)
{
    var theField         = theForm.elements[theFieldName];
    var val              = parseInt(theField.value);

    if (typeof(min) == 'undefined') {
        min = 0;
    }
    if (typeof(max) == 'undefined') {
        max = Number.MAX_VALUE;
    }

    // It's not a number
    if (isNaN(val)) {
        theField.select();
        alert(errorMsg1);
        theField.focus();
        return false;
    }
    // It's a number but it is not between min and max
    else if (val < min || val > max) {
        theField.select();
        alert(val + errorMsg2);
        theField.focus();
        return false;
    }
    // It's a valid number
    else {
        theField.value = val;
    }

    return true;
} // end of the 'checkFormElementInRange()' function

function checkFormElementToZero(theForm, theFieldName, typeMsg)
{
    var theField         = theForm.elements[theFieldName];
    var val              = parseInt(theField.value);

if (val == 0 ) {
        theField.focus();
		if(typeMsg==1)
		  alert(errorMsg3);
		else
          alert(errorMsg4);
        theField.focus();
        return false;
    }
    // It's a valid number
    else {
        theField.value = val;
    }

    return true;
} // end of the 'checkFormElementInRange()' function


function checkFormElementToStar(theForm, theFieldName)
{
    var theField         = theForm.elements[theFieldName];
    var val              = parseInt(theField.value);
 if ((val != 3 )&(val!=4)&(val!=5)&(val!=6)) {
        theField.focus();
        alert(errorMsg5);
        theField.focus();
        return false;
    }
    else {
        theField.value = val;
    }

    return true;
}
function checkFormElementToNull(theForm, theFieldName)
{
    var theField         = theForm.elements[theFieldName];
    var val              = parseInt(theField.value);


 if (val == 0 ) {
        theField.focus();
        alert(errorMsg3);
        theField.focus();
        return false;
    }
    // It's a valid number
    else {
        theField.value = val;
    }

    return true;
}

var tr=0;

function to_change(act){
w=eval('window.document');
var k;
with(w){
  s=selection.createRange().text;
  if (s) {
	switch(act) {
      case 'h1': s=eval("'<h1>'+s+'</h1>'"); break;
	  case 'h2': s=eval("'<h2>'+s+'</h2>'"); break;
	  case 'h3': s=eval("'<h3>'+s+'</h3>'"); break;
	  case 'p': s=eval("'<p>'+s+'</p>'"); break;
	  case 'br': s=eval("s+'<br>'"); break;
	  case 'nb': s=eval("s+'&nbsp;'"); break;
	  case 'ul': s=eval("'<ul>'+s+'</ul>'"); break;
	  case 'li': s=eval("'<li>'+s+'</li>'"); break;
	  case 'strong': s=eval("'<strong>'+s+'</strong>'"); break;
	  case 'b': s=eval("'<b>'+s+'</b>'"); break;
	  case 'i': s=eval("'<i>'+s+'</i>'"); break;
	  case 'u': s=eval("'<u>'+s+'</u>'"); break;
	  case 'a': {k=prompt("Введите URL. Для ссылки на внешний ресурс следует указывать полный URL страницы (приставка http:// обязательна)",""); if (k) s=eval("'<a href=\"'+k+'\" class=\"under\">'+s+'</a>'");} break;
	  case 'a_target': {k=prompt("Введите URL. Для ссылки на внешний ресурс следует указывать полный URL страницы (приставка http:// обязательна)",""); if (k) s=eval("'<a href=\"'+k+'\" target=\"_blank\" class=\"under\">'+s+'</a>'");} break;
	  case 'a_mail': {k=prompt("Введите электронный адрес",""); if (k) s=eval("'<a href=\"mailto:'+k+'\" class=\"under\">'+s+'</a>'");} break;
	  case 'img': {k=prompt("Введите имя файла с расширением.",""); if (k) s=eval("'<img src=\"http://www.efremov.net/images/'+k+'\" border=\"\" align=\"\" vspace=\"\"  class=\"\" hspace=\"\" width=\"\" height=\"\" alt=\"'+s+'\">'");} break;
	  case 'class': {k=prompt("Введите название класса.",""); if (k) s=eval("' class=\"'+k+'\" '+s");} break;
	  case 'div': s=eval("'<div>'+s+'</div>'"); break;
	  }
	selection.createRange().text=s;
	}
  else
    {
    if(tr){
   	  switch(act){
 	    case 'h1':  tr.text='<h1></h1>'; break;
	    case 'h2':  tr.text='<h2></h2>'; break;
  	    case 'h3':  tr.text='<h3></h3>'; break;
	    case 'p':  tr.text='<p></p>'; break;
	    case 'br':  tr.text='<br>'; break;
	    case 'nb':  tr.text='&nbsp;'; break;
	    case 'ul':  tr.text='<ul></ul>'; break;
	    case 'li':  tr.text='<li></li>'; break;
	    case 'strong':  tr.text='<strong></strong>'; break;
	    case 'b':  tr.text='<b></b>'; break;
	    case 'i':  tr.text='<i></i>'; break;
	    case 'u':  tr.text='<u></u>'; break;
	    case 'a': {k=prompt("Введите URL. Для ссылки на внешний ресурс следует указывать полный URL страницы (приставка http:// обязательна)",""); if (k) tr.text='<a href=\"'+k+'\" class=\"under\"></a>';} break;
	    case 'a_target': {k=prompt("Введите URL. Для ссылки на внешний ресурс следует указывать полный URL страницы (приставка http:// обязательна)",""); if (k)  tr.text='<a href=\"'+k+'\" target=\"_blank\" class=\"under\"></a>';} break;
	    case 'a_mail': {k=prompt("Введите электронный адрес",""); if (k)  tr.text='<a href=\"mailto:'+k+'\" class=\"under\"></a>';} break;
  	    case 'img': {k=prompt("Введите имя файла с расширением.",""); if (k) tr.text='<img src=\"http://www.efremov.net/images/'+k+'\" class=\"\" border=\"\" align=\"\" vspace=\"\"  hspace=\"\" width=\"\"  height=\"\" alt=\"\">';} break;
	    case 'class': {k=prompt("Введите название класса.",""); if (k) tr.text=' class=\"'+k+'\" ';} break;
	    case 'div':  tr.text='<div></div>'; break;
	    }
      }
    }
  }
}

function f2() {
   tr = document.body.createTextRange();
   tr.moveToPoint(event.clientX, event.clientY);
}

