// JavaScript Document

function is_msie(){
	var browser = "";
	browser = navigator.appName;	
	if (browser == 'Microsoft Internet Explorer')
		return 1;
	else
		return 0;	
}
function show_props(obj, objName) {
   var result = "";
   for (var i in obj) {
   	if (i.indexOf('height')>=0)
      result += objName + "." + i + " = " + obj[i] + " \n";
   	if (i.indexOf('Height')>=0)
      result += objName + "." + i + " = " + obj[i] + " \n";
   }
   return result;
}

function update_content_h () {//alert(show_props(document.getElementById('test','test')))
//	if (!){
//	if (!is_msie()){//Resize content height to fit in window.
		borders_h = 2;
		hs_h = document.getElementById('hs').offsetHeight;// Head spacer
		hs2_h = document.getElementById('hs2') ? document.getElementById('hs2').offsetHeight : 0;// Spacer row 2(tr-td) 
		fs_h = document.getElementById('fs').offsetHeight;// Foot Spacer
		spacers_height = hs_h + hs2_h + fs_h+borders_h;
		ht_h = document.getElementById('ht') ? document.getElementById('ht').offsetHeight : 0;// Hearers (tr-td)
		if(document.getElementById('stretched_bar_v_spacer')){
			l2t_h = document.getElementById('left2table') ? document.getElementById('left2table').offsetHeight : 0;// Hearers (tr-td)
			other_el_height = l2t_h + borders_h;
//			alert(document.getElementById('left2').style.height);
//			document.getElementById('left2').style.display = 'block';
			document.getElementById('left2').style.height = l2t_h+'px';
//			alert(l2t_h+'px');
//			alert(document.getElementById('left2').style.height);

			//			if (!is_msie()){
				new_sbs_h = l2t_h - ht_h - hs2_h - borders_h;
//				alert(new_sbs_h);
//				alert (l2t_h+' - '+ht_h+' - '+hs2_h)
				document.getElementById('stretched_bar').style.display = 'block';
				document.getElementById('stretched_bar').style.height = new_sbs_h+'px';
				sbgs_h = document.getElementById('stretched_bar_g_spacer') ? document.getElementById('stretched_bar_g_spacer').offsetHeight : 0;
				document.getElementById('stretched_bar_v_spacer').style.height = (new_sbs_h-sbgs_h)+'px';
//			}
		}
		else{
			sb_h = document.getElementById('stretched_bar') ? document.getElementById('stretched_bar').offsetHeight : 0;//Rating bar (tr-td)
			other_el_height = ht_h + sb_h + borders_h;
			l2t_h = ht_h + sb_h + borders_h;
		}
		if(!is_msie()) 
			wh = window.innerHeight;
		else if (window.opera){
//			alert(show_props(document.html));
			wh = document.documentElement.clientHeight;
		}
		else
			wh = document.body.clientHeight;
		if (wh < 697) {
			document.getElementById('hs').style.display='none';
//			document.getElementById('hs').style.height='5px';
			hs_h = 0;
		}
		new_h = wh - spacers_height - other_el_height;
//		alert(new_h +'='+ wh +'-'+ spacers_height +'-'+ other_el_height);
//		alert(new_h +'='+ wh +'-'+ hs_h +'-'+ ht_h +'-'+ hs2_h + fs_h);
//		if (new_h < 330) new_h = 330;
//YA		document.getElementById('stretched_col').style.height = new_h+'px';// - 19;
		//Fixing error height in Mozilla
		if (document.getElementById('stretched_col_spacer'))
			document.getElementById('stretched_col_spacer').style.height = new_h+'px';
//		alert(wh +'-'+ hs_h +'-'+ ht_h +'-'+ hs2_h +'-'+ fs_h);
//YA		document.getElementById('left1').style.height = wh - hs_h - 50 - 10 - fs_h+'px';
//		alert(document.getElementById('left1').offsetHeight +'+'+ ht_h +'-'+ l2t_h);
		test_height = document.getElementById('left1').offsetHeight + ht_h - l2t_h - borders_h;
		if (new_h < test_height) {
//			alert(show_props(document.getElementById('left1')));
//			alert(document.getElementById('left1').offsetHeight);
//			alert(test_height);
			new_h = test_height;
			document.getElementById('stretched_col').style.height = new_h+'px';// - 19;
		}
//		alert(document.getElementById('stretched_bar').offsetHeight);
//		alert(document.getElementById('stretched_col').style.height);
//		alert(document.getElementById('vert_banner_place').clientHeight);
//		document.getElementById('vert_banner_place').style.height = new_h+sb_h+borders_h+'px';
//		alert(document.getElementById('vert_banner_place').style.height);
//		alert(document.getElementById('vert_banner_place').clientHeight);
//		alert(document.getElementById('stretched_bar').offsetHeight);
//	}
//	}
	if(window.opera){//Fixing error height in Opera.
		document.getElementById('left1').height = document.getElementById('left1').clientHeight;
		document.getElementById('left2').height = document.getElementById('left2').clientHeight;
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function getForm() {
	var f = document.forms['kernel_form'];
	return f;
}

function submit_form(params) {
	if (typeof(getForm().onsubmit) == "function") {
		getForm().onsubmit();
	}
	getForm().elements['t'].value = getForm().elements['ct'].value.replace(/^\//, '');
//	alert(getForm().elements['t'].value);
//	alert(params);
	if (typeof(params) != 'undefined') {
		getForm().action = front_end_action + '?' + params;
	} else {
		getForm().action = front_end_action;
	}
//	alert(getForm().elements['t'].value);
//	getForm().elements['t'].value = lang_prefix + getForm().elements['ct'].value;
//	alert(getForm().elements['t'].value);
	getForm().submit();
	getForm().target = '';
	getForm().t.value = t;
}

function submit_action(prefix, action_field, action, params)
{
	getForm().elements[prefix + action_field].value = action;
	submit_form(params);
}

function add_comment(prefix, params)
{
	if (typeof(params) != 'undefined' && params != '') {
		getForm().elements[prefix + 'action_form'].value = getForm().elements[prefix + 'save_action'].value;
	} else {
		getForm().elements[prefix + 'action_form'].value = getForm().elements[prefix + 'save_action'].value;
	}
	submit_form(params);
}

function delete_comment(prefix, action_field, action, params)
{
	if (typeof(getForm().onsubmit) == "function") {
		getForm().onsubmit();
	}
	getForm().elements['t'].value = getForm().elements['ct'].value.replace(/^\//, '');
	if (typeof(params) != 'undefined') {
		getForm().action = front_end_action + '?' + 'admin=1&' + params;
	} else {
		getForm().action = front_end_action + '?' + 'admin=1&';
	}
	getForm().elements[prefix + action_field].value = action;
//	getForm().elements['t'].value = lang_prefix + getForm().elements['ct'].value;
//	alert('t: ' + getForm().elements['t'].value);
//	alert('form action: ' + getForm().action);
	getForm().submit();
	getForm().target = '';
	getForm().t.value = t;
}

//	------------------------------------- Subscribe -------------------------------------
var subscribe_default_text = null;

function hideDefaultText(inpObj) {	// onFocus
	if (subscribe_default_text == null)
		subscribe_default_text = inpObj.value;
	if (inpObj.value == subscribe_default_text)
		inpObj.value = '';
}

function showDefaultText(inpObj) {	// onBlur
	if (inpObj.value == '')
		inpObj.value = subscribe_default_text;
}

function doSubscribe() {
	submit_action('subscribe__', 'action', 'Subscribe');
}
//	---------------------------------- End of Subscribe ---------------------------------



//	--------------------------------------- Vote ----------------------------------------
function doVote() {
	submit_action('vote__', 'action', 'Vote');
}
//	------------------------------------- End of Vote -----------------------------------


function sortGrid(prefix, field, params)
{
	getForm().elements[prefix + 'sort1'].value = field;
	getForm().elements[prefix + 'action_grid'].value = 'sort';
	submit_form(params);
}

function filter_grid(prefix)
{
	getForm().elements[prefix + 'action_grid'].value = 'Filter';
	submit_form();
}

function reset_filters(prefix)
{
	getForm().elements[prefix + 'action_grid'].value = 'ResetFilters';
	submit_form();
}

function clear_option_box(listObj)
{
	listObj.options.length = 0;
}

function setPage(prefix, template, page) {
//	document.kernel_form.t.value = template;
	document.kernel_form.elements[prefix + 'page'].value = page;
	document.kernel_form.elements[prefix + 'action_grid'].value = 'gotoPage';
	submit_form('com=1');
}

function submit_form2()
{
	if (typeof(getForm().onsubmit) == "function") {
		getForm().onsubmit();
	}
	getForm().action = location.href;
	getForm().submit();
	getForm().target = '';
	getForm().t.value = t;	
}

function setPage2(prefix, page)
{
	document.kernel_form.elements[prefix + 'page'].value = page;
	document.kernel_form.elements[prefix + 'action_grid'].value = 'gotoPage';
	submit_form2();
}


function popup(location, target, width, height, resizable, scrollbars, status, menubar, toolbar)
{
	var str = '';
	if (width > 0 && height > 0) {
		str = str + 'width=' + width + ',height=' + height + ',';
	}
	var resizable_str  = resizable ? 'yes' : 'no';
	var scrollbars_str = scrollbars ? 'yes' : 'no';
	var status_str     = status  ? 'yes' : 'no';
	var menubar_str    = menubar ? 'yes' : 'no';
	var toolbar_str    = toolbar ? 'yes' : 'no';

	window.open(
		location,
		target,
		str +
		'resizable='  + resizable_str + ',' +
		'scrollbars=' + scrollbars_str + ',' +
		'status='     + status_str + ',' +
		'menubar='    + menubar_str + ',' +
		'toolbar='    + menubar_str
	);
}

function popupArticle(location, target, width, height)
{
	if (!width > 0)  { width = 560;  }
	if (!height > 0) { height = 500; }
	popup(location, target, width, height, false, true, true);
}

function showFormPart(part)
{
	var natural_fields = Array('name', 'surname', 'age', 'education', 'occupation');
	var juristic_fields = Array('company', 'fax', 'reg_num', 'fax', 'reg_num', 'jur_address', 'quantity_of_copies');
	
	if (part == 'natural'){
		for(i=0; i < natural_fields.length; i++){
			el = document.getElementById(natural_fields[i]);
			el.style.display = '';
//			for(j=0; j < el.children.length; j++){
//				el.children[j].style.display = 'block';
//			}
		}
		for(i=0; i < juristic_fields.length; i++){
			el = document.getElementById(juristic_fields[i]);
			el.style.display = 'none';
//			for(j=0; j < el.children.length; j++){
//				el.children[j].style.display = 'none';
//			}
		}
	}
	else if (part == 'juristic'){
		for(i=0; i < juristic_fields.length; i++){
			el = document.getElementById(juristic_fields[i]);
//			alert(el.innerHTML);
			el.style.display = '';
//			alert(el.innerHTML);
//			for(j=0; j < el.children.length; j++){
//				el.children[j].style.display = 'block';
//			}
		}
		for(i=0; i < natural_fields.length; i++){
			el = document.getElementById(natural_fields[i]);
//			alert(el.innerHTML);
			el.style.display = 'none';
//			alert(el.innerHTML);
//			for(j=0; j < el.children.length; j++){
//				el.children[j].style.display = 'none';
//			}
		}
	}
}

function openwincms( url, name, w, h)
{
	var win = null;
	
/*
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
*/
	
	settings = 'height=200,width=200,scrollbars=no,resizable=no,status=no';
	win = window.open( '' , name , settings );
	var win_content = '<html>\n<head>\n\t<title>Image</title>\n'
						+ '<style type="text/css">\n'
						+ 'body {\n'
						+ '\toverflow: hidden;\n'
						+ '}\n'
						+ '</style>\n'
						+ '<script type="text/javascript" language="javascript">\n'
						+ 'var NS = (navigator.appName=="Netscape") ? true : false;\n'
						+ 'function initImagePopup() {\n'
						+ '\tiWidth = (NS) ? window.innerWidth : document.body.clientWidth;\n'
						+ '\tiHeight = (NS) ? window.innerHeight : document.body.clientHeight;\n'
						+ '\tim_w = document.images[0].width;\n'
						+ '\tim_h = document.images[0].height;\n'
						+ '\tiWidth = im_w - iWidth;\n'
						+ '\tiHeight = im_h - iHeight;\n'
						+ '\tself.resizeBy(iWidth, iHeight);\n'
						+ '\tself.moveTo(screen.width/2 - Math.floor(im_w/2), screen.height/2 - Math.floor(im_h/2));\n'
						+ '};\n'
						+ '</script>\n'
						+ '</head>\n\n'
						+ '<body onload="initImagePopup()" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">\n'
						+ '<a href="javascript:;" onclick="javascript:self.close(); return false;">\n'
						+ '<img src="'+url+'" border="0" alt="Close popup" title="Close popup">\n'
						+ '</a>\n'
						+ '</body>\n</html>';
	if (win && win.open && !win.closed) {
		win.document.write( win_content );
		win.document.close();
		win.focus();
	}
}