function show_full(){
	var full=document.getElementById('full_text');
	var short=document.getElementById('short_text');
	if(full && short){
		var text=full.innerHTML;
		short.innerHTML=text;
	}
}

function open_wind(link,w,h,imia) {
	var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=no,scrollbars=no";
	newWin = window.open(link,imia,win);
	newWin.focus();
}

function open_wind2(link,w,h,imia) {
	var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=no,scrollbars=yes";
	newWin = window.open(link,imia,win);
	newWin.focus();
}


//Login
function browseIt(){
	this.ver = navigator.appVersion.toLowerCase();
	this.verNum = parseInt(this.ver);
	this.agent = navigator.userAgent.toLowerCase();
	this.dom = (document.getElementById ? 1 : 0);
	this.opera = (this.agent.indexOf("opera") > -1 && this.dom ? 1 : 0);
	this.opera7 = (this.opera && this.verNum >= 7);
	this.ie = (this.ver.indexOf("msie") > -1 && this.dom && !this.opera ? 1 : 0);
	this.ieVer = 0;
	if (this.ie) {
		var pos = this.ver.indexOf("msie");
		if (pos != -1)
			this.ieVer = parseInt(this.ver.substr(pos + 5));
	}
	this.ie6 = (this.ie && this.ieVer >= 6);
	this.macOS = (this.agent.indexOf("mac") > -1);
	this.mac = (this.macOS && this.verNum >= 7 ? 1 : 0);
	this.moz = (this.agent.indexOf("gecko") > -1);
	this.ns6 = (this.dom && this.agent.indexOf("netscape") > -1 && this.verNum >= 5 ? 1 : 0);
	this.ff = (this.agent.indexOf("firefox") > -1);
	this.b = (this.ie || this.ns6 || this.opera7 || this.mac || this.moz || this.dom);
	return this;
}
function makeObj(obj){
	this.elem = document.getElementById(obj);
   	this.css = this.elem ? this.elem.style : null;
	return this;
}

//Прятать лишнее под слоями
function toggleDisplay(tag, value, cont)
{
	if (!cont)
		cont = document;
	var sel = document.getElementsByTagName(tag);
	for (var i = 0; i < sel.length; i++)
		sel[i].style.visibility = value;
}

var px = window.opera ? "" : "px";
var b = new browseIt();

function makeloginform(){
	var el = new makeObj('loginForm');
	if (!el.elem){
		return;
	};
	el.elem.innerHTML = '<form onsubmit="return fastcheck()" method="POST" name="login" action="/login.html"><table style="FILTER:progid:DXImageTransform.Microsoft.Shadow(direction=135,color=#666666,strength=4)" class=login cellspacing=0 cellpadding=3 style="filter:revealTrans(Duration=1, Transition=5); " id="samaforma" width=220 bgcolor=#CCCCCC><tr><td bgcolor=#990000 style="color:#FFFFFF"><img onclick="showloginform(1)" src=http://i.smartphone.ua/images/close_.gif align=right style="cursor:pointer">&nbsp;<strong>Вход на сайт</strong></td></tr><tr><td height=100% valign=top style="padding: 15px 15px 0px  15px"><strong>Ваш e-mail:</strong><br><input type=text class=inp id=login_email name=login_email style="width:188px"><br><br><strong>Пароль:</strong><br><input name=login_pass id=login_pass class=inp type=password style="width:188px"><br><input id=login_week type=checkbox name=login_week checked value=1> &nbsp;<label for=login_week>запомнить меня на неделю</td></tr><tr><td valign=top style="padding: 0px 15px 5px 15px"><div class=errspan id=login_error></div></td></tr><tr><td valign=top style="padding: 5px 15px 15px  15px"><p><input onclick="return fastcheck()" type=submit value="Вход" style="width:88px" class=button>&nbsp;&nbsp;&nbsp;<input type=button value="Отмена" style="width:88px" onclick="showloginform(1)" class=button></p><a href=http://www.smartphone.ua/lostpass.html>Забыл пароль?</a> &nbsp;|&nbsp; <a href=http://www.smartphone.ua/register.html>Регистрация</a></td></tr></table></form>';
	
}

