// (C) Netlogic, 2003
isOpera6up = window.opera && window.print && document.getElementById ? true : false;
isOpera7up = isOpera6up && (navigator.userAgent.indexOf("Opera 7") >= 0 || navigator.userAgent.indexOf("Opera/7") >= 0) ? true : false;

var output;
if (isOpera6up) {
	output = '<LINK rel="stylesheet" href="/css/opera6.css" type="text/css">';
}

if (isOpera7up) {
	output = '<LINK rel="stylesheet" href="/css/opera7.css" type="text/css">';
}

if (output) {
	document.write(output);
}

function openW(url, w, h) {
	return Open(url, w, h);
}


function GetQueryVariable(varName, defValue) {
	var begin = location.search.indexOf(varName) + varName.length + 1;
	if (begin != 4) {
		var string = location.search.substring(begin);
		var end = string.indexOf("&");
		if (end != -2) {
			string = string.substring(0, end);
		}
		return string;
	} else {
		return defValue;
	}
}

function dataPopup(url, size) {
	w = window.open(url,'popUp','toolbar=no,status=no,location=no,menubar=no,resizable=no,scrollbars=yes,'+size);
	w.focus();
	return false;
};

function checkVacancy(form) {
	if(form.resume.value.length) {
		return true;
	}

	if(!form.fio.value.length) {
		alert('Вы не указали ФИО');
		form.fio.focus();
		return false;
	}

	if(!form.address.value.length) {
		alert('Вы не указали координаты для связи с Вами');
		form.address.focus();
		return false;
	}

	if(!form.motive.value.length) {
		alert('Вы не указали почему Вы хотите работать в МегаФон-Москва');
		form.motive.focus();
		return false;
	}

	return true;
}

function SearchTurn(input) {
	chapters = document.getElementsByName('ch[]');

	if(input.checked && input.value == 'site') {
		for(i=0; i<chapters.length; i++) {
			chapters[i].disabled = true;
		}
	} else {
		for(i=0; i<chapters.length; i++) {
			chapters[i].disabled = false;
		}
	}
}

function SelectDealersSearchCity(city) {
	if(city.options[city.selectedIndex].innerText == 'Москва') {
		city.form.metroselect.disabled    = false;
//		city.form.streetselect.disabled   = true;
//		city.form.searchinmetro.disabled  = false;
//		city.form.searchinstreet.disabled = false;

		city.form.searchinmetro.checked   = true;
	} else {
		city.form.metroselect.disabled    = true;
//		city.form.streetselect.disabled   = true;
//		city.form.searchinmetro.disabled  = true;
//		city.form.searchinstreet.disabled = true;
	}
}

OPERA = window.opera;
IE    = (document.all)             ? true : false && !OPERA;
NN    = (document.layers)          ? true : false;
MOZ   = ((document.getElementById) ? true : false ) && !IE;

var deletemenu;
var loaded=false;

timeouttime = (OPERA||NN) ? 1500 : 300;

function nomenu() { 
	if (loaded) {
		if (NN)  for (i=1; i<willbeload; i++) document.layers['menu'+i].visibility               = 'hide';
		if (IE)  for (i=1; i<willbeload; i++) document.all['menu'+i].style.visibility            = 'hidden';
		if (MOZ) for (i=1; i<willbeload; i++) document.getElementById("menu"+i).style.visibility = 'hidden';
	}
}

function deltimeout() {
	if (deletemenu) {
		clearTimeout(deletemenu);
	}
}

function deact(how) {
	if (deletemenu) {
		clearTimeout(deletemenu);
	}

	deletemenu = setTimeout('nomenu()', timeouttime);
}

function showmenu(n) {
	deltimeout();
	nomenu();

	lana='menu'+n;

	if (NN)  document.layers[lana].visibility               = 'show';
	if (IE)	 document.all[lana].style.visibility            = 'visible';
	if (MOZ) document.getElementById(lana).style.visibility = 'visible';
}

function generateItem(num) {
	if (IE || NN || MOZ) {
		itemsHere=(putMenu[num].length-5)/2;
		xPosit=putMenu[num][0];
		yPosit=putMenu[num][1];
		bgrCol=putMenu[num][2];
		borCol=putMenu[num][3];
		abgCol=putMenu[num][4];

		if (NN)        document.write('<layer name="menu'+num+'" pagex="'+xPosit+'" pagey="'+yPosit+'" visibility="hide" z-index="100">');
		if (IE || MOZ) document.write('<div id="menu'+num+'" style="position: absolute; left:'+xPosit+'px; top:'+yPosit+'px; visibility: hidden; z-index: 100;">');

		document.write('<table border="0" cellpadding="0" cellspacing="0" bgcolor="'+borCol+'"><tr><td>')
		document.write('<table border="0" cellpadding="0" cellspacing="1">');

		for (i=1; i<itemsHere+1; i++) {
			document.write('<tr>');
			document.write('	<td nowrap><a href="'+putMenu[num][(i+1)*2+2]+'" class="mmenu1" style="background-color: '+bgrCol+';" onmouseover="deltimeout(); this.style.backgroundColor=\''+abgCol+'\';" onmouseout="deact(); this.style.backgroundColor=\''+bgrCol+'\';">'+putMenu[num][(i+1)*2+1]+'</a></td>');  
			document.write('</tr>');
		}

		document.write('</table></td></tr></table>')
		if (IE || MOZ) document.write('</div>')
		if (NN) document.write('</layer>')
	}
}

function openPic(url, w, h) {
	if (w == undefined || h == undefined) {
		winprops='width=680,height=520';
	} else {
		winprops='width='+w+',height='+h;
	}

	openwinsrc = window.open('/void.html', 'winw', winprops+"resizable=no,scrollbars=no");
	openwinsrc.document.open();
	openwinsrc.document.write('<HTML><HEAD><TITLE>МегаФон</TITLE><STYLE>HTML, BODY { padding: 0; margin: 0; background-color: #FFFFFF; height: 100%;}</STYLE></HEAD><BODY><TABLE width="100%" style="height: 100%;" cellpadding="0" cellspacing="0" border="0"><TR><TD align="center"><IMG src="'+url+'" border="0"></TD></TR></TABLE></BODY></HTML>');
	openwinsrc.document.close();
	return false;
}

function HideFlags(ftype, show) {
	imgs = document.getElementsByTagName('img');
	for(i in imgs) {
		if(imgs[i].className == ftype) {
			imgs[i].style.display = show ? 'block' : 'none';
		}
	}
}

function PreviewPostcard(f) {
	f.target = '_blank';
	f.elements['action'].value = 'preview';
}

function SendPostcard(f) {
	f.target = '_top';
	f.elements['action'].value = 'save'
}