var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
window.onscroll = function () {
   // alert( document.documentElement.scrollTop+'-******---');         
	if(document.getElementById("pillow")){//alert(document.documentElement.scrollTop+"--*");
					document.getElementById("pillow").style.top = document.documentElement.scrollTop+167+'px';
	}
			//alert( document.documentElement.scrollTop+'----');
}
function changeClass(id,className){
	if(document.getElementById(id))document.getElementById(id).className=className;
}
function getScrollerWidth() {

          var scr = null;

          var inn = null;

          var wNoScroll = 0;

          var wScroll = 0;

          // Outer scrolling div

          scr = document.createElement('div');

          scr.style.position = 'absolute';

          scr.style.top = '-1000px';

          scr.style.left = '-1000px';
 
          scr.style.width = '100px';

          scr.style.height = '50px';

          // Start with no scrollbar

          scr.style.overflow = 'hidden';

          // Inner content div

          inn = document.createElement('div');

          inn.style.width = '100%';

          inn.style.height = '200px';

          // Put the inner div in the scrolling div

          scr.appendChild(inn);

          // Append the scrolling div to the doc

          document.body.appendChild(scr);

          // Width of the inner div sans scrollbar

          wNoScroll = inn.offsetWidth;

          // Add the scrollbar

          scr.style.overflow = 'auto';

          // Width of the inner div width scrollbar

          wScroll = inn.offsetWidth;

          // Remove the scrolling div from the doc

          document.body.removeChild(

     document.body.lastChild);

          // Pixel width of the scroller
     return (wNoScroll - wScroll);
}
function changeImgSrc(id,src){
	if(document.getElementById(id))document.getElementById(id).src=src;
}


var scroll=0;
function fscroll(ta_id,idscroller,sc){
	var hg=0;
	if(document.getElementById(idscroller).scrollHeight){
		hg=document.getElementById(idscroller).scrollHeight-document.getElementById(ta_id).offsetHeight;
	}else{
		hg=document.getElementById(ta_id).scrollHeight;
	}
	//window.alert(document.getElementById(ta_id).scrollHeight+" - "+scroll+" - "+document.getElementById(ta_id).scrollTop);
	//document.getElementById(ta_id).scrollTop=document.getElementById(ta_id).scrollHeight;
	if((scroll<=hg) && (scroll>=0)){
		scroll+=sc;
		document.getElementById(ta_id).scrollTop=scroll;
	}
	if(scroll>hg){scroll=hg;}
	if(scroll<0){scroll=0;}
	//alert(ta_id+'----'+sc);
	
	
}

function alertSizeHight() {
		  var myHeight = 0;
		  if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			//myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		  } else if( document.documentElement && ( document.documentElement.clientHeight ) ) {//|| document.documentElement.clientHeight 
			//IE 6+ in 'standards compliant mode'
			//myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		  } else if( document.body && ( document.body.clientHeight) ) {// || document.body.clientHeight 
			//IE 4 compatible
			//myWidth = document.body.clientWidth;
		    myHeight = document.body.clientHeight;
		  }
		  //window.alert( 'Width = ' + myWidth );
		  //window.alert( 'Height = ' + myHeight );
		  //alert(document.getElementById('tdmiddle').offsetWidth+'-jjjj---'+document.getElementById('idtd').offsetWidth);
		  //myWidth-getScrollerWidth();
		  return myHeight;
}
function stopAnimate(brot,alle){
	if(document.getElementById(brot))$("#"+brot).animate({height: "0px",opacity: 0}, 500 , function(){displayobj(brot,'none');});
	displayobj(alle,'block');
		//document.getElementById(brot).style.border='3px solid blue';
}


function animateHeight(id,idshow){
	if(globalSuccor==0){
		var oo=document.getElementById('pillow').style.width+'';
		
		var  wth=alertSize();
		var idphialPos=wth-614;
		idphialPos=idphialPos/2;
		if((oo=='')||(oo=='0px')){
			
	//alert(document.getElementById(id)+"--"+id+document.getElementById(idshow)+"---***"+idshow);
			//var ps=returnPosition('idHeader','idphial',0,0);
			if(document.getElementById(id))document.getElementById(id).style.display="block";
			if(document.getElementById(idshow))document.getElementById(idshow).style.display="block";
			//setPosition1('idHeader',id,730,130);
			/* if(document.getElementById('idminister')){
				
				document.getElementById('idminister').innerHTML="X<br />Parašysiu kitą kartą";
			} */
			
			
			//alert(document.getElementById('idministerParent').className);
			//if(document.getElementById(id))document.getElementById(id).style.top=document.documentElement.scrollTop+'px';
			document.getElementById(id).style.left=(idphialPos+694)+'px';
			document.getElementById(id).style.top='100px';
			var tmp=idphialPos;
			$("#"+id).animate({ width: "614px",height: "287px",left: tmp+"px"}, 300,function() {
			globalSuccor=1;
			changeClass('idministerParent','fr ascribe1');
	  } );
			
		}
	}else{
	/* 	if(document.getElementById('idminister')){
				document.getElementById('idminister').innerHTML="Parašykite laišką";
		} */
		
		animateSmallHeight(id,idshow);
		changeClass('idministerParent','fr ascribe1');
		globalSuccor=0;
	}
	
}
function changeOnclick(idclick,idabs,idabssub){
	if(document.getElementById(idclick)){
			var el = document.getElementById(idclick);
			//alert(el+'--');
			el.onclick = animateSmallHeight(idabs,idabssub);
	}
}

