function getE(id){
	return document.getElementById(id);
}

function defined(x){
	return typeof(x) != 'undefined' && x != null;
}

function addListener(element, event, func){
	if(element.attachEvent)
		element.attachEvent('on' + event, function(){ func(window.event) });
	else if(element.addEventListener)
		element.addEventListener(event, func, false);
}

function ShowWin(url,x,y,name,isscrollbars) {
	cx=screen.width / 2 - (x / 2);
	cy=(screen.height/2-(y/2));
    
    isscrollbars=(isscrollbars=="no")?"no":"yes";
	window.open(url,name,"toolbar=no,status=no,directories=no,menubar=no,resizable=yes,width="+x+",height="+y+",scrollbars="+isscrollbars+",top="+cy+",left="+cx);
}


function MOver(MySrc,MyColor) { MySrc.style.cursor="auto"; MySrc.bgColor=MyColor; }
function MOut (MySrc,MyColor) { MySrc.style.cursor="auto"; MySrc.bgColor=MyColor; }



function Selecter(Form, EName, S) {
    var f=Form;
    for ( i=0; i<f.length; i++ ) {
        if (f.elements[i].name==EName) {
            f.elements[i].checked=(S==1)?true:false;
        }
   }        
}



function ShowDivWindow(Name, Text, Action) {
    leerId=Name;
    LoadingHTML=Text;

	cx=(document.body.clientWidth/2)-(200/2);
	cy=(document.body.clientHeight/2)-(100/2);


/*    
	cx=screen.width/2;
	cy=screen.height/2;
*/
    
    if ((navigator.userAgent.indexOf("MSIE 5.5")==-1) && (navigator.userAgent.indexOf("MSIE 6")==-1)) {
//      cx += 90;
      cy-= 117;
    }

   
    if (document.all) {
        var leerElem = document.all[leerId];
        leerElem.innerHTML = LoadingHTML;
        leerElem.style.left = cx;
        leerElem.style.top = cy;
        leerElem.style.visibility = ((Action=="show")?"visible":"hidden");
    }
    else if (document.getElementById) {
        var leerElem = document.getElementById(leerId);
        leerElem.innerHTML = LoadingHTML;
        leerElem.style.left = cx;
        leerElem.style.top = cy;
        leerElem.style.visibility = ((Action=="show")?"visible":"hidden");
    }
    else if (document.layers) {
        document.layers[leerId].left = cx;
        document.layers[leerId].top = cy;
        document.layers[leerId].document.open();
        document.layers[leerId].document.write(LoadingHTML);
        document.layers[leerId].document.close();
        document.layers[leerId].visibility = ((Action=="show")?"show":"hide");
    }
}



function prepare_submit() {
	var form = document.getElementById('f_install');

	//var informer = document.getElementById('informer');

	//var values = informer.value;


	var action = form.action;

	//var inputs = form['informer']; 
	
	var element = form.elements;
	var inputs = Array();

	var j=0;
	for (i=0; i<element.length; i++){
		if (element[i].type=='hidden')
		{
			inputs[j] = element[i];
			j++;
		}
	}

	var values = '';
	
	
	if (inputs != null){
		if (inputs.length != null) {				
			for (i = 0; i<inputs.length; i++){	
				//if (inputs[i].checked) {
					values += inputs[i].value+'_';
				//}								
			}		
			values = values.substr(0,values.length-1);						
		} else {
			//if (inputs.checked) {	
				values = inputs.value;
			//}	
		}	
	}
	
	

	if (values != '')
	{
		form.action = action + '&id=' + values;
	}

	//alert(form.action);
	
	return true;	
}


function get_qs(no_name) {
	var qs = '?';
	var form = document.getElementById(form_name);
	//var selects = form.getElementsByTagName('select');
	//var inputs = form.getElementsByTagName('input');
	

	var element = form.elements;


	if (element != null) {
		if (element.length != null) {
			for (i=0; i<element.length; i++){
				if (element[i].name != no_name)
				{
					qs += element[i].name+'='+element[i].value+'&';	
				}
			}		
		} else {
			if (element[i].name != no_name)
			{
				qs += element.name+'='+element.value+'&';
			}
		}
	}



	/*if (selects != null) {
		if (selects.length != null) {
			for (i=0; i<selects.length; i++){
				
					qs += selects[i].name+'='+selects[i].value+'&';
				}
			}		
		} else {
			qs += selects.name+'='+selects.value+'&';
		}
	}

	if (inputs != null) {
		if (inputs.length != null) {
			for (i = 0; i<inputs.length; i++){
				if (inputs[i].name != no_name)
				{
					qs += inputs[i].name+'='+inputs[i].value+'&';
				}
							
			}		
		} else {
			if (inputs.name != no_name)
			{
				qs += inputs.name+'='+inputs.value+'&';
			}
		}
	}*/

	return qs;
}