function showloginform(act){
	var oTmp = new makeObj("loginForm");
	var m = document.getElementById('FloatMaskLogin');

	if (!oTmp.elem){
		return true;
	}
	
		
	var oTmpW = 300;
	var sW = (!b.ie) ? self.innerWidth : self.document.body.offsetWidth;
	oTmp.css.width = oTmpW + px;
	oTmp.css.left = (sW - oTmpW)/2 + px;
	oTmp.css.top = document.body.scrollTop +200;
	if (act) {
		oTmp.css.display = 'none';
		m.style.display = 'none';
		
		toggleDisplay('SELECT', 'visible');
		toggleDisplay('OBJECT', 'visible');
		toggleDisplay('EMBED', 'visible');
		toggleDisplay('IFRAME', 'visible');
	} else {
		if(b.ns6 && !b.opera){
			return true;
		}
		
		toggleDisplay('SELECT', 'hidden');
		toggleDisplay('OBJECT', 'hidden');
		toggleDisplay('EMBED', 'hidden');
		toggleDisplay('IFRAME', 'hidden');
		

		m.style.display = 'block';
		if (b.opera)
			m.style.background = 'none';
		var bHeight = self.document.body.offsetHeight;
		m.style.height = bHeight + 'px';


		oTmp.css.display = 'block';
	}
	return false;
}
function fastcheck(){
	var email=document.getElementById('login_email').value;
	var pass=document.getElementById('login_pass').value;
	if(email=='' || pass=='' || !validemail(email) || !validpass(pass)){
		show_error('Введите e-mail и пароль','login_error');
		return false
	}else{	
		var url='/flogin.php?email='+encodeURIComponent(email)+'&pass='+encodeURIComponent(pass)+'&r='+Math.round((Math.random()*10000000));
		var answer=serverGetRequest(url);
		if(answer){
				show_error(answer,'login_error');
				return false;
		}else{
			show_error('','login_error');
			return true;	
		}
		return true;
	}
}
function fastcheck2(){
	var email=document.getElementById('login_email2').value;
	var pass=document.getElementById('login_pass2').value;
	if(email=='' || pass=='' || !validemail(email) || !validpass(pass)){
		show_error('Введите e-mail и пароль','login_error2');
		return false
	}else{	
		//var url='flogin.php?email='+encodeURIComponent(email)+'&pass='+encodeURIComponent(pass)+'&r='+Math.round((Math.random()*10000000));
		//var answer=serverGetRequest(url);
		//if(answer){
		//		show_error(answer,'login_error2');
		//		return false;
		//}else{
		//	show_error('','login_error2');
		//	return true;	
		//}
		return true;
	}
}
function show_error(text,place){
	var err_place=document.getElementById(place);
	if(err_place){
		if(text){
			err_place.innerHTML='<div>'+text+'</div>';
			err_place.style.display='block';
		}else{
			err_place.innerHTML='';
			err_place.style.display='none';
		}
	}
}


//АЯКС
function createRequestObject() {
	var xmlhttpindex = null;
	if (window.XMLHttpRequest) {
		xmlhttpindex = new XMLHttpRequest();
	}else if (window.ActiveXObject) {// ??? IE: 
		xmlhttpindex = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		xmlhttpindex = null;
	}
	return xmlhttpindex;
}
var answer='';
function serverGetRequest(url) {
    var request = createRequestObject();
    if(!request) return false;
	request.open("GET",url,false);
	request.send(null);
	answer=request.responseText;
    return answer;	
}

//Проверка имейла
function validemail(email){
	emailTest = "^[_\\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z_-]*\\.)+[a-zA-Z]{2,4}$"; 
	var regex = new RegExp(emailTest); 
	if (!regex.test(email) || !(email.length > 0)) {
		return false;
	}else{
		return true;	
	}
}
function validpass(pass){
	passTest = "^[0-9a-zA-Z]+$"; 
	var regex = new RegExp(passTest); 
	if (!regex.test(pass) || !(pass.length > 0)) {
		return false;
	}else{
		return true;	
	}
}
function validicq(icq){
	icqTest = "^[0-9]{4,10}$"; 
	var regex = new RegExp(icqTest); 
	if (!regex.test(icq) || !(icq.length > 0)) {
		return false;
	}else{
		return true;	
	}
}

