function LoginBox(){
	this.clicked = false;
	this.hide  = function(){$('vip').addClassName('hide');}
	this.show  = function(){$('vip').removeClassName('hide');} 
	this.click  = function(){
		if(this.clicked==false){
		this.clicked = true;
		this.show();
		}
		else {
			this.clicked = false;
			this.hide();
		}
	}
}

function usr_pop(uid){
	//popWin=window.open( base_url+'index.php?module=&action=&user_id='+uid,'user_detales','width=554,height=350,menubar=no,status=no,location=no,toolbar=no,scrollbars=yes,resizable=yes,fullscreen=no');
	//popWin.window.focus();
}

function prt_pop(pid){ 
	popWin=window.open( base_url+'index.php?module=partners&action=partnersPopup&partner_id='+pid,'partner_detales','width=554,height=330,menubar=no,status=no,location=no,toolbar=no,scrollbars=yes,resizable=yes,fullscreen=no');
	popWin.window.focus();
}

function itm_pop(iid){ 
	popWin=window.open( base_url+'index.php?module=catalog&action=itemPopup&itemId='+iid+'&no_buy=1',iid,'width=600,height=450,menubar=no,status=no,location=no,toolbar=no,scrollbars=yes,resizable=yes,fullscreen=no');
	popWin.window.focus();
	return false;
}

function crt_pop(bid){ 
	popWin=window.open( base_url+'index.php?module=cart&action=one_cart&cart_id='+bid,'cart_detales','width=554,height=500,menubar=no,status=no,location=no,toolbar=no,scrollbars=yes,resizable=yes,fullscreen=no');
	popWin.window.focus(); 
}

function invc_pop(vid){ 
	popWin=window.open( base_url+'index.php?module=cart&action=invoice_cart&cart_id='+vid,'invoice_detales','width=700,height=500,menubar=no,status=no,location=no,toolbar=no,scrollbars=yes,resizable=yes,fullscreen=no');
	popWin.window.focus(); 
}