//-----------------------------------------------
function load_frame() {
	var qs = get_qs();
	var frame = window.parent.document.getElementById('frame_js');
	//window.opener

	frame.src = 'http://'+http+'/informers/'+controller_name+qs;	//	'/view'+
}


function fill_code() {						
	var HTML = '';
	
	var qs = get_qs('html');
	var area = window.parent.document.getElementById('code'+controller_id);
	//window.opener

	if (scripts != null){
		for (i = 0; i<scripts.length; i++){
			HTML = HTML + '<script language="javascript" src="http://'+http+scripts[i]+'"></script>';
		}
	}
	
	window.parent.document.getElementById('request').value = 'http://'+http+'/informers/'+controller_name+qs;
	
	HTML = HTML + '<script language="javascript"><!--\n';
	HTML = HTML + 'document.write(\'<script language="javascript" src="http://'+http+'/informers/'+controller_name+qs+'_rand=\'+Math.random()+\'"></script>\');\n';
	HTML = HTML + '//--></script>';
	
	area.value = HTML;
}

function fill_a() {						
	var HTML;
	var qs = get_qs();
	var a = window.parent.document.getElementById('a'+controller_id);
	//window.opener
	a.href = '/informers/'+controller_name+'/edit'+qs;
}


function fill_div() {
	var qs = get_qs();
	var div = window.parent.document.getElementById('div'+controller_id);
	//window.opener
	var sUrl = "http://"+http+"/informers/"+controller_name+qs;

	window.parent.document.getElementById('floader').src = sUrl;

	//div.innerHTML = loadHTML(sUrl);
}

function LoadCSS(name,n) {
	window.parent.document.getElementById(name).href = n;
	//window.opener
}
//-----------------------------------------------

/*
function loadHTML(sURL)

{

  var request=null;



  // пытаемся создать объект для MSXML 2 и старше

  if(!request) try {

    request=new ActiveXObject('Msxml2.XMLHTTP');

  } catch (e){}



  // не вышло... попробуем для MSXML 1

  if(!request) try {

    request=new ActiveXObject('Microsoft.XMLHTTP');

  } catch (e){}



  // не вышло... попробуем для Mozilla

  if(!request) try {

    request=new XMLHttpRequest();

  } catch (e){}



  if(!request)

    // ничего не получилось...

    return "";

 

  // делаем запрос

  request.open('GET', sURL, false);

  request.send(null);



  // возвращаем текст

  return request.responseText;

}
*/

function get_div(id) {
	var div = window.opener.document.getElementById(id);	
	if (!div) { alert('Ошибка фильтра: Отсутствует div с id = div_'+filter) } 
	return div.innerHTML;	
}


function set_div(id,content) {
	var div = window.opener.document.getElementById(id);	
	div.innerHTML = content;
	
}


/*function LoadCSS(Filehref) {
	var link = window.opener.document.createElement('link');
	window.opener.document.getElementsByTagName("body")[0].appendChild(link);
	link.rel = 'stylesheet';
	link.type = 'text/css';
    link.href = Filehref;
}
*/

function tli_on_change(){ document.getElementById('pc_input_ci').value=document.getElementById('pc_select').options[document.getElementById('pc_select').selectedIndex].value; return true;}

function relcal() {
	
	Calendar.setup({
	inputField : "DaF", // ID of the input field
	ifFormat : "%d-%m-%Y", // the date format
	showsTime : false,
	button : "trigger_DaF" // ID of the button
	});

	Calendar.setup({
	inputField : "DaT", // ID of the input field
	ifFormat : "%d-%m-%Y", // the date format
	showsTime : false,
	button : "trigger_DaT" // ID of the button
	});

}