var agt=navigator.userAgent.toLowerCase();
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));  

var idsA = new Array();
window.$ = function (id){
  if(idsA[id] != null)
    return idsA[id];
  else
    return idsA[id] = document.getElementById(id)
}
/*dynapi.library.setPath('/includes/dynapi/');
dynapi.library.include('dynapi.api');
dynapi.library.include('ViewPane');
*/
/*function dw_showLayers() {
  if ( document.getElementById ) {
    var lyr, i;
    for (i=0; arguments[i]; i++) {
      lyr = document.getElementById( arguments[i] );
      lyr.style.visibility = "visible";
    }
  }
}
function initScrollLayers() {
  // arguments: id of layer containing scrolling layers (clipped layer), id of layer to scroll, 
  // if horizontal scrolling, id of element containing scrolling content (table?)
 // var wndo1 = new dw_scrollObj('wn1', 'lyr1', null);

  // arguments: dragBar id, track id, axis ("v" or "h"), x offset, y offset
  // (x/y offsets of dragBar in track)
  //wndo1.setUpScrollbar("dragBar1", "track1", "v", 1, 1);
  
  var wndo2 = new dw_scrollObj('wn2', 'lyr2', 'imgTbl');
  wndo2.setUpScrollbar("dragBar2", "track2", "v", 1, 1);
  wndo2.setUpScrollbar("dragBar3", "track3", "h", 1, 1);
  
  // Read instructions if your scrolling layers are inside tables 
  
  // Scrollbars initially hidden in this example 
  dw_showLayers("scrollbar2", "scrollbar3");
}*/
if(is_ie){
  window.fixPng = function (imgName, path, sstyle, onloadf) { 
    if(path == '')
      path = '/images/collections/models/';
    var img = new Image();
    img.src = path+imgName;
   /* return "<span style=\"" + "width:" + img.width + "px; height:" + img.height + "px;cursor:hand;display:inline-block;;" 
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" 
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" */
    return "<img  "+(onloadf!=''?'onload="'+onloadf+'"':'')+" src='/images/design/null.gif' width='"+img.width+"' height='"+img.height+"' style='"+sstyle+";filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+'"'+img.src+'"'+");') />";
  } 
}else {
  window.fixPng = function (imgName, path, sstyle, onloadf) { 
    if(path == '')
      path = '/images/collections/models/';
    return "<img style='"+sstyle+";cursor:hand;' src='"+path+imgName+"' alt='' "+(onloadf!=''?'onload="'+onloadf+'"':'')+" />";
  }
}

// collections pictures
var currentCollection = 0;
collections = new Array();
                
function scrollRightCollections(){
  if(currentCollection == collections.length)
    currentCollection = 0;
  else
    currentCollection++;
  showCollections();
}
function scrollLeftCollections(){
  if(currentCollection == 0)
    currentCollection = collections.length;
  currentCollection--;
  showCollections();
}



function showCollections(){
  code = '<table border="0" width="100%"><tr>';
  var c = 5;
  if(collections.length < 5)
    c = collections.length;
  if(c == 0)
    return;
  for(i = currentCollection; i <= currentCollection + 5; i++){
    if(c == 0)
      break;
    if(i >= collections.length)
      i = 0;
    if(collections[i]!=null){
       c--;
       code += "<td valign='top' style='padding-left:5px;'>";
       if(collections[i][1] != '')
       code += "<a href='"+collections[i][1]+"'>";
       var imgName = collections[i][0];
       if (imgName.substring(imgName.length-3, imgName.length) == "png") 
          code += fixPng(imgName);
       else
          code += "<img width='149' height='73' src='/images/collections/"+imgName+"' alt='' />";
       if(collections[i][1] != '')
        code += "</a>";
       code += "<br/><a class='colSelLink2'>"+collections[i][2]+"</a>";
       code += "</td>";
    }
  }
  code += '</tr></table>';
  document.getElementById('collections_td').innerHTML = code;
}

function makeRequest(url) {
                  alert('123');
                http_request = false;

                if (window.XMLHttpRequest) { // Mozilla, Safari,...
                    http_request = new XMLHttpRequest();
                    if (http_request.overrideMimeType) {
                        http_request.overrideMimeType('text/xml');
                    }
                } else if (window.ActiveXObject) { // IE
                    try {
                        http_request = new ActiveXObject("Msxml2.XMLHTTP");
                    } catch (e) {
                        try {
                        http_request = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e) {}
                    }
                }

                if (!http_request) {
                    alert('Giving up :( Cannot create an XMLHTTP instance');
                    return false;
                }
                http_request.onreadystatechange = alertContents;
                http_request.open('GET', url, true);
                http_request.send(null);

            }

            function alertContents() {

                if (http_request.readyState == 4) {
                    if (http_request.status == 200) {
                        alert(http_request.responseText);
                    } else {
                        alert('There was a problem with the request.');
                    }
                }

            }



function showbig(picname){
    window.open('/includes/foto.php5?pic='+picname,'_blank','scrollbars=yes,taskbar=no,resizeable=no,status=no,menubar=no,top=30,left=30,width=30,height=30');
  }
  
  function PreLoad(source){
    var NewImage = new Image();
    NewImage.src = source;
  }
  
  function prepareSubmit(frm){
    var len = frm.all("editbox").length; if (!len) len = 1;
    for (var i=0; i<len; i++)
      frm.all("codebox", i).innerText = frm.all("codebox", i).style.display ? borderOn(frm.all("codebox", i).innerText) : borderOn(frm.all("editbox", i).innerHTML);
  }
   
 function menuProcess(menuId){
 	 if(menuId.style.display == 'none'){
     menuId.style.display = 'block';
   }else{
   	 menuId.style.display = 'none';
   }
 }
 
 function btShowFunctionArguments(name){
	 btChangeFunctionArgumentsBlock(name,'none','block','block');
 }
 
 function btHideFunctionArguments(name){
	 btChangeFunctionArgumentsBlock(name,'block','none','none');
 }
 
 function btChangeFunctionArgumentsBlock(name,plus,minus,arguments){
 	 document.getElementById('backtrace_img_plus_'+name).style.display = plus;
 	 document.getElementById('backtrace_img_minus_'+name).style.display = minus;
 	 document.getElementById('backtrace_arguments_'+name).style.display = arguments;
 }
 
  function processTree(elementId,isTop){
 	 tbl = document.getElementById('dir_'+elementId);
 	 img = document.getElementById('img_'+elementId);
 	 
 	 if(tbl.style.display != 'none'){
 	 	 tbl.style.display = 'none';
 	 	 img.alt = 'Раскрыть';
 	 	 if(isTop)
 	 	   img.src = '/images/design/tree_plus.gif';
 	 	 else
 	 	   img.src = '/images/design/tree_sub_plus.gif';
 	 }else{
 	 	 tbl.style.display = 'block';
 	 	 img.alt = 'Закрыть';
 	 	 if(isTop)
 	 	   img.src = '/images/design/tree_minus.gif';
 	 	 else
 	 	   img.src = '/images/design/tree_sub_minus.gif';
 	 }
 }
 
  /*function scrollRightCollections(){
    o = document.getElementById("collections");
    if(o.scrollWidth - 770 - o.scrollLeft >= 154)
      o.scrollLeft = o.scrollLeft + 156;
  }
  function scrollLeftCollections(){
    o = document.getElementById("collections");
    if(o.scrollLeft >= 154)
      o.scrollLeft = o.scrollLeft - 156;
  }*/