//<block name="pop_up_prinable">,'basket_prinable','width=554,height=400,menubar=yes,status=no,location=no,toolbar=no,scrollbars=yes,resizable=yes,fullscreen=no'); popWin.window.focus(</block name="pop_up_prinable">

	/* Login form */
	function showVal(obj, text) {		
		if (obj != null && obj.value == "") {			
				obj.value = obj.id;
			
		}
	}
	
	function clearVal(obj) {
		if (obj != null && (obj.value == obj.id)) {
			obj.value = "";
		}
	}

	/* / Login form */
	
	
	/**
	*	Function to open preview popup window
	*	@param string url to open
	*	@param string type 'new' or whatever 
	*/
	function openPreview(url, type) {
		
		if (type = 'new') {
			form = document.getElementById("albumForm");
			argStr = "";
			for (i = 0; i < form.length; i++){	
				if (form.elements[i].type == 'checkbox' && form.elements[i].name == 'album[photos][]' && form.elements[i].checked == true) {
					argStr += form.elements[i].value + ";";
				}
			}
			argStr = (argStr != '') ? "&phids="+argStr : '';
		}
		window.open(url+argStr, 'previewPopup', "scrollbars=yes,toolbar=no,height=675,width=565,resizable=no,z-lock=yes")
		return false;
	}
	
	/**
	*	Submit form by given ID
	*/
	function submitForm(id) {
		form = document.getElementById(id);
		if (form != null)
			form.submit();
	}
	
	
	
	/**
	*	Confirm delete dialog box
	*
	*/
	function confirmDelete(text) {
		
		return confirm(text);
		
	}
	
	var check_state = true;
	function checkAll(){
		
		form = document.getElementById("albumForm");
		for (i = 0; i < form.length; i++){	
			if (form.elements[i].type == 'checkbox') {
				form.elements[i].checked = check_state;
			}
		}
		check_state = !check_state;
		
	}
	
	/* Login form */
	
	
	/**
	*	DIV element display
	*/
	function div_display( div_name ){
		
		div_ = document.getElementById(div_name);
		if ( div_ != null ){
			if ( div_.style.display == 'none'){
				div_.style.display = 'block'; 
			}else{ 
				div_.style.display = 'none';
			}
		}
		return false;
	}

	
	/*
	*	Rounds given float to given decimal places
	*	@param float number
	*	@param int places	 	
	*/
	function round(number, places) {
		
		if (number > 0 && places > 0) {
			inc = Math.pow(10, places);
			number = number * inc;
			number = Math.round(number);
			number = number / inc;
			return number;
		}
		else {
			return '';
		}
		
	}
	
	/**
	*	leaves two digits after point
	*/
	function round_money(price){
		
		price = Math.round(price*100)/100;
		price = price.toString(10);
		taskas = price.lastIndexOf(".");
		if (taskas==-1){
			price+=".00";
		}else{
			poTasko = price.length-taskas-1;
			if (poTasko < 2){
				price+="0";
			}
		}
		return price;
	}
		
	function me_submit() {
		document.votebar.submit();
	}
	
	/**
	*	Setting nice errors on fly
	**/
	function raiseError(msg)
	{
		document.getElementById('js_error_container').style.display = 'none';		
		document.getElementById('js_error_inside_text').innerHTML = msg;
		document.getElementById('js_error_container').style.display = 'block';
		return false;
	}
	/**
	*	Hidding error container
	*/
	
	function hideError()
	{
		document.getElementById('js_error_container').style.display = 'none';
	}
	
	/**
	*	checks are there any photos in current folder
	**/
	function showPhotos(url, type)
	{
		error = true;	
		form = document.getElementById('albumForm');
		for (i=0; i<form.elements.length; i++)
		{
			if (form.elements[i].name.indexOf('photos')>0)
			{
				error = false;
			}
		}
		
		if (!error)
		{
			openPreview(url, type);
			return false;
		}
		else
		{
			raiseError('Šiame kataloge nuotraukų nėra');
			return false;
		}
	}
	
	/***** foninio submit'o objekto funkcijos *****/
	// išvalo objektą, jei submitinamas turinys nebereikalingas
	function clear_(){
		this.cont = '';	
	}
	// prideda prie submit turinio duomenis
	// parname - parametro vardas
	//parvalue - parametro reikšmė
	function add_(parname,parvalue){
		this.cont += (this.cont==''?'':'&') + parname + '=' + parvalue;
	}
	// sinchroniškai submitina objektą - gražinamas visas atsakymo turinys
	function submit_(){
		if (window.ActiveXObject)
		{
			this.obj = new ActiveXObject("Microsoft.XMLHTTP");
		}
		this.obj.onreadystatechange = function(){};
		if(this.cont==''){
			this.obj.open('GET',this.url,false);
			this.obj.send();
		}else{
			this.obj.open('POST',this.url,false);
			this.obj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			this.obj.send(this.cont);
		}
		this.clear();
		return this.obj.responseText;
	}
	// gražina paskutinio submitinimo atsakymo turinį
	function lastresult_(){
		return this.obj.responseText;
	}
	// pagalbinė funkcija kviečiama kai įvykdomas asinchroninis submitas
	function onreadystatechangefuncimpl_(){		
		var tmp_onsubmitedfuncref;
		if(this.obj.readyState==4){
			this.clear();
			this.obj.onreadystatechange = function(){};
			
			if(this.onsubmitedfuncref){
				tmp_onsubmitedfuncref = this.onsubmitedfuncref;
				this.onsubmitedfuncref = null;
				
				if (this.return_xml)
					tmp_onsubmitedfuncref(this.obj.responseXML);
				else				
					tmp_onsubmitedfuncref(this.obj.responseText);
			}
		}
	}
	// asinchroniškai submitina objektą
	// callbackfunc - jei perduotas šis parametras, tai gavus rezultatą, 
	//				ši funkcija bus iškviesta su atsakymo tekstu kaip vieninteliu parametru
	function submitasync_(callbackfunc){
		if (window.ActiveXObject)
		{
			this.obj = new ActiveXObject("Microsoft.XMLHTTP");
		}
		this.obj.onreadystatechange = this.onreadystatechangefuncref;
		this.onsubmitedfuncref = ((typeof(callbackfunc)=='string')?eval(callbackfunc):callbackfunc);		
		if(this.cont==''){			
			this.obj.open('GET',this.url,true);
			this.obj.send();
		}else{			
			this.obj.open('POST',this.url,true);
			this.obj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			this.obj.send(this.cont);
		}
	}
	
	function datasubmit(oid,url,xml_true){
		this.myid = oid;
		this.url = url;
		if (xml_true)
			this.return_xml = true;
		else
			this.return_xml = false; 
		this.cont = '';
		if (window.XMLHttpRequest) // Mozilla, Opera etc.
		{
			this.obj = new XMLHttpRequest();			
		}		
		this.clear = clear_;
		this.add = add_;
		this.submitasync = submitasync_;
		this.submit = submit_;
		this.lastresult = lastresult_;
		this.onreadystatechangefuncref = new Function(this.myid+'.onreadystatechangefuncimpl();');
		this.onreadystatechangefuncimpl = onreadystatechangefuncimpl_;
		this.onsubmitedfuncref = null;
	}
	
	function get_xml_doc(xml_string)
	{
		var doc = '';
		if (document.all)
		{			
			doc = xml_string;
		}
		else if (DOMParser)
		{
			var parser = new DOMParser();
			doc = parser.parseFromString(xml_string, "text/xml");
		}		
		
		return doc;
	}
	
	
	function select_fill_list_xml(select_id, xml_doc, keys, reset){
		
		var i;		
		var select_list = parent.document.getElementById( select_id );
		if (select_list == null){			
			return false;
		}
		
		var keys_row = 'row';
		var keys_name = 'name';
		var keys_value = 'value';
		var keys_selected = 'selected';
		if (keys != null){
			if( keys[0] != null ) keys_row = keys[0];
			if( keys[1] != null ) keys_name = keys[1];
			if( keys[2] != null ) keys_value = keys[2];
			if( keys[3] != null ) keys_selected = keys[3];
		}
		
		
		var xmldoc = xml_doc;
		var root = xmldoc.getElementsByTagName( keys_row );
		
		if (reset){			
			//select_list.options.length = 0;
			while(select_list.length) select_list.remove(0);
		}
		selected_index = 0;
		
		j = select_list.length;
		
		for (i=0; i < root.length; i++)
		{			
			var item = root[i];
			if (item.getElementsByTagName( keys_name )[0].firstChild != null){
				var name = item.getElementsByTagName( keys_name )[0].firstChild.nodeValue;
				var id = item.getElementsByTagName( keys_value )[0].firstChild.nodeValue;
			}else{
				var name = '';
				var id = '';
			}
			if (item.getElementsByTagName( keys_selected )[0] != null){				
				selected_index = i + j;
			}

			select_list.options.add( new Option (name, id) );
			//select_list.options[select_list.options.length] = new Option (name, id);
		}
		
		select_list.selectedIndex = selected_index;
		
	}

	
	
	/**
	*	indicate bad form entry fields		
	*/
	function form_bad_fields_indicate(errors, form_id){

		form = document.getElementById( form_id );
		if (errors[0] == null || form == null){
			for (i = 0; i < form.length; i++){
				form.elements[i].className = 'form_input_';
			}
			return true;
		}
		
		for (i = 0; i < form.length; i++){	
			for (j = 0; errors[j] != null; j++){				
				if (form.elements[i].name == ('f['+errors[j]+']')){
					//form.elements[i].style.border = '1px solid red';
					form.elements[i].className = 'form_input_1';
				}else{
					form.elements[i].className = 'form_input_';
				}
			}
		}
		return false;
	}

	
	/* 
		showing content from iframe, to given element by id
	*/
	function showContent(doc, id)
	{	
		var source = doc.body.innerHTML;
		var targetDiv = document.getElementById(id);				
		if (targetDiv)
		{
			targetDiv.innerHTML = source;
		}
		
	}
	
	
	
	
	
	
	
	
	
	
	
	function swapImage(id, offer)
	{
	
		for (i=1; i<links.length; i++)
		{			
			document.getElementById('link_'+links[i]).className = "";
		}
		if (offer)
		{
			var src = base_url+"lib/image.jpg.php?5;2;1;"+id;
		}
		else
		{			
			var src;
			for (i=1; i<prev_images.length; i++)
			{
				if (prev_images[i].catalog_id == id)
				{					
					src = prev_images[i].src;					
				}
			}
		}
		document.getElementById('item_img').src = src;		
		document.getElementById('link_'+id).className = "active";		
		return false;
	}
	
