
// from http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();

// *** BROWSER VERSION ***
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

// Note: Opera and WebTV spoof Navigator.  We do strict client detection.
// If you want to allow spoofing, take out the tests for opera and webtv.
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
			&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
			&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav2 = (is_nav && (is_major == 2));
var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) ||
				(agt.indexOf("; nav") != -1)) );
var is_nav6 = (is_nav && (is_major == 5));
var is_nav6up = (is_nav && (is_major >= 5));
var is_gecko = (agt.indexOf('gecko') != -1);

var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up  = (is_ie && (is_major >= 4));
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

// KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
// or if this is the first browser window opened.  Thus the
// variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
var is_aol   = (agt.indexOf("aol") != -1);
var is_aol3  = (is_aol && is_ie3);
var is_aol4  = (is_aol && is_ie4);
var is_aol5  = (agt.indexOf("aol 5") != -1);
var is_aol6  = (agt.indexOf("aol 6") != -1);

var is_opera = (agt.indexOf("opera") != -1);
var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
var is_opera6 = (agt.indexOf("opera 6") != -1 || agt.indexOf("opera/6") != -1);
var is_opera7 = (agt.indexOf("opera 7") != -1 || agt.indexOf("opera/7") != -1);
var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

var is_webtv = (agt.indexOf("webtv") != -1); 

var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 
var is_AOLTV = is_TVNavigator;

var is_hotjava = (agt.indexOf("hotjava") != -1);
var is_hotjava3 = (is_hotjava && (is_major == 3));
var is_hotjava3up = (is_hotjava && (is_major >= 3));

// *** JAVASCRIPT VERSION CHECK ***
var is_js;
if (is_nav2 || is_ie3) is_js = 1.0;
else if (is_nav3) is_js = 1.1;
else if (is_opera5up) is_js = 1.3;
else if (is_opera) is_js = 1.1;
else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
else if (is_hotjava3up) is_js = 1.4;
else if (is_nav6 || is_gecko) is_js = 1.5;
// NOTE: In the future, update this code when newer versions of JS
// are released. For now, we try to provide some upward compatibility
// so that future versions of Nav and IE will show they are at
// *least* JS 1.x capable. Always check for JS version compatibility
// with > or >=.
else if (is_nav6up) is_js = 1.5;
// NOTE: ie5up on mac is 1.4
else if (is_ie5up) is_js = 1.3
// HACK: no idea for other browsers; always check for JS version with > or >=
else is_js = 0.0;

// end of browser detection

function MyGetElementById(id)
{
	return document.all[id];
}
if (document.getElementById == null)
	document.getElementById = MyGetElementById;

function OpenBlock(name)
{
	var el = document.getElementById(name);

	if (el._state == "hide") {
		el._state = "show";
		el.style.display = "block";
	} else {
		el._state = "hide";
		el.style.display = "none";
	}
}

function GetCookie(name)
{
	var nm = name + "=";
	var beg = document.cookie.indexOf(nm);
	if (beg == -1)
		return null;
	
	beg = beg + nm.length;
	
	var end = document.cookie.indexOf(";", beg);
	if (end == -1)
		end = document.cookie.length;
	
	return unescape(document.cookie.substring(beg,end))
}

function SetCookie(name,value)
{
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path    = (argc > 3) ? argv[3] : null;  
	var domain  = (argc > 4) ? argv[4] : null;  
	var secure  = (argc > 5) ? argv[5] : false;  

	if (expires == null)
	{	
		expires = new Date();
		expires.setFullYear(2020,1,1);
		expires.setHours(0,0,0,0);
	}

	if (path == null)
	{	
		path = "/";
	}

	document.cookie = 
		name + "=" + escape (value) + 
		((expires == null)? "" : ("; expires=" + expires.toGMTString())) + 
		((path    == null)? "" : ("; path="    + path)) +  
		((domain  == null)? "" : ("; domain="  + domain)) +    
		((secure  == true)? "; secure" : "");
}

