//globaliu kintamuju ir funkciju prefiksas - wc

//kintamajame naudoti domena patartina,
//kad pereinant is saito i saita nekiltu nenorimu rezultatu
//funkcijos wc_winOpen() antras parametras turi buti vienas is siu kint.
var wc1a, wc2a, wc3Domenas;
//juos naudoja funkcija wc_winOpenByNr(), atitinka kintamiesiems wc1Domenas, wc2Domenas, ...
var wc1 = "wcDomenas1", wc2 = "wcDomenas2", wc3 = "wcDomenas3";


//butinas tik win_type parametras
function wc_set(win_type,file_url,win_target) 
{
	switch (win_type)
	{
		case "pristatymas":
			window.open(file_url,'_blank','status=yes,scrollbars=yes,toolbar=yes,resizable=yes,width=760,height=430')
			break
	}
}


//***************************************************************************************
//funkcija langams su kintamaisiais atidaryti
//naudojimas:  <A href="javascript:void(0)" onClick="wc_winOpen('popupwin/nemokamai.htm','wc1Domenas','width=590,height=257',1)">
//parametrai:  (visi parametrai butini)
//1. WinID (string)     - lango kintamasis ir target vardas, t. y. tagams <A> ir <FORM>
//2. FileURL			- kelias
//3. winFormat			- lango formatas-atributai
//   bene visi atributai: 'width=200,height=200,left=0,top=0,toolbar=yes,menubar=yes,location=yes,scrollbars=yes,status=yes,resizable=yes,directories=yes,copyhistory=yes'
//4. winFocus			- jei true arba 1  -> jei langas su tuo paciu kintamuoju jau yra atidarytas, tada tik sufokusuoja jį, 
//						jei false arba 0 -> jei langas su tuo paciu kintamuoju jau yra atidarytas, sufokusuoja ir perkrauna nurodytą FileURL
//						koment: norint pakrauti URL į langą, kuris gal yra atidarytas, o gal nėra, reikia -> winFocus = 0
//						koment: jei lango su nurodytu WinID kintamuoju nera - visada sukurs tokį langą ir pakraus URL
//***************************************************************************************
function wc_open(WinID,FileURL,winFormat,winFocus,center) {
	if (center) {
		var param_pos = winFormat.indexOf('width')
		if (winFormat.indexOf(',',param_pos) == -1)		//kai parametru stringo gale
			var value_width = winFormat.substring(param_pos+6,winFormat.length)
		else
			var value_width = winFormat.substring(param_pos+6,winFormat.indexOf(',',param_pos))
		param_pos = winFormat.indexOf('height')
		if (winFormat.indexOf(',',param_pos) == -1)
			var value_height = winFormat.substring(param_pos+7,winFormat.length)
		else
			var value_height = winFormat.substring(param_pos+7,winFormat.indexOf(',',param_pos))
			
		var win_left = (screen.width - value_width) / 2;
		var win_top = ((screen.height - value_height) / 2) - 10;
	
		winFormat += ',left=' + win_left + ',top=' + win_top
	}

	if (eval(WinID)==null || eval(WinID+".closed")) {
		eval(WinID+"=window.open('"+FileURL+"','"+WinID+"','"+winFormat+"')"); 
		eval(WinID+".focus()");
	}
	else	if (winFocus) eval(WinID+".focus()"); 
			else {
				eval(WinID+"=window.open('"+FileURL+"','"+WinID+"','"+winFormat+"')");
				eval(WinID+".focus()");
			}
	return false;
	
	//alert('value_height>>> '+value_height)
}

/*_________________________     resize window   */

function wc_resize_to_content_interval(obj) {
	if (obj.scrollHeight > document.body.clientHeight) {
		if (document.body.clientHeight + 130 < screen.height) {
			window.resizeBy(0,30)
			//alert('after >> window.resizeBy()')
			window.moveBy(0,-15)
			//alert('after >> window.moveBy()')
		}
		else {
			window.moveBy(0,-35)
			window.clearInterval(inter)
			return
		}
	}
	else window.clearInterval(inter)
}

function wc_resize_to_content() {
	cont_obj = zm_findObjById('content-inside')
	//   sucentruoja langa
	//var win_left = (screen.width - document.body.clientWidth) / 2;
	var win_top = ((screen.height - document.body.clientHeight) / 2) - 10;
	window.moveTo(window.screenLeft-4,win_top)
	if (document.all && cont_obj.scrollHeight > document.body.clientHeight)
		inter = window.setInterval('wc_resize_to_content_interval(cont_obj)',1)
	//else (!document.all && document.body.scrollHeight > window.innerHeight)
}

/*_______     resize for prenumerata   

function resizeWindowInterval(need_height) {
	if (need_height > document.body.clientHeight) {
		if (document.body.clientHeight + 130 < screen.height) {
			window.resizeBy(0,30)
			//alert('after >> window.resizeBy()')
			window.moveBy(0,-15)
			//alert('after >> window.moveBy()')
		}
		else {
			window.moveBy(0,-35)
			window.clearInterval(inter)
			return
		}
	}
	else window.clearInterval(inter)
}


function resizeWindow_prenumerata() {
	sum_height = zm_findObjById('partTop').scrollHeight + zm_findObjById('partBottom').scrollHeight
	//var win_left = (screen.width - document.body.clientWidth) / 2;
	var win_top = ((screen.height - document.body.clientHeight) / 2) - 10;
	window.moveTo(window.screenLeft-4,win_top)
	if (document.all && sum_height > document.body.clientHeight)
		inter = window.setInterval('resizeWindowInterval(sum_height)',1)
	//else (!document.all && document.body.scrollHeight > window.innerHeight)
}

*/

//***************************************************************************************
//kito psl. pakrovimas brauzeryje
//1. WinID |string|
//   gali būti: 1) atidaryto lango kintamasis 
//              2) "self"
//              3) "top"
//              4) "opener"
//pvz.: <A href="javascript:void(0)" onClick="wc_Load('self','tekstas.htm'); return false">   <<< taip atidaryti tame pačiame lange
//***************************************************************************************
function wc_Load(WinID,fileURL) {
	var WinIDreal;
	if (eval(WinID)) WinIDreal = eval(WinID);
	else { alert(WinIDreal.location); return; }
	var tarp = WinIDreal==null || WinIDreal.closed; 
	if (!tarp) {
		WinIDreal.location.href = fileURL;
	}
}



/***************************************************************************************
			centruoja langa
***************************************************************************************

function NewWindow(mypage, myname, w, h, scroll, resizable) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable='+resizable;
	win = window.open(mypage, myname, winprops);
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

<script language="JavaScript">
<!--
function displayWindow(theURL,winName,width,height,features) {
var window_width = width;
var window_height = height;
var newfeatures= features;
var window_top = (screen.height-window_height)/2;
var window_left = (screen.width-window_width)/2;
newWindow=window.open
(''+ theURL + '',''+ winName + '','width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left + ',features=' + newfeatures + '');

newWindow.focus();
}
//-->
</script>


//be centravimo
function wc_open(WinID,FileURL,winFormat,winFocus) {
	if (eval(WinID)==null || eval(WinID+".closed")) {
		eval(WinID+"=window.open('"+FileURL+"','"+WinID+"','"+winFormat+"')"); 
		eval(WinID+".focus()");
	}
	else	if (winFocus) eval(WinID+".focus()"); 
			else {
				eval(WinID+"=window.open('"+FileURL+"','"+WinID+"','"+winFormat+"')");
				eval(WinID+".focus()");
			}
	return false;
}



*/