function animateSmallHeight(id,idHide){
	
	//var ps=returnPosition('idHeader','idphial',0,0);
	//setPosition1('idHeader',id,730,130);
	var  wth=alertSize();
	var idphialPos=wth-614;
	idphialPos=idphialPos/2;
	
	var tmp1=(idphialPos+694)+'px';
	//var tmp=document.getElementById(id).offsetLeft-639;
	//if(document.getElementById(id))document.getElementById(id).style.left=tmp+"px";
	$("#"+id).animate({ width: "0px",height: "0px",left: tmp1}, 300 );
	document.getElementById(id).style.display="none";
	document.getElementById(idHide).style.display="none";
	document.getElementById('pillow2').style.display="none";
	
	
	

	
}

function onLoadpage(){
	//logo
	setheightLimTable('idlodge',-51);
	
	
	
}
function displayobj(id,visibility){
	if(document.getElementById(id))document.getElementById(id).style.display =visibility;
}

function setheightLimTable(id,h1){
//alert("---");
	var hh=alertSizeHight();
	
	if(document.getElementById(id)){
		 document.getElementById(id).style.height=hh+h1+'px';
		 //alert(hh+"---"+h1);
	}
	
	//var hgt1=0,hgt2=0;
	//if(document.getElementById(id)){
	//	var hgt1=document.getElementById(id).offsetHeight;
	//}
	//if(document.getElementById(idShow)){
	//	hgt2=document.getElementById(idShow).offsetHeight;
	//	if(hgt1>hgt2) document.getElementById(idShow).style.height=hgt1+height+'px';
	//	else document.getElementById(id).style.height=hgt2+86+'px';
	//}
	//alert((hgt1+height)+'px');
}

function setheightObj(id,idShow,left,hgt){
	var hgt1=0,left1=0,wdt=0,wd=0,ws=0;
	if(document.getElementById(id)){
	//	hgt1=document.getElementById(id).offsetTop;
		wd=alertSize();
		//left1=document.getElementById(id).offsetLeft;
		wdt=document.getElementById(id).offsetWidth;
		//alert(wd+'---+++'+wdt)
	}
	
	if(document.getElementById(idShow)){
		ws=document.getElementById(idShow).offsetWidth;
		document.getElementById(idShow).style.top=hgt+'px';
		document.getElementById(idShow).style.left=wd-((wd-wdt)/2)-ws+left+'px';
	}
	
	//alert(document.getElementById(idShow).style.left+'----'+hgt1+'--');
}


function changeClassesAll(id1,cl1,id2,cl2,id3,cl3,id4,cl4){
	changeClass(id1,cl1);
	changeClass(id2,cl2);
	changeClass(id3,cl3);
	changeClass(id4,cl4);
}

function verifyEmail(email,name,question){
var status = false;     
var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
     if (email.search(emailRegEx) == -1) {
          alert("Neteisingas pašto adresas!");
     }
    
     else if(question==''){
         // alert("Woohoo!  The email address is in the correct format and they are the same.");
	
			
			alert("Užpildykite laukus!");
		
     }
	 else if(name==''){
         // alert("Woohoo!  The email address is in the correct format and they are the same.");
	
			
			alert("Užpildykite laukus!");
		
     }
	 
	 
	 else{
		status = true;
	 }
     return status;
}
function sendEmail(email,name,question){
	var bool=verifyEmail(email,name,question);
	if(bool){
	//alert(22);
		$.ajax({
		  url: 'http://www.firminis-stilius.info/send.php',
		  data: {email:email,question: question,name: name},
		  success: function(data) {
			//$('.result').html(data);
		//	alert(22222222);
		//   alert('Load was performed.'+data);
			 animateOpacity('pillow2','pillow1');
		
		  }
		});
		//alert(33);
	}
	
}

function animateOpacity(id,idHide){
	if(document.getElementById(idHide))document.getElementById(idHide).style.display="none";
				
	if(document.getElementById(id))document.getElementById(id).style.display="block";
	if(BrowserDetect.browser=="Explorer"&&BrowserDetect.version=="6"){
		document.getElementById(id).style.filter="alpha(opacity="+(0.1*100)+")";
	}else{
		 document.getElementById(id).style.MozOpacity=0.1;
	}
	$("#"+id).animate({opacity: 1},1000); 
}

function ajaxFunction(email,yourName,txtArea)
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	{
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	}
	else
	{
	  // code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
		//document.myForm.time.value=xmlhttp.responseText
			//alert(xmlhttp.responseText+'ppppppp');
			//alert('Jus sekmingai uzsiregistravote!!!');
			//window.location.href=window.location.href;
			
			document.getElementById('successfully').className='successfull';
			document.getElementById('showSuccessfully').className='imgOpicity';
			
			
			//alert(document.getElementById('successfully').className+'---------');
		}
	}
	xmlhttp.open("GET","data.php?yourName="+yourName+"&email="+email+"&txtArea="+txtArea+"",true);
	xmlhttp.send(null);
}
function changeClass(id,classname){
	if(document.getElementById(id))document.getElementById(id).className=classname;
}