function DeleteCookie(name)
{
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);   
	var cval = GetCookie(name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function GetOptions()
{
	var opt = GetCookie("opt");
	return opt == null? 0x00000001: parseInt(opt);
}

function IsOptions(opt)
{
	opt = 1 << (opt - 1);
	return (GetOptions(page) & opt) == opt;
}

function SetOption(opt,val)
{
	var gopt = GetOptions();
	opt = 1 << (opt - 1);
	opt = (gopt & ~opt) | (val?opt:0);
	SetCookie("opt",opt);
}

var indentleft=17;
var indenttop=20;
var bsh = 0;
var start='';
var pointerY=250;

var pointerup = "/img/bob-up.gif";
var bobkupimru = "/img/bob.gif";
var pointerdown = "/img/bob-down.gif";

function pilot() { 
//	if (is_ie5up) { 
//		 pt(); 
//		 window.setInterval("vbe()",10);
//	} 
}

function vbe() { document.all.bob.style.visibility="visible"; }

function pt() 
{	
	var d; 
	var db = document.body;	
	
	bsh = document.body.scrollHeight;	
	d = bob.style;
	
	dt=db.scrollTop+(db.clientHeight/2)-indenttop;
	if (dt!=pointerY) 
	{
 		pointerY += Math.round((dt-pointerY)/10);
 		d.pixelTop = pointerY;
	}
			
	dl=db.clientWidth + db.scrollLeft-indentleft;		
	
	if (dl>761) { d.pixelLeft = dl; }
	else d.pixelLeft = 761;

	setTimeout("pt()",10);
}

if (is_ie5up)
{
	start='<span id="bob" style="Position:absolute; Top:0; Left:0; Z-Index:10; VISIBILITY:hidden"><table cellpadding="0" cellspacing="0" width="11" border="0"><tr><td><a href="javascript:goUp()"><img src="' + pointerup + '" width="11" height="6" border="0" alt="Вверх"></a></td></tr><tr><td><img src="' + bobkupimru + '" width="11" height="6" border="0" alt="kupim.ru"></td></tr><tr><td><a href="javascript:goDown()"><img src="' + pointerdown + '" width="11" height="6" border="0" alt="Вниз"></a></td></tr></table></span>';
	document.write(start);
}

function goUp() {window.scrollTo(0,0);}
function goDown() {window.scrollTo(0,bsh);}
function cityother(form, obj) {	
	var d = form.location_other;
	var vc = obj.value;	
	if (vc == 0) {
		d.style.display="";
		d.value="Введите Ваш город";
	}
	else d.style.display="none";
}

function checkParent(src, dest)
{
	if (is_ie5up || is_opera7)
		prnt = 'parentElement';
	else
		prnt = 'parentNode';
		
	while (src != null) {
		if (src.tagName == dest)
			return src;
		src = eval("src." + prnt);
	}
	return null;
}
	
//function toggle(e, node, anchor,gid)
function toggle(e, node, anchor)
{
//	if (is_ie || is_opera7) {
//		src = 'srcElement';
//		chld = 'children';
//	}
//	else {
//		src = 'target';
//		chld = 'childNodes';
//	}

//	op = eval("e."+src);
					
//	var el = checkParent(op,"A");
//	if (null != el) {					
//		for (var pos=0; pos < eval("el." + chld + ".length"); pos++) {						
//			if (eval("el." + chld + "[pos].tagName") == "UL")
//				break;
//		}
//
//		if (pos == eval("el." + chld + ".length"))
//			return;
//	}
//	else
//		return;		

//	el = eval("el." + chld + "[pos]");
//	if (el.tagName == "UL") {
		var ul = document.getElementById("ul"+node);
		var img = document.getElementById("img"+node);
		var div1 = document.getElementById("lotCnt"+node);
		var div2 = document.getElementById("ofrCnt"+node);
		

		if (null != ul) {
			str = ''+img.src;
			ul.className = ul.className == "expanded" ? "" : "expanded";
			if (ul.className == "expanded") 
				img.src = str.substr(0, str.length-5)+"o.gif";
			else {
				img.src = str.substr(0, str.length-5)+"c.gif";
				if (anchor != null) anchor.href="javascript:;";
			}

			if (null != div1 && null != div2) {
				div1.style.display = ul.className == "expanded" ? "" : "none";
				div2.style.display = ul.className == "expanded" ? "" : "none";
			}

			if (ul.innerHTML == "") 
				ul.innerHTML = "<div class=loadMsg>&nbsp;Загрузка,&nbsp;пожалуйста,&nbsp;подождите...&nbsp;</div>";
			
				
			if (anchor != null && "object" == typeof(anchor) && top.length > 0) 			
				
				//anchor.target = 'dummyFrame'+gid;
				anchor.target = 'dummyFrame';
		}

	e.cancelBubble = true;
}


function toggle_ad(e, node, anchor)
{

		var ul = document.getElementById("ul"+node);
		var img = document.getElementById("img"+node);
		var div1 = document.getElementById("adCnt"+node);

		

		if (null != ul) {
			str = ''+img.src;
			ul.className = ul.className == "expanded" ? "" : "expanded";
			if (ul.className == "expanded") 
				img.src = str.substr(0, str.length-5)+"o.gif";
			else {
				img.src = str.substr(0, str.length-5)+"c.gif";
				if (anchor != null) anchor.href="javascript:;";
			}

			if (null != div1) {
				div1.style.display = ul.className == "expanded" ? "" : "none";				
			}

			if (ul.innerHTML == "") 
				ul.innerHTML = "<div class=loadMsg>&nbsp;Загрузка,&nbsp;пожалуйста,&nbsp;подождите...&nbsp;</div>";
			
				
			if (anchor != null && "object" == typeof(anchor) && top.length > 0) 							

				anchor.target = 'dummyFrame';
		}

	e.cancelBubble = true;
}

function isEmpty(str)
{
	for (var i=0; i < str.length; i++)
		if (" " != str.charAt(i))
			return false;
 
	return true;
}

function checkForm(frm)
{	
	var strError = "";
	for (var i = 0; i < frm.elements.length; i++) 
		if (null != frm.elements[i].getAttribute("required"))
			if (isEmpty(frm.elements[i].value)) 
				strError += " " + frm.elements[i].getAttribute("displayed") + "\n";
	
	if ("" != strError) {
		alert("Не были заполнены следующие поля:\n\n" + strError);
		return false;
	}

	return true;
}


function checkShow(act)
{	
	var strError = "";
	for (var i = 0; i < document.Mainfrm.elements.length; i++) 
		if (null != frm.elements[i].getAttribute("required"))
			if (isEmpty(frm.elements[i].value)) 
				strError += " " + frm.elements[i].getAttribute("displayed") + "\n";
	
	if ("" != strError) {
		alert("Не были заполнены следующие поля:\n\n" + strError);
		return false;
	}
	
	document.Mainfrm.action=act;
  	document.Mainfrm.submit();
	return true;
}

function mysubmit (act)
{
  document.formad.action=act;
  document.formad.submit();

}
function SubmitFormEdit()
{
document.formad.action = document.formad.act.value;
alert(act.value);
document.formad.submit();
}
function checkEssential(frm)
{	
	if (!checkPassword(frm))
		return false;


	if (!checkEmail(frm))
		return false;

	return true;
}

function checkLogin(obj)
{	
	// No pasaran!!!
	if ("" != obj.value) {
		if (4 > obj.value.length) {
			alert('Недопустимая длина e-mail');
			obj.focus();
			obj.select();
			return false;
		}

//		re = /\s+/g;
//		if (obj.value.match(re)) {
//			alert('E-mail cодержит пробелы');
//			obj.focus();
//			obj.select();
//			return false;
//		}
	
//		if (!isNaN(obj.value.charAt(0))) {
//			alert('E-mail начинается с цифры');
//			obj.focus();
//			obj.select();
//			return false;
//		}

		re = /[a-zA-Z0-9]/;
		ch = obj.value.charAt(obj.value.length-1);		
		if (!ch.match(re)) {
			alert('E-mail оканчивается недопустимым символом');
			obj.focus();
			obj.select();
			return false;
		}
		
//		re = /[а-яА-Я]/;
//		if (obj.value.match(re)) {
//			alert('E-mail содержит русские буквы');
//			obj.focus();
//			obj.select();
//			return false;
//		}
	}

	return true;
}

function checkPassword(frm)
{
	if (frm.elements['password'].value.length < 6) {
		alert('Недопустимая длина пароля');
		frm.elements['password'].focus();
		frm.elements['password'].select();
		return false;
	}

	if (frm.elements['password'].value != frm.elements['confirm_password'].value) {
		alert('Введенные пароль и его подтверждение не идентичны.\nПовторите ввод.')
		return false;
	}

	return true;
}

function checkEmail(frm)
{
	pattern = /^[0-9a-zA-Z]+[\.\da-zA-Z0-9_-]*\@[\da-zA-Z-]+[\.\da-zA-Z-]*\.[a-zA-Z]{2,4}$/;
	if (frm.login.value.match(pattern))
		return true;
	
	alert('Неверный e-mail');
	return false;
}

function checkID(frm)
{
	pattern = /[1-9]+[0-9]*/;
	if (frm.id.value.match(pattern))
		return true;
	
	alert('Неверный формат id');
	return false;
}


// Показать/скрыть одно предложение
function showOffer(e, anchor,lotof)
{		
	var IDon = new Array();
	var IDoff= new Array();	
		
	re1 = /^\d+/;
	re2 = /\d+$/;
		
	idlot = lotof.match(re1);
	idof = lotof.match(re2);
	


	checkbox = document.getElementById(idlot + 'cb' + idof);
	anchor.innerHTML = (anchor.innerHTML == 'показать') ? 'скрыть' : 'показать';
	checkbox.checked = (anchor.innerHTML == 'показать') ? 0 : 1;
	IDon.push(idof);
	ShowOffersInfo(IDon,IDoff,idlot);	
	e.cancelBubble = true;
}

// Показать/скрыть выбранные предложения
function ShowSelected(idlot)
{
	var anc_id,anc_idlot,anc_idof;
	var IDon = new Array();
	var IDoff= new Array();	
	re1 = /^\d+/;
	re2 = /\d+$/;
		
	//просмотр всех ссылок
	var numRefs = document.anchors.length;

	var j = 0;
	var k = 0;
	for (var i=0; i < numRefs; i++ ) {
		
		anc_id = document.anchors(i).id;//490
		anc_idlot = parseInt(anc_id.match(re1));
		anc_idof = parseInt(anc_id.match(re2));
		
		//если ссылка нужная, пометить checkbox
				
		if (anc_idlot==idlot){				
		
			checkbox = document.getElementById(anc_idlot + 'cb' + anc_idof);		
			if (checkbox.checked){			
			IDon.push(anc_idof);					
		}else{			
			IDoff.push(anc_idof);		
		}
		
		
		}
	}	

	ShowOffersInfo(IDon,IDoff,idlot);
}


// Показать/скрыть все предложения
function ShowAll(idlot)
{
	var anc_id,anc_idlot,anc_idof;
	var IDon = new Array();
	var IDoff= new Array();	
	re1 = /^\d+/;
	re2 = /\d+$/;
		
	//просмотр всех ссылок
	var numRefs = document.anchors.length;

	var j = 0;
	var k = 0;
	for (var i=0; i < numRefs; i++ ) {
		
		anc_id = document.anchors(i).id;//
		anc_idlot = parseInt(anc_id.match(re1));
		anc_idof = parseInt(anc_id.match(re2));
		
		//если ссылка нужная, пометить checkbox
				
		if (anc_idlot==idlot){				
		
			checkbox = document.getElementById(anc_idlot + 'cb' + anc_idof);		
			checkbox.checked = 1;
			IDon.push(anc_idof);		
		}
	}	

	ShowOffersInfo(IDon,IDoff,idlot);
}

// Отобразить/скрыть строки предложений.
function ShowOffersInfo(IDon,IDoff,idlot)
{

	for (i = 0; i < IDoff.length; i++) {
		var tr = document.getElementById(idlot+'offerInfo'+IDoff[i]);
		tr.style.display = 'none';
		
		var tr = document.getElementById(idlot+'ofbrief'+IDoff[i]);
		tr.style.display = '';
		
	}

	for (i = 0; i < IDon.length; i++) {			
		var tr = document.getElementById(idlot+'offerInfo'+IDon[i]);
		tr.style.display = '';		
		
		var tr = document.getElementById(idlot+'ofbrief'+IDon[i]);
		tr.style.display = 'none';
	}	
}

function ShowLayer(lyr,mode)
{		
	var frm = top.document.getElementsByName(lyr).item(0);
	if (null != frm)
		if (mode == 'on') {
			frm.style.display = 'block';
			var w = eval("top."+lyr);
			w.focus();
			frm.focus();
		}
		else
		 	frm.style.display  = 'none';
}

function DeleteItems(form, bDelAll)
{		
	
	if (bDelAll) {
		for (i=0; i < form.elements.length; i++) 
			if ('checkbox' == form.elements[i].type) 
				form.elements[i].checked = 1;
	}
	else {
		var HasChecked = false;
 		for (i = 0; i < form.elements.length; i++) {
			if (form.elements[i].checked) {
				HasChecked = true;
				break;
			}
		}
		if (!HasChecked) return false;
	}	

	return confirm('Вы действительно хотите удалить выбранные позиции?');
}

	function chkform()
	{

		var email = document.sendform.sender_address.value;
		if ( (email.length < 6) || (email.indexOf('@') < 1) || (email.indexOf('.') == -1 ) )
		{
			alert("<?php echo $_enter_email ?>");
			document.sendform.sender_address.focus();
			return false;
		}
	return true;
	}
	
	function help_window(url,s_width,s_height) {
		window.open(url,"photo","width="+s_width,height="+s_height,scrollbars=yes,resizable=yes");
	}