function choose_phone(action){
	var div=document.getElementById('your_phone');
	if(action==1){
		div.innerHTML='<p align=center>загрузка ...</p>';
		var url='/your_phone.php?r='+Math.round((Math.random()*10000000));
		var recieve=serverGetRequest(url);
		if(recieve){
			div.innerHTML=recieve;
			return false;
		}else{
			return true;
		}
	}else if(action==2){
		var yourphoneid=document.getElementById('yourphoneid').value;
		if(yourphoneid>0){
			var choose_phone_button=document.getElementById('choose_phone_button');
			choose_phone_button.style.disabled='true';
			div.innerHTML='<p align=center>загрузка ...</p>';
			var url='/your_phone.php?phone='+yourphoneid+'&r='+Math.round((Math.random()*10000000));
			var recieve=serverGetRequest(url);
			if(recieve){
				div.innerHTML=recieve;
				choose_phone_button.style.disabled='false';
				return false;
			}else{
				window.location.href='http://www.smartphone.ua/catalog.html';
			}
		}else{
			alert('Выберите модель смартфона');	
			return false;
		}
	}
	
}
//Функция голоса
function rate_it(mark,id,table){
	var url='/include/rating2.php?mark='+mark+'&table='+table+'&id='+id+'&r='+Math.round((Math.random()*10000000));
	var recieve=serverGetRequest(url);
	if(!recieve){
		 show_error('К сожалению, Ваш бразуер не поддерживает технологию Ajax. Рекомендуем обновить версию','rating_error'+id)
	}else if(recieve=='ok'){ 
		 show_error('Спасибо, Ваша оценка учтена. Она поможет другим сделать правильный выбор!','rating_good'+id)
		 show_error('','rating_error'+id)
	}else if(recieve=='notok'){ 
		show_error('Извините, но Вы уже оценивали этот обьект','rating_error'+id)
		show_error('','rating_good'+id)
	}else if(parseInt(recieve)>0 && parseInt(recieve)<6){ 
		 show_error('Спасибо, Ваша оценка учтена. Она поможет другим сделать правильный выбор!','rating_good'+id)
		 show_error('','rating_error'+id);
		 var ratingimg=document.getElementById('ratingimg'+id);
		  if(ratingimg){
			 ratingimg.src='/images/rate_'+parseInt(recieve)+'.gif';
		  }
	}else{
		show_error(recieve,'rating_error'+id)
		show_error('','rating_good'+id)
	}
	
}


function show_hide(layer,value){
	blok=document.getElementById(layer);
	if(blok){
		if(blok.style.display == 'none' || value=='inline'){
			blok.style.display = 'inline';
		}else{
			blok.style.display = 'none';
		}
	}
}

function change_code(code_img,code_value,code_time,bg){
	var code_img=document.getElementById(code_img);
	var code_value=document.getElementById(code_value);
	var code_time=document.getElementById(code_time);
	if(code_img && code_time){
		var nowtime=new Date();
		nowtime=nowtime.getTime();
		nowtime=Math.floor(nowtime/1000);
		code_img.src='/code.php?time='+nowtime+'&r='+Math.round((Math.random()*10000000))+'&bg='+bg;
		code_time.value=nowtime;
		code_value.value='';
		//alert(3131);
	}
}
function validurl(url){
	emailTest = "^http://(.+)$"; 
	var regex = new RegExp(emailTest); 
	if (!regex.test(url) || !(url.length > 10) || !(url.indexOf(".")>-1)) {
		return false;
	}else{
		return true;	
	}
}

function inputLimit(input, maxlen, left)
{
	inputstr = input.value;
	strlen = inputstr.length;
	if (strlen > maxlen)
		input.value = inputstr.substring(0, maxlen);
	if (left)
		left = document.getElementById(left);
	if (left) {
		if (left.tagName == 'INPUT')
			left.value = maxlen - input.value.length;
		else
			left.innerHTML = maxlen - input.value.length;
	}
	return true;
}
function mnuover(td){
	td.style.backgroundImage='url(http://i.smartphone.ua/images/mnubg.jpg)';
}
function mnuout(td){
	td.style.backgroundImage='';
}

//Кукис
function createCookie(name,value,days,domain) {
  if(days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }else{
	var expires = "";
  }
  if(domain=='all' && all_domain){
	var dom = "; domain="+all_domain; 
  }else{
	var dom="";	  
  }
  document.cookie = name+"="+value+expires+dom+"; path=/";
 // alert(name+"="+value+expires+"; path=/"+dom);
}
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}




