function bookmark(){
	window.external.AddFavorite('http://www.torg.uz/','Torg.Uz');
};
function open_window(url,width,height){
	window.open(url,'_blank','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=yes,resizable=yes,width='+width+',height='+height+',top='+(window.screen.height/2 - height/2)+',left='+(window.screen.width/2 - width/2));
	return false;
};
function makehomepage(destobj){
	destobj.style.behavior='url(#default#homepage)';
	destobj.setHomePage('http://www.torg.uz/');
};
function length_left(maxlength, textlength, objid){	
	
	dispobj=document.getElementById(objid);	
	descriptionValue = document.getElementById('description1').value;	
	
	if(maxlength-textlength >= 0){		
		dispobj.style.color="green";	
		dispobj.innerHTML=maxlength-textlength;	
	} else {		
		document.getElementById('description1').value = document.getElementById('description1').value.substr(0, maxlength);		
	}
};

function show_groupNew(elementId){

	$(document).ready(function(){
		//alert('sim');
		$(".leftNavMenu").hide();

	});

	var element = document.getElementById(elementId);
	if(element.style.display == 'none')
		element.style.display = 'block';
	else
		element.style.display = 'none';

}

function show_group(group_array, active_group){
	for(group_id in group_array){
		groupStyle = document.getElementById(group_id).style;
		if(group_id == active_group){
			groupStyle.display = (groupStyle.display == 'none') ? '' : 'none';
		} else {
			groupStyle.display = 'none';
		}
	}
};
function check_subitems(subitems, parent_id, is_parent_event){
	if(is_parent_event){
		isChecked = document.getElementById(parent_id).checked;
		for(subitem_id in subitems){
			document.getElementById(subitem_id).checked = isChecked;
			if(isArray(subitems[subitem_id])) check_subitems(subitems[subitem_id], subitem_id, true);
		}
	} else if (arrayLength(subitems) > 0) {
		isChecked = true;
		for(subitem_id in subitems){
			if(document.getElementById(subitem_id).checked != true) isChecked = false;
		}
		document.getElementById(parent_id).checked = isChecked;
	}
};

function arrayLength(arr){
	arr_length = 0;
	for(void_this in arr) arr_length++;
	return arr_length;
}
function isArray(obj) {
	if (obj.constructor.toString().indexOf("Array") == -1)
		return false;
	else
		return true;
}

function load_my_image(img_id, img_width, img_height, site_url){
	with (parent.document) {
		with (getElementById('image_tag')) {
			src = site_url+'/images/notes/thumb-'+img_id+'.jpg';
			width = img_width;
			height = img_height;
		}
		getElementById('image_file_input').value = '';
		getElementById('image_id_input').value = img_id;
		getElementById('image_place').style.display="";
		getElementById('image_input').style.display="none";
	}
};

function clear_my_image(){
	with (parent.document) {
		with (getElementById('image_tag')) {
			src = '';
			width = 0;
			height = 0;
		}
		getElementById('image_id_input').value = 0;
		getElementById('image_place').style.display="none";
		getElementById('image_input').style.display="";
	}
};

