function doc_onload() {
    var obj = document.getElementsByTagName('input');
    var sel_obj = null;
    var first_obj = null;
    for (var i = 0 ; i < obj.length; i++) {
        if (obj[i].name != 'q' && obj[i].type != 'file' && obj[i].type != 'hidden') {
            if (first_obj == null) first_obj = obj[i];
            if (sel_obj == null && obj[i].value == '') sel_obj = obj[i];

        
            var o = obj[i];
            if (/date_cal/.test(o.className)) {
                Calendar.setup({
                inputField     :    o.id,
                ifFormat       :    "%d.%m.%Y",
                ifFormat       :    "%Y-%m-%d %H:%M",
                button         :    o.id + "_cal",
                align          :    "Tl",
                singleClick    :    true
                });
            }
        
        }
    }

    obj = document.getElementsByTagName('select');
    for (var i = 0 ; i < obj.length; i++) {
        if (first_obj == null) first_obj = obj[i];
        if (sel_obj == null && obj[i].value == '') sel_obj = obj[i];
    }
    obj = document.getElementsByTagName('textarea');
    for (var i = 0 ; i < obj.length; i++) {
        if (first_obj == null) first_obj = obj[i];
        if (sel_obj == null && obj[i].value == '') sel_obj = obj[i];
    }
    initFileUploads();
}


function setup_panel_size() {
    /*if ($('bgpanel2').offsetHeight < $('bgpanel').offsetHeight) {
      $('bgpanel2').style.height = $('bgpanel').offsetHeight + 'px';
    }*/
}
  function window_open(url,title,w,h,x,y){
    var blaa = 'toolbar=0,location=0,directories=0,scrollbars=1,screenX='+x+',screenY='+y+',status=0,menubar=0,resizable=0,width='+w+',height='+h;
    open(url, title, blaa);
  }
  function $(x) {
    return document.getElementById(x);
  }
  function toggle(a1, a2) {
    $(a1).style.display='none';
    $(a2).style.display='block';
    return false;
  }
  function bk1(obj) {
    obj.style.backgroundColor='#ebebeb';
  }
  function bk2(obj) {
    obj.style.backgroundColor='#f4f4f4';
  }

  function hide(obj) {
      $(obj).style.display='none';
  }
  function show(obj) {
      $(obj).style.display='';
  }
  function upd_auct(type) {
    if (type == 'S') {
      show('resprice');
      hide('pquantity');
    }
    if (type == 'H') {
      hide('resprice');
      show('pquantity');
      hide('buynowcheck');
    }
    if (type == 'A') {
      hide('resprice');
      show('pquantity');
      hide('buynowcheck');
    }
  }
  function upd_currency(new_currency) {
      var x = document.getElementsByTagName('span');
      for (var i=0;i<x.length;i++) {
        if (x[i].className != 'currency') continue;
        x[i].innerHTML = new_currency;
      }

  }

  function set_interval(days) {
    //alert(days);
    var strd = $('fb_df').value.replace("-", "/");
    strd = strd.replace("-", "/");
    var d = new Date(strd);
    for (var i = 0 ; i < days; i++) {
      d.setDate(d.getDate()+1);
    }
    var dy = d.getFullYear();
    var dm = d.getMonth() + 1;
    var dd = d.getDate();
    var dh = d.getHours();
    var di = d.getMinutes();
    var dx = dy + "-" + (dm < 10 ? "0" : "") + dm + "-" + (dd < 10 ? "0" : "") + dd + " " + (dh < 10 ? "0" : "") + dh + ":" + (di < 10 ? "0" : "") + di + ":00";
    $('fb_dt').value = dx;
}



var locked = false;

function iu_start() {
    $('aim').onload=iu_complete;
    $('uploader').style.display='block';
    $('uploadform').style.display='none';
    return true;
}

function iu_complete() {

    locked = false;

    if (i.contentDocument) {
        var d = i.contentDocument;
    } else if (i.contentWindow) {
        var d = i.contentWindow.document;
    } else {
        var d = window.frames['aim'].document;
    }
    if (!d) return;
    
    if (d.location.href == "about:blank") {
        return;
    }

    response = d.body.innerHTML;
    
    document.getElementById('auc_pic_form').reset();
    $('uploader').style.display='none';
    $('uploadform').style.display='block';
  
    if( response != '') {
        $('iu_pictures').innerHTML = response;
    }
}



