

// prasideda link_pop-up script'as

function openWindow(url, w, h) {
var options = "width=" + w + ",height=" + h + ",";
options += "resizable=no,scrollbars=yes,status=no,";
options += "menubar=no,toolbar=no,location=no,directories=no";
var newWin = window.open(url, 'newWin', options);
newWin.focus();
}


var i;
function ajax_start(){
		i = i + 1;
		http_request = false;
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }
        return http_request;
}

function ajax_post(http_request,parameters){
	    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      	http_request.setRequestHeader("Content-length", parameters.length);
      	http_request.setRequestHeader("Connection", "close");
      	http_request.send(parameters);
}

function popup_on(id,post){
	this.document.getElementById('content').style.display = 'none';
	this.document.getElementById('popup').style.display="block";
	this.document.getElementById('nw_div').style.display = 'block';
	setTimeout("popup_on2("+id+",'"+post+"')",3000);
}
function popup_on2(id,post){
	this.document.getElementById('nw_div').style.display = 'none';
	this.document.getElementById('close').style.display = 'block';
	ajax = ajax_start();
	ajax.onreadystatechange = function() {popup_on3(ajax,id); };
	post = post + '&';
	http_request.open('POST',"in2.php?id="+id,true);
	ajax_post(ajax,post);
	//this.document.getElementById('content').style.display = 'block';
}
function popup_on3(ajax,id){
	if (ajax.readyState == 4) {
    	if (ajax.status == 200) {
			this.document.getElementById('content').style.display = 'block';			
 			this.document.getElementById('content').innerHTML = ajax.responseText;
    	}
	}
}
function popup_close(){
	Effect.Fold('popup',{afterFinish:popup_close2});
}
function popup_close2(obj){
	//this.document.getElementById('popup').style.display = 'none';
	//this.document.getElementById('popup').innerHTML = '';
	//this.document.getElementById('close').style.display = 'none';
	//this.document.getElementById('content').style.display = 'block';
}
function page(id){
	//popup_close();
	if(lapai[id] == 1){
		popup_on(id);
	}else{
		this.document.getElementById('iframe').src='in.php?id='+id;
	}
}
function rekomenduokite_toogle(){
	if(this.document.getElementById('rekomenduokite').style.display == 'none'){
		this.document.getElementById('rekomenduokite').style.display = 'block';
		this.document.getElementById('rekomenduokite2').style.display = 'block';
		this.document.getElementById('rekomenduokite3').style.display = 'block';
	}else{
		this.document.getElementById('rekomenduokite').style.display = 'none';
		this.document.getElementById('rekomenduokite2').style.display = 'none';
		this.document.getElementById('rekomenduokite3').style.display = 'none';
	}
}
function rekomenduoti_draugui(){
	ajax = ajax_start();
	if(this.document.getElementById('vardas_1').value == '' || this.document.getElementById('vardas_2').value == '' || this.document.getElementById('email_1').value == '' || this.document.getElementById('email_2').value == ''){
		alert('Užpildykite visą formą!');
		return false;
	}
	this.document.getElementById('submit').disabled = true;
	ajax.onreadystatechange = function() {rekomenduoti_draugui2(ajax); };
	ajax.open('POST',"rekomenduoti.php",true);
	parameters='vardas_1='+this.document.getElementById('vardas_1').value+'&vardas_2='+this.document.getElementById('vardas_2').value+'&email_1='+this.document.getElementById('email_1').value+'&email_2='+this.document.getElementById('email_2').value+'&';
	ajax_post(ajax,parameters);
	return false;
}
function rekomenduoti_naujas(){
	this.document.getElementById('rekomendacija2').innerHTML = '<form onSubmit="return rekomenduoti_draugui();" method="post" name="rekomendacija">\
	<div style="float:right;margin-right:45px;display:none;margin-left:2px;margin-top:20px;width:20px;" id="rekomenduokite3"><input id="submit" type="image" src="fls/img/btn_send_20.png"></div>\
	<div style="float:right;margin-left:10px;display:none;align:left;width:210px;font-size:12px;" id="rekomenduokite"><input style="width:100px;height:18px;border:2px solid #787878;color:#3A7BA2;margin:1px;font-size:12px" onClick="this.value=\'\'" value="Jūsų vardas" type="text" id="vardas_1"> <input style="width:100px;height:18px;border:2px solid #787878;color:#3A7BA2;margin:1px;font-size:12px" onClick="this.value=\'\'" value="Draugo vardas" id="vardas_2" type="text"><br> <input style="width:100px;height:18px;border:2px solid #787878;color:#3A7BA2;margin:1px;font-size:12px" onClick="this.value=\'\'" value="Jūsų @" type="text" id="email_1"> <input style="width:100px;height:18px;border:2px solid #787878;color:#3A7BA2;margin:1px;font-size:12px" onClick="this.value=\'\'" id="email_2" value="Draugo @" type="text"></div><div id="rekomenduokite2" style="float:right;display:none;vertical-align:bottom;font-size:10px;padding-top:9px;">Įveskite savo ir savo draugo duomenis ir paspauskite "»"<br>Nurodytu el. paštu bus nusiųsta nuoroda į mūsų tinklapį</div>\
	</form>';
	rekomenduokite_toogle();
}
function rekomenduoti_draugui2(ajax){
	if (ajax.readyState == 4) {
    	if (ajax.status == 200) {
 			this.document.getElementById('rekomenduokite').innerHTML = '';			
 			this.document.getElementById('rekomenduokite2').innerHTML = 'Jūsų rekomendacija buvo sėkmingai išsiųsta draugui. <a href="#" onClick="rekomenduoti_naujas()">Siųsti dar vieną</a>.';
 			this.document.getElementById('rekomenduokite3').innerHTML = '';
    	}
	}
}
function wrapImg(id){
	this.iframe.document.getElementById(id).childNodes[1].style.visibility = 'visible';
}
function unWrapImg(id){
	this.iframe.document.getElementById(id).childNodes[1].style.visibility = 'hidden';
}
function wrapImg2(id){
	this.iframe.document.getElementById(id).parentNode.childNodes[5].style.visibility = 'visible';
}
function unWrapImg2(id){
	this.iframe.document.getElementById(id).parentNode.childNodes[5].style.visibility = 'hidden';
}
//function s_play(now){
//	alert(now);
//}
function s_next(){
	Effect.toggle('s_img','appear',{afterFinish:s_next2});
}
function s_next2(obj){
	//alert(now);
	now = now+'';
	this_id = images_ln.indexOf(now);
	next_id = this_id + 1;
	if(!images_ln[next_id+'']){
		next_id = 1;
	}
	info = images[images_ln[next_id]];
	$('s_img').src = 'images/galerija/normal/'+info['normal'];
	Effect.toggle('s_img','appear');
	$('s_title').update('<b>'+info['title']+'</b>');
	$('s_descr').update(info['description']);
	$('s_b_zoom').href = 'images/galerija/original/'+info['original'];
	$('original').href = 'images/galerija/original/'+info['original'];
	//$('s_b_next').writeAttribute('onclick','s_next('+iframe.images_ln[next_id]+')');
	//$('s_b_previous').writeAttribute('onclick','s_previous('+iframe.images_ln[next_id]+')');
	now = images_ln[next_id];
}
function s_previous(){
	Effect.toggle('s_img','appear',{afterFinish:s_previous2});
}
function s_previous2(obj){
	this_id = images_ln.indexOf(now);
	previous_id = this_id - 1;
	if(!images_ln[previous_id+'']){
		previous_id = images_ln.length - 1;
	}
	info = images[images_ln[previous_id]];
	$('s_img').src = 'images/galerija/normal/'+info['normal'];
	Effect.toggle('s_img','appear');
	$('s_title').update('<b>'+info['title']+'</b>');
	$('s_descr').update(info['description']);
	$('s_b_zoom').href = 'images/galerija/original/'+info['original'];
	$('original').href = 'images/galerija/original/'+info['original'];
	//$('s_b_previous').writeAttribute('onclick','s_previous('+iframe.images_ln[previous_id]+')');
	//$('s_b_next').writeAttribute('onclick','s_next('+iframe.images_ln[previous_id]+')');
	now = images_ln[previous_id];
}
function s_play(){
	now = now+'';
	stop_playing = '';
	$('s_b_play').src="fls/img/btn_pause.png";
	//$('s_b_play').writeAttribute('onclick','s_pause()');
	$('s_b_play').onclick = s_pause;
	s_next();
	new PeriodicalExecuter( function(pe) {
		if(stop_playing != 'yes'){
			s_next();
		}else{
			pe.stop();
		}
	},5);
}
function s_pause(){
	$('s_b_play').src="fls/img/btn_play.png";
	$('s_b_play').onclick = s_play;
	stop_playing = 'yes';
}
