// Get element by ID
function getEl(id){
    if(document.layers){
        return document.layers[id];
    }
    if(document.all && document.all.item){
        return document.all[id];
    }
    if(document.getElementById){
        return document.getElementById(id);
    }
}


// Get ajax by adress
function GetAjax(m_adress){ 
      var Res;
      
      if (typeof window.ActiveXObject != 'undefined' ) 
      {
        Res = new ActiveXObject("Microsoft.XMLHTTP");
      }
      else 
      {
        Res = new XMLHttpRequest();
      }
      Res.open("GET", 'http://' + document.domain + '/ajax/' + m_adress, false );
      Res.send( null );
      if ( Res.readyState != 4 ) return ;
      
      return Res.responseText;      
}

function Prosmotr(id)
{
    $("#wnts"+id).html($("#prs1").val());
    $("#wnts1").val("prosmotr");
    $('#pdata').html("<b>" + getEl("posdata").value + "</b><br /><br />" + $('#' + id).html()); 
    $.blockUI({ message: $('#sendform'), css: { top: '20%', left: ($(window).width() - 500) /2 + 'px', width: '500px', cursor: null } });    
}

function Kupit(id)
{
    $("#wnts"+id).html($("#prs2").val());
    $("#wnts1").val("kupit");
    $('#pdata').html("<b>" + getEl("posdata").value + "</b><br /><br />" + $('#' + id).html()); 
    $.blockUI({ message: $('#sendform'), css: { top: '20%', left: ($(window).width() - 500) /2 + 'px', width: '500px', cursor: null } });
}

function Prodat()
{
    $.blockUI({ message: $('#prform'), css: { top: '20%', left: ($(window).width() - 500) /2 + 'px', width: '500px', cursor: null } });
}

function sendobj()
{
    if ($("#contacts2").val()!="")
    {
        var res=GetAjax('sendorder3.php?contacts=' + escape($("#contacts2").val()) + "&zobject=" + escape($("#zobject").val()) + "&pdata=" + escape($('#posdata').val()));
        $.blockUI({ message: $('#sended') });
        setTimeout($.unblockUI, 1000);
    }
    else alert($("#nocontacts").val());
}

function canselmessage()
{
    setTimeout($.unblockUI, 100);
}

function sendmessage()
{
    if ($("#contacts").val()!="")
    {
        var res=GetAjax('sendorder2.php?eml=' + $("#wnts1").val() + '&contacts=' + escape($("#contacts").val()) + "&pdata=" + escape($('#pdata').html()));
        $.blockUI({ message: $('#sended') });
        setTimeout($.unblockUI, 1000);
    }
    else alert($("#nocontacts").val());
}

function SendOrder()
{
    var whish=getEl("whish");
    var contacts=getEl("contacts");
    var res=GetAjax('sendorder.php?whish=' + escape(getIframeDocument(whish).body.innerHTML) + '&contacts=' + escape(getIframeDocument(contacts).body.innerHTML));
    alert(res);
}

function BigPhoto(photo)
{
    getEl("mainf").src=photo;
}
