			document.write("<style type='text/css'>.hidden{display:none;}<\/style>");
$(document).ready(
	function()
		{
		
			boxChain = function() {
				$("a[href='/auth']").colorbox({inline:true, href:"#inline_msg"});
//				$("a[href='/companies/0/add']").colorbox({inline:true, href:"#inline_msg"});			
				$("a[href='/registration']").colorbox({href:"/register.php"});			
				$("#doLogin").colorbox({inline:true, href:"#inline_msg"});
				$("#doReg").colorbox();
				$("#loginForget").colorbox({href:"/forget.php"});
				$("#rules").colorbox({fixedWidth:980});
				$("#rules1").colorbox({fixedWidth:980});








 
$("#forgetForm").submit(function() {			 				 
    var id = id;
    var req = new JsHttpRequest	();
    req.onreadystatechange = function() {
	if (req.readyState == 4)
	{
		document.getElementById("forgetMessage").innerHTML="&nbsp;";		
		if(req.responseJS.signature=="otvet")
		{
			if(req.responseJS.ok==1)
			{
				document.getElementById("modalLoadedContent").innerHTML="<h1>&nbsp;</h1><h2>"+req.responseJS.msg+"</h2><p>&nbsp;</p><a href='#' onclick='$(\"#modalClose\").click()'>Закрыть это окно</a>";
			}else document.getElementById("forgetMessage").innerHTML=req.responseJS.msg;
		}else
		{
			document.getElementById("forgetMessage").innerHTML="Ошибка. Попробуйте еще раз, или используйте <a href='/auth/forget/'>эту форму</a>";
		}
	}
    }
    document.getElementById("forgetMessage").innerHTML="Подождите...";
    req.open(null, '/inc/auth.forget.ajax.php', true);
    req.send({email:$('#email').val(),rand:Math.random()});				 				
    return false;
});

$("#registrationForm").submit(function() {			 				 
    var id = id;
    var req = new JsHttpRequest	();
    req.onreadystatechange = function() {
	if (req.readyState == 4)
	{
		document.getElementById("registrationMessage").innerHTML="&nbsp;";		
		if(req.responseJS.signature=="otvet")
		{
			if(req.responseJS.ok==1)
			{
				document.getElementById("modalLoadedContent").innerHTML="<h1>&nbsp;</h1><h2>"+req.responseJS.msg+"</h2><p>&nbsp;</p><a href='#' onclick='$(\"#modalClose\").click()'>Закрыть это окно</a>";
			}else document.getElementById("registrationMessage").innerHTML=req.responseJS.msg;
		}else
		{
			document.getElementById("registrationMessage").innerHTML="Произошла ошибка. Попробуйте еще раз, или используйте <a href='/auth/registration/'>эту форму</a>";
		}
	}
    }
    document.getElementById("registrationMessage").innerHTML="Подождите...";
    req.open(null, '/inc/registration.ajax.php', true);
    req.send({email:$('#reg_email1').val(),password:$('#reg_pw1').val(),rand:Math.random()});				 				
    return false;
});










			}
		
			boxChain();
			
$("#loginForm").submit(function() {			 				 
    var id = id;
    var req = new JsHttpRequest	();
    req.onreadystatechange = function()
    {
	if (req.readyState == 4)
	{
		document.getElementById("loginMessage").innerHTML="&nbsp;";		
		if(req.responseJS.signature=="otvet")
		{
			//alert(req.responseJS.msg);
			document.getElementById("loginMessage").innerHTML=req.responseJS.msg;
			if(req.responseJS.url)
			{
				document.getElementById("modalLoadedContent").innerHTML="<h1>&nbsp;</h1><h2>"+req.responseJS.msg+"</h2>";
				top.location=req.responseJS.url;
			}
		}else
		{
			document.getElementById("loginMessage").innerHTML="Произошла ошибка. Попробуйте еще раз, или используйте <a href='/auth/'>старый вход</a>";
		}
	}
    }
    

    document.getElementById("loginMessage").innerHTML="Подождите...";
    req.open(null, '/inc/auth.ajax.php', true);
    req.send({login:$('#login').val(),password:$('#password').val(),tryToGo:$('#tryToGo').val(),back_url:$('#back_url').val(),rand:Math.random()});				 				
    return false;
});



			$("div.frameWhiteGray").wrap("<div class='frameWhiteGrayWrap'></div>");
			$("div.frameGreenGreen").wrap("<div class='frameGreenGreenWrap'></div>");
			$("div.frameWhiteGray2").wrap("<div class='frameWhiteGray2Wrap'></div>");
			$("div.registration .ok input:checkbox").addClass("checkbox");
			$("div.registration .ok input:button").addClass("button");
			$("div.userLogin .ok input:button").addClass("button");
			$("div.passRecover .inputs input:text").addClass("i");
			$("div.passRecover .inputs input:button").addClass("b");
			$("div.innerHeader .wayFinder .search input:text").addClass("i");
			$("div.innerHeader .wayFinder .search input:button").addClass("b");
			$("a.buttAdd").wrap("<div class='buttAddWrap'></div>");
			$("div.sectionChoicer .leftCol .sections").append("<div class='clearBoth'><!-- --></div>");
			$("div.sectionChoicer .leftCol .sections li strong").wrap("<b></b>");
			$("div.companyList .item682").wrap("<div class='item682Wrapper'></div>");
			$("div.companyList .item682").append("<div class='item682BottArr'><!-- --></div>");
			$("div.sectionChoicer .withIcFolder").append("<div class='icFolder'><!-- --></div>");
			$("div.liquidGrayFrame").wrap("<div class='liquidGrayFrameTL'><div class='liquidGrayFrameTR'><div class='liquidGrayFrameBR'></div></div></div>");
			$("div.liquidGreenFrame").wrap("<div class='liquidGreenFrameTL'><div class='liquidGreenFrameTR'><div class='liquidGreenFrameBR'></div></div></div>");
			$("div.searchQueryFounded .item:last").addClass("noBottSeparaor");
			$("div.announceList .jobItem:first").addClass("jobItemFirst");
			$("div.announceList .announceItem:last").addClass("announceItemLast");
			$("div.strongBlock01").append("<div class='clearBoth'><!-- --></div>");
			$("div.strongBlock01 .title h2:eq(0)").addClass("h21");
			$("div.strongBlock01 .title h2:eq(1)").addClass("h22");
			$("div.companyPage .rightCol .liquidGrayFrame").append("<div class='arr'><!-- --></div>");
			$("div.companyPage .rightCol .liquidGrayFrameTL .fotoGallery th:last").addClass("bottPad");
			$("div.companyPage .rightCol .liquidGrayFrameTL .fotoGallery td:last").addClass("bottPad");
			$("div.companyPage").append("<div class='clearBoth'><!-- --></div>");
			$("div.companyPage .leftCol .infoBlockGray .body").append("<div class='clearBoth'><!-- --></div>");
			$("div.staticPage blockquote").wrap("<div class='blockquoteTL'><div class='blockquoteTR'><div class='blockquoteBR'></div></div></div>");
			$("div.staticPage blockquote").append("<div class='blockquoteLarr'><!-- --></div>");
			$("div.staticPage blockquote").append("<div class='blockquoteRarr'><!-- --></div>");
			$("div.staticPage .tableListing td:nth-child(odd)").addClass("odd");
			$("div.staticPage .tableListing tr:last").addClass("bottPadd");
			$("div.fotoGalleryPage .innerHeader").wrap("<div class='innerHeaderWrapWrap'><div class='innerHeaderWrap'></div></div>");
			$("div.fotoReportingItem").append("<div class='fotoReportingItemBott'><!-- --></div>");
			$("div.fotoReportingItem").append("<div class='fotoReportingItemTop'><!-- --></div>");
			$("div.fotoReportingItem .picFrame").wrap("<div class='picFrameT'><div class='picFrameR'><div class='picFrameB'><div class='picFrameL'></div></div></div></div>");
			$("div.fotoReportingItem .picFrame").append("<div class='picFrameTL'><!-- --></div>");
			$("div.fotoReportingItem .picFrame").append("<div class='picFrameTR'><!-- --></div>");
			$("div.fotoReportingItem .picFrame").append("<div class='picFrameBR'><!-- --></div>");
			$("div.fotoReportingItem .picFrame").append("<div class='picFrameBL'><!-- --></div>");
		}
);