function show_offer(the_event, popup_text){
	show_select_boxes();
	base_scroll_height = document.documentElement.scrollHeight;

	offerbox=document.getElementById("offerlayer");
	offerbox.innerHTML = popup_text;
	offerbox.style.left=document.documentElement.scrollLeft+the_event.clientX+10+'px';
	if(document.documentElement.scrollTop+the_event.clientY-offerbox.offsetHeight-5 >= 0){
		offerbox.style.top=document.documentElement.scrollTop+the_event.clientY-offerbox.offsetHeight-5+'px';
	} else {
		offerbox.style.top = 0+'px';
	}
	if(offerbox.offsetTop < document.documentElement.scrollTop) offerbox.style.top = document.documentElement.scrollTop+'px';

	if(document.documentElement.scrollHeight > base_scroll_height || (offerbox.offsetTop+offerbox.offsetHeight) > document.documentElement.scrollHeight){
		offerbox.style.top=base_scroll_height-offerbox.offsetHeight+'px';
	}
	hide_select_boxes();
	offerbox.style.visibility="visible";
};
function build_offer_popup(offer){

	popup  = '<table cellspacing=\"0\" cellpadding=\"0\" id=\"offerlayer_table\"><tr><td id=\"offerlayer_title\"><b>';
	popup += offer['title'];
	popup += '<\/b><\/td><\/tr><tr><td><table cellspacing=\"0\" cellpadding=\"0\"><tr><td valign=\"top\" width=\"100%\" id=\"offerlayer_text\">'+offer['description'];
	if(offer['price']) popup += '<br /><br />'+offer['price'];
	if(offer['phone']) popup += '<br /><br />'+offer['phone'];
	if(offer['ad_end_on']) popup += '<br /><br />'+offer['ad_end_on'];
	if(offer['companyId']) popup += '<br /><a href=\"'+site_url+'/catalog/' + offer['companyId'] + '\" target=\"blank\">'+company + '</a>';
	if(offer['priceFile']) popup += '&nbsp;-&nbsp;  <a href=\"'+site_url+'/files/prices/' + offer['companyId'] + '.' + offer['priceFile'] + '\" target=\"blank\">'+priceList + '</a>';
	
	if(offer['logo']){
		popup += '<\/td><td> <a href=\"#\"><img src=\"'+site_url+'/images/logos/thumb-'+offer['logo']+'.jpg\"  border=\"0\" align=\"right\" hspace=\"10\"><\/a>';
	}

	if(offer['image_width']!="0"){
		if(offer['image_width'] == parseFloat(offer['image_width']))
			popup += '<\/td><td><a href=\"#\" onñlick=\"javascript:open_window(\''+site_url+'/offer-'+offer['id']+'.htm\',600,600); return false;\"><img src=\"'+site_url+'/images/offers/thumb-'+offer['id']+'.jpg\" align=\"right\" style=\"padding:10px\"><\/a>';
		else
			popup += '<\/td><td><a href=\"#\" onclick=\"javascript:open_window(\''+site_url+'/images/offers/image-'+offer['image_width']+'\',500,600); return false;\"><img src=\"'+site_url+'/images/offers/thumb-'+offer['image_width']+'\" align=\"right\" style=\"padding:10px\"><\/a>';
	} else {
		//popup += '<\/td><td> <img src=\"'+site_url+'/images/no_photo.gif\" width=\"90\" height=\"60\" border=\"0\" align=\"right\" hspace=\"5\">';
	}

	popup += '<\/td><\/tr><\/table><\/td><\/tr>';
	popup += '<tr><td>&nbsp;&nbsp;<a href=\"#\" onclick=\"javascript:open_window(\''+site_url+'/offer-'+offer['id']+'.htm\',600,600); return false;\">'+more+'<\/a> <br /><br /></td></tr>';
	popup += '<tr><td id=\"offerlayer_foot\" nowrap>';
	if(offer['password']){
		if(offer['is_disabled']) popup += '<a href=\"#\" onclick=\"javascript:open_window(\''+site_url+'/edit.php?id='+offer['id']+'&action[republish]=true\',600,600); return false;\">'+offer['is_disabled']+'<\/a> &nbsp;|&nbsp; ';
		if(offer['ad_balance']) popup += '<a href=\"#\" onclick=\"javascript:open_window(\''+site_url+'/my-ad.php?offer[id]='+offer['id']+'\',600,600); return false;\">'+offer['ad_balance']+'<\/a> &nbsp;|&nbsp; ';
		else popup += '<a href=\"service-offers.htm\" >'+offer['ad_balanceNull']+'<\/a> &nbsp;|&nbsp; ';
		popup += '<a href=\"#\" onclick=\"javascript:open_window(\''+site_url+'/edit.php?id='+offer['id']+'&password='+offer['password']+'\',600,650); return false;\">'+edit_offer+'<\/a>';
	} else {
		if(offer['catalog']){
		if(offer['email']) popup += '<a href=\"#\" onclick=\"javascript:open_window(\''+site_url+'/offer.php?id='+offer['id']+'&action[contact]=true\',600,600); return false;\">'+offer['email']+'<\/a>';
		}
		else
		{
		if(offer['email']) popup += '<a href=\"#\" onclick=\"javascript:open_window(\''+site_url+'/offer.php?id='+offer['id']+'&action[contact]=true\',600,600); return false;\">'+offer['email']+'<\/a>';
		}
	}
	if(offer['delete_from_notepad'])
		popup+=' &nbsp;|&nbsp; <a href=\"my-notepad.php?action[delete]=true&notess[id]='+offer['note_id']+'\" >'+offer['delete_from_notepad']+'</a>  ';
	if(offer['auth']==1)
		popup+=' &nbsp;|&nbsp;<input type=\"hidden\" id=\"offer_id\" value=\"'+offer['id']+'\"> <a href=\"#\" onclick=\'JavaScript:xmlhttpPost(\"add_note.php?type=0\")\'>'+add_note+'</a>';

	if(offer['added_by']){
		popup+='&nbsp; | &nbsp;<a href=\"'+site_url+'/user/'+offer['added_by']+'/ \">'+user_profile+'</a>';
		if(offer['user_group'])
		popup+='&nbsp;<a href=\"'+site_url+'/help.htm#pro\"><img src=\"'+site_url+'/images/pro-account.jpg\" alt=\"\" align=\"middle\"/></a>';
	}
	if(!offer['password'])
	popup+='&nbsp; | &nbsp;<a href=\"#\" onclick=\"javascript:open_window(\''+site_url+'/offer.php?id='+offer['id']+'&action[complain]=true\',600,600); return false;\">'+complain+'<\/a>';

	popup+=' <\/td><\/tr><\/table> ';


	return popup;
};

