//use browser sniffing to determine if IE or Opera (ugly, but required)
var isOpera, isIE = false;
if(typeof(window.opera) != 'undefined'){isOpera = true;}
if(!isOpera && navigator.userAgent.indexOf('Internet Explorer')){isIE = true};

//fix both IE and Opera (adjust when they implement this method properly)
if(isOpera || isIE){
  document.nativeGetElementById = document.getElementById;
  //redefine it!
  document.getElementById = function(id){
    var elem = document.nativeGetElementById(id);
    if(elem){
      //verify it is a valid match!
      if(elem.attributes['id'] && elem.attributes['id'].value == id){
        //valid match!
        return elem;
      } else {
        //not a valid match!
        //the non-standard, document.all array has keys for all name'd, and id'd elements
        //start at one, because we know the first match, is wrong!
        for(var i=1;i<document.all[id].length;i++){
          if(document.all[id][i].attributes['id'] && document.all[id][i].attributes['id'].value == id){
            return document.all[id][i];
          }
        }
      }
    }
    return null;
  };
}

if(window_ua.htmlElement){
    HTMLElement.prototype.removeNode = function(removeChildren) {
        if (Boolean(removeChildren))
            return this.parentNode.removeChild(this);
        else {
            var r=document.createRange();
            r.selectNodeContents(this);
            return this.parentNode.replaceChild(r.extractContents(),this);
        }
    }
}

function deleteIt(lang, num)
{
    
//    document.getElementById('tbl_'+lang).removeNode(true);
    document.getElementById('tr1_'+lang+'_'+num).removeNode(true);
    document.getElementById('tr2_'+lang+'_'+num).removeNode(true);

}

function addElem(lang)
{
//    var countTr = document.getElementById('tbl_'+lang).childNodes[0].length;
    countItT++;
    var oRow = document.getElementById('tbl_'+lang).insertRow(-1);
    oRow.id = "tr1_"+lang+"_"+countItT;
    var oCell_1 = oRow.insertCell(-1);
    var oCell_11 = oRow.insertCell(-1);
    oCell_1.innerHTML = "Вопрос:<br>";
    oCell_11.align = "center";
    oCell_11.innerHTML = "<a href=\"javascript:;\" onclick=\"deleteIt('"+lang+"', '"+countItT+"');\">Удалить</a>";
    
    var tmp = document.createElement("input");
    tmp.type = "text";
    tmp.name = "q_"+lang+"_"+countItT;
    tmp.size = 60;
    tmp.value = "";
    oCell_1.appendChild(tmp);
    
    var oRow2 = document.getElementById('tbl_'+lang).insertRow(-1);
    oRow2.id = "tr2_"+lang+"_"+countItT;
    var oCell_2 = oRow2.insertCell(-1);
    oCell_2.colSpan = 2;
    oCell_2.innerHTML = "Ответы:<br>";
    var tmp = document.createElement("textarea");
    tmp.name = "a_"+lang+"_"+countItT;
    tmp.rows = 5;
    tmp.cols = 45;
    oCell_2.appendChild(tmp);
    
//    var oRow = document.getElementById('tbl_'+lang).insertRow(-1);
//    var oCell_1 = oRow.insertCell(-1);
    
}

function validateForm()
{
    var elemValue = '';
    var len = validateForm.arguments.length;
    for (var i=0; i<len; i++)
    {
        elemValue = document.getElementById(validateForm.arguments[i]);
        if (elemValue.value == '')
        {
            makeNotification();
            return false;
        }
    }
    return true;
}

var notificMess = null;

function makeNotification()
{
    var note = 'Заповніть, будь ласка, всі необхідні поля!';
    if (notificMess != null)
        note = 'Заповніть, будь ласка, всі поля!';
    
    alert(note);
}

function isValidEmail(email, mess)
{
    if (email.length == 0)
        return true;
        
    if ((/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email))
    {
        return true;
    }
 	else
 	{
 	    alert(mess);
 	    return false;
 	}
}