function swapSearch(){
	d = document.getElementById('srch');
	p = document.getElementById('phn');
	if(d.style.display == 'block'){
		d.style.display = 'none';
		p.style.display = 'block';
	}else{
		d.style.display = 'block';
		p.style.display = 'none';
	}
}


function select_innerHTML(objeto,innerHTML){
/******
* select_innerHTML - corrige o bug do InnerHTML em selects no IE
* Veja o problema em: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228
* Versao: 2.1 - 04/09/2007
* Autor: Micox - Nairon Jose C. Guimaraes - micoxjcg@yahoo.com.br
* @objeto(tipo HTMLobject): o select a ser alterado
* @innerHTML(tipo string): o novo valor do innerHTML
*******/
    objeto.innerHTML = ""
    var selTemp = document.createElement("micoxselect")
    var opt;
    selTemp.id="micoxselect1"
    document.body.appendChild(selTemp)
    selTemp = document.getElementById("micoxselect1")
    selTemp.style.display="none"
    if(innerHTML.indexOf("<option")<0){//se nao e option eu converto
        innerHTML = "<option>" + innerHTML + "</option>"
    }
    innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span")
    selTemp.innerHTML = innerHTML
      
    
    for(var i=0;i<selTemp.childNodes.length;i++){
  var spantemp = selTemp.childNodes[i];
  
        if(spantemp.tagName){     
            opt = document.createElement("OPTION")
    
   if(document.all){ //IE
    objeto.add(opt)
   }else{
    objeto.appendChild(opt)
   }       
    
   //getting attributes
   for(var j=0; j<spantemp.attributes.length ; j++){
    var attrName = spantemp.attributes[j].nodeName;
    var attrVal = spantemp.attributes[j].nodeValue;
    if(attrVal){
     try{
      opt.setAttribute(attrName,attrVal);
      opt.setAttributeNode(spantemp.attributes[j].cloneNode(true));
     }catch(e){}
    }
   }
   //getting styles
   if(spantemp.style){
    for(var y in spantemp.style){
     try{opt.style[y] = spantemp.style[y];}catch(e){}
    }
   }
   //value and text
   opt.value = spantemp.getAttribute("value")
   opt.text = spantemp.innerHTML
   //IE
   opt.selected = spantemp.getAttribute('selected');
   opt.className = spantemp.className;
  } 
 }    
 document.body.removeChild(selTemp)
 selTemp = null
}