function build_message_popup(message){
	popup  = '<table cellspacing=\"0\" cellpadding=\"0\" id=\"offerlayer_table\"><tr><td id=\"offerlayer_title\"><b>'+message['subject'];
	popup += '<\/b><\/td><\/tr><tr><td id=\"offerlayer_text\"><table cellspacing=\"0\" cellpadding=\"0\"><tr><td valign=\"top\" width=\"100%\">'+message['text'];
	if(message['phone']) popup += '<br><br>'+message['phone'];
	popup += '<br><br>'+message['email'];
	popup += '</td></tr></table></td></tr></table>';

	return popup;
};
function hide_offer(eventobj){
	offerbox  = document.getElementById("offerlayer");
	eventelem = document.getElementById("offerlayer_table");

	var left   = offerbox.offsetLeft;
	var top    = offerbox.offsetTop;
	var right  = offerbox.offsetLeft+eventelem.offsetWidth;
	var bottom = offerbox.offsetTop+eventelem.offsetHeight;

	eX = eventobj.clientX+document.documentElement.scrollLeft;
	eY = eventobj.clientY+document.documentElement.scrollTop;

	if(document.documentElement.clientLeft) eX -= document.documentElement.clientLeft;
	if(document.documentElement.clientTop) eY -= document.documentElement.clientTop;

	if (eX <= left || eX >= right || eY <= top || eY >= bottom){
		show_select_boxes();
		offerbox.style.visibility="hidden";
	}
};
function show_antibot_img(antibot_src){
	if(document.getElementById("td_antibot_img").innerHTML == ''){
		document.getElementById("td_antibot_img").innerHTML = '<img src="'+antibot_src+'" width="145" height="35" style="border: 1px solid gray">';
		document.getElementById("tr_img").style.display = '';
		document.getElementById("tr_input").style.display = '';
	}
}
function blink_me(objid){
	blinkobj = document.getElementById(objid);
	blinkobj.style.textDecoration = (blinkobj.style.textDecoration == 'underline') ? 'none' : 'underline';
	window.setTimeout("blink_me('"+objid+"')", 500);
}
function hide_select_boxes() {
	if(!document.all) return;

	tag_types = new Array("IFRAME", "SELECT", "OBJECT");
	offerbox  = document.getElementById("offerlayer");
	oX = page_location(offerbox, 'Left');
	oY = page_location(offerbox, 'Top');
	oW = offerbox.offsetWidth;
	oH = offerbox.offsetHeight;

	for (var j=0; j<tag_types.length; j++) {
		selEl = document.all.tags(tag_types[j]);
		for (var i=0; i<selEl.length; i++) {
			select_box = selEl[i];
			sX = page_location(select_box, 'Left');
			sY = page_location(select_box, 'Top');
			sW = select_box.offsetWidth;
			sH = select_box.offsetHeight;
			if((oX+oW) < sX || oX > (sX+sW) || (oY+oH) < sY || oY > (sY+sH)) continue;
			select_box.isHidden = 1;
			select_box.style.visibility = 'hidden';
		}
	}
}
function show_select_boxes() {
	if(!document.all) return;

	tag_types = new Array("IFRAME", "SELECT", "OBJECT");
	for (var j=0; j<tag_types.length; j++) {
		selEl = document.all.tags(tag_types[j]);
		for (var i=0; i<selEl.length; i++) {
			select_box = selEl[i];
			if(typeof select_box.isHidden !=  'undefined' && select_box.isHidden) {
				select_box.isHidden = 0;
				select_box.style.visibility = 'visible';
			}
		}
	}
}
function page_location(o, t){
	x = 0;
	while(o.offsetParent){
		x += o['offset'+t];
		o = o.offsetParent;
	}
	x += o['offset'+t];
	return x
}

function dw_scroller(id, w, h, num, axis, bMouse) {
  this.id=id; this.el = document.getElementById? document.getElementById(id): null;
  if (!this.el) return; this.css = this.el.style;
  this.css.left = this.x = 0; this.css.top = this.y = 0;
  this.w=w; this.h=h; this.num=num; this.axis=axis||"v";
  this.ctr=0; // pause onload (for large doc's, may want to set this to 1)
  this.pause=5000; this.speed=60; // defaults
  if (bMouse) dw_scrollers.setMouseEvents(this.el);
  this.lastTime = new Date().getTime(); this.check = 0;
  this.index = dw_scrollers.ar.length;  dw_scrollers.ar[this.index] = this;
  this.active = true;
}

dw_scroller.prototype.setTiming = function(speed, pause) {
  this.speed = speed; this.pause = pause;
}