function next_forum(id){
	var url='/include/forum_list.php?id=' + id ;
	var recieve=serverGetRequest(url);
	if(!recieve){
		 return true;
	}else if(recieve=='1'){ 
		 return true;
	}else if(recieve=='2'){ 
		 alert('Ошибка');
		 return false;
	}else{ 
		var place=document.getElementById('h_r_forum_tb');
		if(place){
			place.innerHTML=recieve;
			return false;
		}else{
			return true;
		}
		
	}
		
}
function next_soft(){
	var url='/include/soft_list.php?r='+Math.round((Math.random()*10000000));
	var recieve=serverGetRequest(url);
	if(!recieve){
		 return true;
	}else if(recieve=='1'){ 
		 return true;
	}else if(recieve=='2'){ 
		 alert('Ошибка');
		 return false;
	}else{ 
		var place=document.getElementById('h_r_soft_tb');
		if(place){
			place.innerHTML=recieve;
			return false;
		}else{
			return true;
		}
		
	}
		
}
function showpic(picurl,w,h,act){
	var m = document.getElementById('FloatMaskLogin')
	var l = document.getElementById('fotodiv')
	if(!act){
		var fotohtml='<table style="FILTER:progid:DXImageTransform.Microsoft.Shadow(direction=135,color=#666666,strength=4)" class=login cellspacing=0 cellpadding=3 style="filter:revealTrans(Duration=1, Transition=5); " bgcolor=#CCCCCC><tr><td bgcolor=#990000 style="color:#FFFFFF"><img onclick="showpic(\'\',\'\',\'\',1)" src=http://i.smartphone.ua/images/close_.gif align=right style="cursor:pointer">&nbsp;<strong>Просмотр фотографии</strong></td></tr><tr><td valign="top" style="padding:0px;"><a href="#" onclick="showpic(\'\',\'\',\'\',1); return false;"><img id=showfotoobj src='+picurl+' width='+w+' height='+h+' border=0></td></tr></table>';
		l.innerHTML=fotohtml;
		l.css = l ? l.style : null;
		if (!l){
			return true;
		}
		var lW = w;
		var lH = h;
		var sW = (!b.ie) ? self.innerWidth : self.document.body.offsetWidth;
		var sH = (!b.ie) ? self.innerHeight : self.document.body.offsetHeight;
		l.style.width = lW + px;
		l.style.left = (document.body.scrollLeft + (sW - lW)/2) + px;
		l.style.top = (document.body.scrollTop + (sH - lH-25)/2) + px;
	}
	
	if (act) {
		l.style.display = 'none';
		m.style.display = 'none';		
		toggleDisplay('SELECT', 'visible');
		toggleDisplay('OBJECT', 'visible');
		toggleDisplay('EMBED', 'visible');
		toggleDisplay('IFRAME', 'visible');
	} else {
		if(b.ns6 && !b.opera){
			return true;
		}
		toggleDisplay('SELECT', 'hidden');
		toggleDisplay('OBJECT', 'hidden');
		toggleDisplay('EMBED', 'hidden');
		toggleDisplay('IFRAME', 'hidden');
		m.style.display = 'block';
		if (b.opera)
			m.style.background = 'none';
		var bHeight = document.body.offsetHeight;
		m.style.height = document.body.scrollTop + bHeight + 'px';
		l.style.display = 'block';
	}
	return false;
}
var trs=new Array();
function color_tr(id){
	var tr=document.getElementById(id);
	//alert(trs[id])
	if(trs[id]=='#FFE8E8'){
		//alert(2323)
	}else if(trs[id]=='#EFEFEF'){
		tr.style.backgroundColor='#FFFFFF'
		trs[id]='#FFFFFF';
	}else{
		tr.style.backgroundColor='#EFEFEF'
		trs[id]='#EFEFEF';
	}
}
function mark_tr(id){
	var tr=document.getElementById(id);
	if(trs[id]=='#FFE8E8'){
		tr.style.backgroundColor='#EFEFEF';
		trs[id]='#EFEFEF';
	}else{
		tr.style.backgroundColor='#FFE8E8';
		trs[id]='#FFE8E8';
	}
}
function clickprice(url){
	window.open('http://'+url);
}