﻿function preload()
{
	var a=preload.arguments;
	for(var i in a)	(new Image).src=a[i];
}

window.onload=function(){ preload('images/logo_up.gif');};

function swap(a,b) {
	if(b){document.c=a.src; a.src=b;}
	else a.src=document.c;
}

function showToolTip(element, text)
{
	var w = jQuery(element).width();
	var h = jQuery(element).height();
	var ttH = jQuery('#tt').height();
	var offset = jQuery(element).offset();
	jQuery('#tt').attr("innerHTML", text);
	jQuery('#tt').css('top', (offset.top-(ttH-h)/2+3)+'px');
	jQuery('#tt').css('left', (offset.left+w+20)+'px');
	jQuery('#tt').show('fast');	
}

function hideToolTip()
{
	jQuery('#tt').hide();
}


function validate(form) {
 
  var name = form.name.value;
  var email = form.email.value;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var passRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);

  if(name == "") {
    inlineMsg('name','Въведете Вашето име',2);
    return false;
  }

  if(email == "") {
    inlineMsg('email','Въведете email',2);
    return false;
  }
  if(!email.match(emailRegex)) {
    inlineMsg('email','Невалиден email',2);
    return false;
  }
  
 
  return true;
}

function showservices(){
	newImage = "url(images/services_up.gif)";
        document.getElementById('services').style.backgroundImage = newImage;
	document.getElementById('servicessn').style.display="block";
	document.getElementById('services').style.color = "#04477e";
}
function hideservices(){
	newImage = "none";
        document.getElementById('services').style.backgroundImage = newImage;
	document.getElementById('servicessn').style.display="none";
	document.getElementById('services').style.color = "#293896";
}

function showc(){
	var e = document.getElementById('device_tab_open');
       if(e.style.display == "none"){
        e.style.display = "block";
       }else{
	e.style.display = "none";
       }
	var e1 = document.getElementById('device_tab_closed');
       if(e1.style.display == "none"){
        e1.style.display = "block";
       }else{
	e1.style.display = "none";
       }
}

var isIE=window.ActiveXObject?true:false;
function addFlash(path,w,h,id,alt)
{
	var args=addFlash.arguments,p,pos;
	var code=isIE?'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" width="'+w+'" height="'+h+'" id="'+id+'"><param name="movie" value="'+path+'" />':'<object type="application/x-shockwave-flash" data="'+path+'" width="'+w+'" height="'+h+'" id="'+id+'">';
	code+='<param name="menu" value="false" />';
	for(var x=args.length-1;x>4;x--)
	{
		p=args[x];
		pos=p.indexOf('=');
		code+='<param name="'+p.substr(0,pos)+'" value="'+p.substr(pos+1)+'" />';
	}
	code+=alt+'<param name="wmode" value="transparent" /><embed wmode="transparent" /></object>';
	document.write(code);
}

function showanim(obj){
       var e2 = document.getElementById('anim'+obj);
       e2.style.display = "block";
}

function hideanim(obj){
       var e2 = document.getElementById('anim'+obj);
       e2.style.display = "none";
}

function showp(obj){
	var ajaxRequest; 
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	var id = obj;
	
	var queryString = "?id=" + id;
	ajaxRequest.open("GET", "showp.php" + queryString, true);
	ajaxRequest.send(null);
	
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			document.getElementById("showpinfo").innerHTML=ajaxRequest.responseText;
		}
	}
}

function ss(){
       var e = document.getElementById('poll');
       var e1 = document.getElementById('n');

	if(e1.style.display == "none"){
        e1.style.display = "block";
	document.getElementById("switch").innerHTML= "<a href='javascript:ss();'>Анкета</a>";
       }else{
	e1.style.display = "none";
	document.getElementById("switch").innerHTML= "<a href='javascript:ss();'>Новини</a>";
       }

       if(e.style.display == "none"){
        e.style.display = "block";
       }else{
	e.style.display = "none";
       }
}

function sss(){
       var e = document.getElementById('blockrandomrp');
var e1 = document.getElementById('blockrandomlist');

       if(e.style.display == "none"){
        e.style.display = "block";
       }else{
	e.style.display = "none";
       }
e1.style.display = "none";
	
}

function ssss(){
       var e = document.getElementById('blockrandomlist');
var e1 = document.getElementById('blockrandomrp');

       if(e.style.display == "none"){
        e.style.display = "block";
       }else{
	e.style.display = "none";
       }
e1.style.display = "none";
	
}



var xmlHttp;

function getVote(int)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 } 
var url="poll_vote.php";
url=url+"?vote="+int;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function stateChanged() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("showpoll").
 innerHTML=xmlHttp.responseText;
 } 
} 

function GetXmlHttpObject()
{ 
var objXMLHttp=null;
if (window.XMLHttpRequest)
 {
 objXMLHttp=new XMLHttpRequest();
 }
else if (window.ActiveXObject)
 {
 objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
return objXMLHttp;
}



function validate1(form)
{
	var name = form.name.value;
	var phone = form.phone.value;
	var message = form.message.value;
	var email = form.mail.value;
	var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
 	
	if(name == "Вашето име"){
		document.getElementById('name').style.border = "1px #e75858 solid";
		return false;
	}

	if(phone == "Телефон за връзка"){
		document.getElementById('phone').style.border = "1px #e75858 solid";
		return false;
	}

	if(email == "Email") {
   	 document.getElementById('mail').style.border = "1px #e75858 solid";
   	 return false;
 	 }

 	 if(!email.match(emailRegex)) {
 	  document.getElementById('mail').style.border = "1px #e75858 solid";
  	  return false;
 	 }

	if(message == "Съобщение или запитване"){
		document.getElementById('message').style.border = "1px #e75858 solid";
		return false;
	}

	return true;
}

function nrs(){
	var ajaxRequest; 
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	ajaxRequest.open("GET", "shownrs.php", true);
	ajaxRequest.send(null);
	
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			
			document.getElementById("newsrightc").innerHTML=ajaxRequest.responseText;
		}
	}
}