dw_scroller.prototype.controlScroll = function() {
  if (this.ctr > this.num-1) {
    this.shiftTo(0, 0); this.ctr = 1;
	} else {
    switch (this.axis) {
      case "v" :
        if (this.y > -this.h * this.ctr) {
    			var ny = this.y + -1 * this.elapsed/1000 * this.speed;
          ny = Math.max(ny, -this.h * this.ctr);
          this.shiftTo(0, ny);
    		} else this.doPause();
      break;
      case "h" :
        if (this.x > -this.w * this.ctr) {
    			var nx = this.x + -1 * this.elapsed/1000 * this.speed;
          nx = Math.max(nx, -this.w * this.ctr);
          this.shiftTo(nx, 0);
    		} else this.doPause();
      break;
     }
	}
}

dw_scroller.prototype.doPause = function() {
  this.check += this.elapsed;
  if (this.check >= this.pause) { this.ctr++; this.check = 0; }
}

dw_scroller.prototype.shiftTo = function(x, y) {
  this.css.left = (this.x = x) + "px";
  this.css.top = (this.y = y) + "px";
}

dw_scrollers = {};
dw_scrollers.ar = []; // global access to all scroller instances

dw_scrollers.setMouseEvents = function(obj) {
  obj.onmouseover = dw_scrollers.halt;
  obj.onmouseout = dw_scrollers.resume;
}

dw_scrollers.halt = function() {
  var i, curObj;
  for (i=0; curObj = dw_scrollers.ar[i]; i++)
    if ( curObj.id == this.id ) { curObj.active = false; return; }
}

dw_scrollers.resume = function(e) {
  var i, curObj, toEl, now;
  for (i=0; curObj = dw_scrollers.ar[i]; i++) {
    if ( curObj.id == this.id ) {
      e = e? e: window.event;
      toEl = e.relatedTarget? e.relatedTarget: e.toElement;
      if ( this != toEl && !contained(toEl, this) ) {
        now = new Date().getTime();
        curObj.elapsed = now - curObj.lastTime;
        curObj.lastTime = now; curObj.active = true; return;
      }
    }
  }
}

dw_scrollers.callRate = 10;
dw_scrollers.timer = window.setInterval("dw_scrollers.control()", dw_scrollers.callRate);
dw_scrollers.control = function() {
  var i, curObj, now;
  for (i=0; curObj = dw_scrollers.ar[i]; i++) {
    if ( curObj.active ) {
      now = new Date().getTime();
      curObj.elapsed = now - curObj.lastTime;
      curObj.lastTime = now; curObj.controlScroll();
    }
  }
}

dw_scrollers.GeckoTableFix = function() {
  var i, wndo, holderId, holder, x, y;
	if ( navigator.userAgent.indexOf("Gecko") > -1 && navigator.userAgent.indexOf("Firefox") == -1 ) {
    dw_scrollers.hold = []; // holds id's of wndo (i.e., 'the scroller') and its container
    for (i=0; arguments[i]; i++) {
      wndo = document.getElementById( arguments[i] );
      holderId = wndo.parentNode.id;
      holder = document.getElementById(holderId);
      document.body.appendChild( holder.removeChild(wndo) );
      wndo.style.zIndex = 1000;
      x = holder.offsetLeft; y = holder.offsetTop;
      wndo.style.left = x + "px"; wndo.style.top = y + "px";
      dw_scrollers.hold[i] = [ arguments[i], holderId ];
    }
   window.addEventListener("resize", dw_scrollers.rePosition, true);
  }
}

dw_scrollers.rePosition = function() {
  var i, wndo, holder, x, y;
  if (dw_scrollers.hold) {
    for (i=0; dw_scrollers.hold[i]; i++) {
      wndo = document.getElementById( dw_scrollers.hold[i][0] );
      holder = document.getElementById( dw_scrollers.hold[i][1] );
      x = holder.offsetLeft; y = holder.offsetTop;
      wndo.style.left = x + "px"; wndo.style.top = y + "px";
    }
  }
}

function contained(oNode, oCont) {
  if (!oNode) return; // in case alt-tab away while hovering (prevent error)
  while ( oNode = oNode.parentNode ) if ( oNode == oCont ) return true;
  return false;
}

dw_scrollers.unHook = function() {
  var i, curObj;
  for (i=0; curObj = dw_scrollers.ar[i]; i++) {
    if ( curObj.el ) {
      curObj.el.onmouseover = null;
      curObj.el.onmouseout = null;
      curObj.el = null;
    }
  }
}

if ( window.addEventListener ) window.addEventListener( "unload", dw_scrollers.unHook, true);
else if ( window.attachEvent ) window.attachEvent( "onunload", dw_scrollers.unHook );

function getNewCode(){
	var rand=Math.random();
	$("#antibotImage").attr('src','/antibot.php?'+rand);
} 