function initFileUploads()
{
    var x = document.getElementsByTagName('input');
    var n_inputs = 0;
    for (var i=0;i < x.length ; i++) {

            if (x[i].type != 'file') continue;
            if (x[i].parentNode.className != 'fileinputs') continue;
            n_inputs += 1;

            x[i].onchange = x[i].onmouseout = function () {
              if (!locked && this.value != '') {
                  locked = true;
                  var f = $('auc_pic_form');
                  iu_start();
                  f.submit();
              }
            }

    }
    if (n_inputs > 0) {
        var ifr = document.createElement('DIV');
        ifr.innerHTML = '<iframe style="display:none" src="about:blank" id="aim" name="aim" onload="iu_complete()"></iframe>';
        document.body.appendChild(ifr);
    }
}

function show_flash_banner(url, w, h) {
    document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ w + '" height="' + h + '">' + 
    '<param name="allowScriptAccess" value="sameDomain" />' + 
    '<param name="movie" value="' + url + '" />' + 
    '<param name="quality" value="high" />' + 
    '<embed src="' + url + '" quality="high" width="' + w + '" height="' + h + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
    '</object>');
}
function show_flash_banner_url(url, w, h, clicktag, clicktagname) {
    document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ w + '" height="' + h + '">' + 
    '<param name="allowScriptAccess" value="sameDomain" />' + 
    '<param name="movie" value="' + url + '?'+ clicktagname +'=' + clicktag + '" />' + 
    '<param name="quality" value="high" />' + 
    '<embed src="' + url + '?'+ clicktagname +'=' + clicktag + '" quality="high" width="' + w + '" height="' + h + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
    '</object>');
}

function check_checkboxs(check) {
    var x = document.getElementsByTagName('input');
    for (var i=0;i < x.length ; i++) {
        if (x[i].name.indexOf('all') == -1 && x[i].name.indexOf('recent') == -1 && x[i].name.indexOf('cat') == -1) {
            x[i].checked = check;
        }
    }
}

function targetBlank (url) {
    blankWin = window.open(url,'_blank','menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes');
}

function appletSessionCompleted(result, key, localFile, description) {
    var message = "JavaScript event:\r\n" +
       " result: " + result + "\r\n" +
    	" key: " + key + "\r\n" +
    	" localFile: " + localFile + "\r\n" +
    	" description: " + description;
    alert(message);
}

function clearDefaultText(obj, defaultText) {    
    if (obj.value == defaultText) {
        obj.value = '';
    }
    obj.style.color="black";
}

function showImailReply(userTo, topic, processSubject) {
    if( typeof(processSubject) == 'undefined'){
        processSubject = true;
    }
    document.getElementById('txtToUser').value = userTo;
    document.getElementById('txtSubject').value = topic;

	if (topic && processSubject)
	{
		newsubj = topic;
		if (topic.substring(0, 3) != 'Re:' && topic.substring(0, 3) != 'Re[')
		{
			newsubj = 'Re[1]: ' + topic;
		}
		else if (topic.substring(0, 3) == 'Re[')
		{
			pos = topic.indexOf(']');
			if (pos && pos > 0 && !isNaN(pos))
			{
				count = topic.substring(3, pos) * 1;
				newsubj = 'Re[' + (count + 1) + ']:' + topic.substring(pos + 2, topic.length);
			}
		}
		else if (topic.substring(0, 3) == 'Re:')
		{
			topic = topic.replace('Re:', '');
			newsubj = 'Re[2]: ' + topic;
		}
		document.getElementById('txtSubject').value = newsubj;
	}
    document.getElementById('divnewimsg').style.display = '';
    return false;
}

function setOrdering(newVal) {
    $('orderingSel').options[$('orderingSel').selectedIndex].value = newVal;
    return $('ordering').submit();
}

function setOrderingRM(newVal) {
    $('orderingSel').value = newVal;
    return $('ordering').submit();
}

function disableEnterKey(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}

function DraugiemSay( title, url, titlePrefix ){
 window.open(
  'http://www.draugiem.lv/say/ext/add.php?title=' + encodeURIComponent( title ) +
  '&link=' + encodeURIComponent( url ) +
  ( titlePrefix ? '&titlePrefix=' + encodeURIComponent( titlePrefix ) : '' ),
  '',
  'location=1,status=1,scrollbars=0,resizable=0,width=530,height=400'
 );
 return false;
}


function show_lang_menu() {
    document.getElementById('lang_menu').style.display = 'block';
    document.getElementById('lang_menu_block').style.border = '1px solid #ccc';
    document.getElementById('lang_menu_block').style.borderBottom = '2px solid #ccc';
    document.getElementById('lang_menu_block').style.borderRight = '2px solid #ccc';
}

function hide_lang_menu() {
    document.getElementById('lang_menu').style.display = '';
    document.getElementById('lang_menu_block').style.border = '1px solid #fff';
}

function cp_confirm(tt) {
    var r=confirm(tt);
    if (r==true) {
        document.frmAuctions.submit(); return false;
    } else {
        return false;
    }
}

function cpSetAucMultiAction(val) {
    document.getElementById('aucMultiAction').value = val;
}