var moz = (navigator.appName=="Netscape") ? true : false;
function $(id){return document.getElementById(id);}
setOuterHtml = function (pElement, pHTML)
{
 if (typeof pElement.outerHTML == 'undefined')
 {
 var r = document.createRange();
 r.setStartBefore(pElement);
 var df = r.createContextualFragment(pHTML);
 pElement.parentNode.replaceChild(df, pElement);
 }
 else
 {
 pElement.outerHTML = pHTML;
 }
}
var curPhoto = 1;
var maxPhoto = 50;

var curTel = 0;
var maxTel = 4;

var ini = 0;

var AddPhoto = function ()
{
    curPhoto = curPhoto + 1;
    var s = '<div><input type="file" size="28" style="height: 21px;" name="photo' + curPhoto + '" id="fPhoto' + curPhoto + '"/></div>';
    if (curPhoto < maxPhoto) s = s + '<a id="addphoto" href="javascript:AddPhoto(); void 0;">Ещё фото<\/a>';
    setOuterHtml($('addphoto'), s);
}

var AddTel = function ()
{
	curTel = curTel + 1;
	var s = '<div class="left_cont"><span class="left_foto">';
	s = s + '</span>' +
	'<div class="cont_body">' +
	'(<input style="width: 40px;" maxlength="5" name="codephone_' + curTel + '" id="inCodePhone_' + curTel + '" type="text"/>)' +
	'&nbsp;&nbsp;<input style="width: 99px;" maxlength="7" name="phone_' + curTel + '" id="inPhone_' + curTel + '" type="text"/>' +
	'<small>(внесите свой номер телефона, без пробелов и тире)</small>' +
	'</div></div>';
	if (curTel < maxTel) s = s + '<a id="addtel" href="javascript:AddTel(); void 0;" style="font-size: 13px;">Ещё телефон<\/a>';
	setOuterHtml($('addtel'), s);
}

var initb = function (){
  if (ini==2){
    //AddPhoto();
    AddTel();
  }
}


function init() {
   ini = ini + 1;
   initb();
};

if ((window.opera)||(moz)) {
    ini = 1;
    if (document.addEventListener) {
        document.addEventListener("DOMContentLoaded", init, false);
    }
} else init();

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
    document.write("<script id=\"__ie_onload\" defer=\"defer\" src=\"javascript:void(0)\"><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
            ini = ini + 1;
			initb(); // call the onload handler
		}
	};
/*@end @*/

/*var checkForm = function ()

{
    var ioberror3=true;
    var errorList = [];
    var errorText = {
        1 : "Не указан тип транспортного средства",
        2 : "Неверно указан первый телефон",
        3 : "Неверно указан второй телефон",
        4 : "Неверно указан третий телефон",
        5 : "Неверно указан четвертый телефон",
        6 : "Неверно указан е-mail адрес",
    }
    if ($('sVehicle').options[$('sVehicle').selectedIndex].value == '') errorList.push(1);

    //var reg = /[0-9a-z_]+@[0-9a-z_^.]+\.[a-z]{2,3}/i;
    //if (!reg.test($("replyto").value)) errorList.push(6);
    if ($("replyto").value == "") errorList.push(6);

    var regd = /[\d]/;

    if ( (!($("inCodePhone_1").value.length + $("inPhone_1").value.length == 10))
         ||(!(regd.test($("inCodePhone_1").value)))
         ||(!(regd.test($("inPhone_1").value))) )
            errorList.push(2);

    for (i = 2; i <=4; i++ )
    try
    {
        if ( ($("inCodePhone_"+i).value.length + $("inPhone_"+i).value.length > 0)
             &&( (!($("inCodePhone_"+i).value.length + $("inPhone_"+i).value.length == 10))
             ||(!(regd.test($("inCodePhone_"+i).value)))
             ||(!(regd.test($("inPhone_"+i).value))) ) )
            errorList.push(1+i);
    }
    catch (e) {}   

    if (!errorList.length) return true;
    // Если есть ошибки - формируем сообщение, выовдим alert
    // и возвращаем false
    var errorMsg = "При заполнении формы допущены следующие ошибки:\n\n";
    for (i = 0; i < errorList.length; i++) {
        errorMsg += errorText[errorList[i]] + "\n";
    }
    alert(errorMsg);
    return false;
};

var testKey = function(e)
{
    var reg = /^\d+$/;
    var val = e.srcElement.value.trim();
    if (!(reg.test(val)))
    {
        e.srcElement.value = '';
        alert('Разрешен ввод только цифр');
    }

};*/