function changeCat(id){
    var req = new JsHttpRequest	();
    req.onreadystatechange = function() {
	if (req.readyState == 4){
		select_innerHTML(document.getElementById("subcat"),req.responseJS.res);
        }
    }
    req.open(null, '/changecat', true);
    req.send({id: id});
}

/*function changeCat(id){
    var req = new JsHttpRequest	();
    req.onreadystatechange = function() {
	if (req.readyState == 4){
		document.getElementById('subcat').innerHTML = req.responseJS.res;
        }
    }
    req.open(null, '/changecat', true);
    req.send({id: id});
}*/

//index_news functions ////////////
function send(){
    var value = document.getElementById('idtosend').value;
    var req = new JsHttpRequest	();
    text = document.getElementById('text');
    req.onreadystatechange = function() {
	if (req.readyState == 4){
		alert("Ваше сообщение отправлено");
		document.getElementById('senddiv').style.visibility = 'hidden';
		document.getElementById('idtosend').value=0;
        }
    }
    req.open(null, '/sendletter', true);
    req.send({to: value, text: text.value, theme: 'Ответ на комментарий'});
}
function doSomething(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
}

function sendLetter(id, self){
	document.getElementById('senddiv').style.visibility = 'visible';
	var e = self;
	if (e.pageX || e.pageY) 	{
		x = e.pageX;
		y = e.pageY;
	}
	else if (e.offsetLeft || e.offsetTop) 	{
		x = e.offsetLeft + document.body.scrollLeft+ document.documentElement.scrollLeft+60;
		y = e.offsetTop + self.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
	}
	document.getElementById('senddiv').style.left = x+'px';
	document.getElementById('senddiv').style.top = y+'px';
	document.getElementById('idtosend').value=id;
}
function setCat(id, obj){

	$('#ajaxNewsAdd').attr("href","/news/"+id+"/add");
    var id = id;
    var req = new JsHttpRequest	();
    req.onreadystatechange = function() {
	if (req.readyState == 4){
		document.getElementById('new1').innerHTML = req.responseJS.new1;
		document.getElementById('new2').innerHTML = req.responseJS.new2;
		actives = inputs=document.getElementsByTagName('a');
		for(i=0;i<actives.length;i++){
			if(actives[i].className == 'active'){
				actives[i].className = '';
			}
		}
		document.getElementById(obj).className = 'active';
		document.getElementById(obj).blur();
	}
    }
    req.open(null, '/setcat', true);
    req.send({id: id});
}
////////////////////////////////////
//news functions 
function showBy(col){
	document.getElementById('by').value = col;
	document.getElementById('showby').submit();
}
/////////////////////////
//registration functions
function checkAll(){
if(document.getElementById('goreg'))
{	
	var pw1 = document.getElementById('reg_pw');
	var pw2 = document.getElementById('sec_pw');
	var email1 = document.getElementById('reg_email');
	var email2 = document.getElementById('sec_email');
	var accepted = document.getElementById('accepted');
	if((pw1.className == "yes") && (pw1.value == pw2.value) && (email1.className == "yes") &&  accepted.checked){
		document.getElementById('goreg').disabled = false;
	}else{
		document.getElementById('goreg').disabled = true;
	}
}
}
function checkEmail(el){
	var email = el.value;
	emailTest = "^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z_-]+\\.)+[a-z]{2,4}$";
	var regex = new RegExp(emailTest);
	if (!regex.test(email) || !(email.length > 0)){
		el.className = "no";
	}
	else{
		el.className = "yes";
		checkAll1();
		checkAll();
	}
}
function checkPw(el){
	var pw = el.value;
	if ((pw.length > 0)){
		el.className = "yes";
		checkAll();
		checkAll1();
	}
	else{
		el.className = "no";
	}
}
function checkSecPw(el){
	var spw = el.value;
	var fpw = document.getElementById('reg_pw').value;
	if (fpw == spw){
		el.className = "yes";
		checkAll();
		checkAll1();
	}
	else{
		el.className = "no";
	}
}

function checkSecPw1(el){
	var spw = el.value;
	var fpw = document.getElementById('reg_pw1').value;
	if (fpw == spw){
		el.className = "yes";
		checkAll();
		checkAll1();
	}
	else{
		el.className = "no";
	}
}


function checkAll1(){
	
if(document.getElementById('goreg1'))
{	
	var pw1 = document.getElementById('reg_pw1');
	var pw2 = document.getElementById('sec_pw1');
	var email1 = document.getElementById('reg_email1');
	var accepted = document.getElementById('accepted1');
	if((pw1.className == "yes") && (pw1.value == pw2.value) && (email1.className == "yes") && accepted.checked){
		document.getElementById('goreg1').disabled = false;
	}else{
		document.getElementById('goreg1').disabled = true;
	}
}
}
