var objarr= new Array();

onload = function () {	
/*		alert(escape(document.referrer)+((typeof(screen)=="undefined")?"":
	";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?
	screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+
	";"+getCookie('uvID'));*/
}

function gid(id) {
  return document.getElementById(id);
}

function redir(loc, timeout) {
	setTimeout("document.location='"+loc+"'", timeout);
}

function show(val) {
	if (val) {
		if (val.style.display == '') {
			val.style.display = 'none';
		} else {
			val.style.display = '';
		}
	}
}

function setBkColor(obj, color) {
	obj.style.backgroundColor = color;
}

function showWindow(src) {
	cms_win_frame.src=src;
	show(cms_win);
}

function _out(name) {
	obj = document.getElementById(name);
	objb = document.getElementById(name+'B');
	obj.style.border = "1px solid #3081BA";
	objb.style.display = "none";
}

function _over(name) {
	obj = document.getElementById(name);
	objb = document.getElementById(name+'B');
	obj.style.border = "1px solid red";
	objb.style.display = "";
	//obj.style.display = "none";
}

function openCalendar() {

}

//-----------------------//
//  CMS BLOCKS
//-----------------------//

function _active(obj) {
	//    obj.style.cssText = "border: 1px solid #FFFFFF; ";
}

function _deactive(obj) {
	//    obj.style.cssText = "border: 1px solid #999999; ";
}


//-----------------------//
//  AJAX
//-----------------------//

function pageupdate() {
	window.location.reload(true)
}


function ajaxQuery(val, funcName) {
	JsHttpRequest.query(
	'/sys/ajax/getvalue.php',
	{
		'req': val
	},
	// Function is called when an answer arrives.
	function(result, errors) {
		eval(funcName+'(result);');
	},
	true// disable caching
	);
}

function jq(val, funcName, script) {
	JsHttpRequest.query(
	script,
	{
		'req': val
	},
	// Function is called when an answer arrives.
	function(result, errors) {
		eval(funcName+'(result);');
	},
	true// disable caching
	);
}


function ajaxCallback() {
    if (req.readyState == 4){
        if (req.status == 200) { 
            eval(req.responseText);
        }
    }
}


function req(vals) {
	ajaxQuery(vals, "req_cb");
}

function req_cb(res) {
      el = document.getElementById(res['id']+'dd');
      el.innerHTML = '';
      if (res['val']) {
	el.innerHTML = res['val'];
        el.className = "ddMenu";
        el.onclick = function() {el.className="ddNone";}
        document.onclick=function() {
          document.getElementById(res['id']+'dd').className="ddNone";
          document.onclick = "";
        }
      } else {
        el.className = "ddNone";
      }
}


function jsend(obj) {
  _timeout=0;
  _currobj = obj;
  _tout(0);
}

function _tout(time) {
  if (time == 5) {
    req({'cmd':'tag', 'val':_currobj.obj.value, 'id':_currobj.obj.id,'table':_currobj.table,'name':_currobj.name});
    timeout=0;       
  } else {
    _timeout++;
    setTimeout("_tout("+_timeout+");", 100);
  }
}

//-----------------------//
//  AJAX CONTROLS
//-----------------------//
function grid_update_row(id, data) {
	for (name in data)  {
		val = document.getElementById('col_'+id+'_'+name);
		val.innerHTML = data[name];
	}
}

function add_to_order(id, name, link) {
	req = new Array();
	req["cmd"] = "add_to_order";
	req["id"] = id;
	req["name"] = name;
	req["link"] = link;
	ajaxQuery(req, 'order_callback');
}

function delete_from_order(id) {
	req = new Array();
	req["cmd"] = "delete_from_order";
	req["id"] = id;
	ajaxQuery(req, 'order_callback');
}

function order_list() {
	req = new Array();
	req["cmd"] = "order_list";
	ajaxQuery(req, 'order_callback');
}

function set_dt(id) {
	el =  document.getElementById(id); 
	d = document.getElementById(id+'_d').value; 
	m = document.getElementById(id+'_m').value; 
	y = document.getElementById(id+'_y').value; 
	t = document.getElementById(id+'_t').value; 
	el.value = y+'-'+m+'-'+d+' '+t;
}

function delConfirm(str, str2) {
	if (!str2) str2 = 'Удалить содережимое модуля?';
	if (confirm(str2) == true) {
		document.location = str;
	}
}

function setCookie(name, value) {
	var today = new Date();
	expire = new Date(today.getTime() + 1000*60*60*24*356);
	document.cookie = name + "=" + escape(value)
	+ ((expire == null) ? "" : ("; expires="+ expire.toGMTString()+"; path=/"))
}

function getCookie(Name) {
	var search = Name + "="
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(offset, end))
		}
	}
}

  function pan_scroll(id, wx, dx, pp, step) {
    var el = document.getElementById(id);        
    if (el) {
      width = parseInt(el.width);
      if (dx <= -width+wx+step) {
        pp = pp*-1;
      }
      if (dx > 0) {
        pp = pp*-1;
      }      
      dx = dx + step*pp;
      el.style.marginLeft = dx+'px';
    }
    setTimeout("pan_scroll('"+id+"', "+wx+", "+dx+", "+pp+", "+step+")", 30);  
  }


var clear="/img/spacer.gif" //path to clear.gif

var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
pngfix=function(){
  if (isIE) {
    var els=document.getElementsByTagName('*');var ip=/\.png/i;var i=els.length;while(i-- >0){var el=els[i];var es=el.style;if(el.src&&el.src.match(ip)&&!es.filter){es.height=el.height;es.width=el.width;es.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+el.src+"',sizingMethod='crop')";el.src=clear;}else{var elb=el.currentStyle.backgroundImage;if(elb.match(ip)){var path=elb.split('"');var rep=(el.currentStyle.backgroundRepeat=='no-repeat')?'crop':'scale';es.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path[1]+"',sizingMethod='"+rep+"')";es.height=el.clientHeight+'px';es.backgroundImage='none';var elkids=el.getElementsByTagName('*');if (elkids){var j=elkids.length;if(el.currentStyle.position!="absolute")es.position='static';while (j-- >0)if(!elkids[j].style.position)elkids[j].style.position="relative";}}}}
  }
}
if (isIE) {window.attachEvent('onload',pngfix);}


//if (!getCookie("uvID")) {setCookie("uvID", Math.random());}