/* определение браузера */
function $Browser()
{
    this.isOpera = false;
    this.isFirefox = false;
    this.isIE = false;
    this.isMozilla = false;
    this.version = '';
}
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('opera') != -1) { $Browser.isOpera = true; } 
else if (ua.indexOf('firefox') != -1) { $Browser.isFirefox = true; } 
else if (ua.indexOf('msie') != -1) { $Browser.isIE = true; } 
else if (ua.indexOf('mozilla') != -1) { $Browser.isMozilla = true; }

function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	// Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {	// all other Explorers
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight-4;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}
var highestzindex = 99;
function ShowPop(popid) {
	var pl = document.getElementById(popid);
	if(pl.offsetHeight) {
		pl.style.display = "none";
		// IE select fix
		if ($Browser.isIE){
			if(document.getElementById(popid+"_iframe")){
				document.body.removeChild(document.getElementById(popid+"_iframe"));
			}
		}
	} else {
		pl.style.display = "block";
		var pagescroll = getPageScroll();
		var pagesize = getPageSize();
		pl.style.top = Math.round(pagescroll[1]+((pagesize[3]-pl.offsetHeight)/2));
		pl.style.left = Math.round((pagesize[0]-pl.offsetWidth)/2);
		highestzindex = highestzindex+2;
		pl.style.zIndex = highestzindex;
		
		/* fix firefox absolute */
		var captiontd = pl.getElementsByTagName('TD');
		if(captiontd[0].className.indexOf('blockcaption'!=-1)){
			captiontd[0].style.width=pl.offsetWidth;
		}

		// IE select fix
		if ($Browser.isIE){
			var pl_iframe = document.createElement("iframe");
			document.body.appendChild(pl_iframe);
			pl_iframe.id = popid+"_iframe";
			pl_iframe.src="about:blank";
			pl_iframe.style.zIndex = highestzindex-1;
			pl_iframe.style.position = "absolute";
			pl_iframe.style.top = pl.style.top;
			pl_iframe.style.left = pl.style.left;
			pl_iframe.style.width = pl.offsetWidth;
			pl_iframe.style.height = pl.offsetHeight;
			pl_iframe.frameBorder = 0;
		}
	}
}

function RegistrationContinue(obj) {
//	if(document.getElementById('reg_as_user').checked) {
//		ShowPop('pop_register');
//		ShowPop('pop_register_user');
//	} else if(document.getElementById('reg_as_contractor').checked) {
	if(document.getElementById('reg_as_contractor').checked) {
		ShowPop('pop_register');
		ShowPop('pop_register_contractor');
	} else {
		document.getElementById('error_reg_user').innerHTML = "Выберите, вы&nbsp;хотите пользоваться услугами или предлагать&nbsp;их"
	}
}
function Close() {    
    var regstages = ['pop_register','pop_register_user','pop_register_contractor','pop_remind_password','pop_help'];
	for (var i=0,j = regstages.length; i<j; i++){
		var k = document.getElementById(regstages[i]);
		if (k.offsetHeight) {
			//k.style.display = "none";
			ShowPop(regstages[i]);
		}             
    }   
}

function CloseWithParam(id) {
    var k = document.getElementById(id);
    if (k.offsetHeight) {
        //k.style.display = "none";
		ShowPop(id);
    }
}

function Help(){
    ShowPop('pop_help');    
}
