// JavaScript Document
function submit_query(formName, actionName, actionValue) {
	var form_obj = eval("document."+formName);
	eval("window.document."+formName+"."+actionName).value = actionValue;
	return true;
}
function submit_query_prompt(formName, actionName, actionValue, msg) {
	if ((msg != "") && (!window.confirm(msg))) {
		return false;
	}
	return submit_query(formName, actionName, actionValue);
}
function clearInput(formName, inputName) {
	eval("document."+formName+"."+inputName).value = '';
}
function view_image(path, width, height, id) {
	//window.confirm(path);
	//window.location = "admin/popup/view_image.php?"+path;
	pop = popup("units/catalog/view_image.php?file="+path+"&id="+id, "popup", width, height, false, false, 50, 150);
}
function popup(url){
	xPos = window.screenLeft+10;
	yPos = window.screenTop+20;
	win = window.open(url, 'filepopup', "width=500,height=300,left="+xPos+",top="+yPos+",scrollbars=yes,resizable=yes,toolbars=no");
}
function popupbyname(url){
	var img=new Image();
	img.onload=function() {
		var w=this.width;
		var h=this.height;
		
		xPos = window.screenLeft+10;
		yPos = window.screenTop+20;
		win = window.open(url, 'filepopup', "width="+w+",height="+h+",left="+xPos+",top="+yPos+",scrollbars=no,resizable=yes,toolbars=no");
	}
	img.src=url;
	
	
}
function toggleDiv(id){
	obj = document.getElementById(id);
	tmp = obj.style.display;
	if (tmp == 'none') obj.style.display='block';
	else obj.style.display='none';
}
function show_basket() {
	param = "top=150,left=150,width=630,height=500,scrollbars,resizable";
	popupwindow = window.open(siteUrl + "/basket/", "BasketWindow", param);
}
function getid(id){
	return document.getElementById(id);
}
function smart_hyperlinks() {
	try {
		links = document.links
		if (links.length) {
			var current_location      = window.location.href
			current_location          = current_location.toString()
			current_location_relative = current_location.replace(/^[a-z]+\/\/[^\/]+/, '')
			var i = 0
			var node, href, inner, span;
			while (node = links.item(i++)) {
				href = node.getAttribute('href')
				href = href.toString()
				if (!href || 
					(href == current_location) || 
					(href == current_location+"#") || 
					(href == current_location+"/#") || 
					(href == current_location_relative) || 
					(href == current_location_relative+"#") || 
					(href == current_location_relative+"/#") || 
					(href == "./") || 
					(href == "#") || 
					(href == "./#")) {
					node.removeAttribute('href')
				}
			}
		}
	} catch (e) {
		alert(e.message)
	}
}
function showhide(arr) {
	if (arr.length > 0) {
		for (var i=0; i<arr.length; i++) {
			toggleDiv(arr[i]);
		}
	}
}
var k=0;
function getchildes () {
	var main_ul=document.getElementById('gallery');
	var li=main_ul.getElementsByTagName('LI');
	for (var i=0;i<li.length;i++) {
		if (li[i].className=="wn") {
			span=li[i].getElementsByTagName('span');
			span[0].onclick=function() {
				var l=this.parentNode;
				var main_ul=document.getElementById('gallery');
				
				var ul=l.getElementsByTagName('UL');
				if (ul[0].style.display=='none') {
					ul[0].style.display='block';
					this.style.borderColor="#f8963d";
					this.style.color="#f8963d";
					if (l.parentNode!=main_ul) {
					this.style.fontWeight="bold";
					l.style.background="url(../img/gar2.gif) left 0.2em no-repeat";
					}
					
				}
				else {
					ul[0].style.display='none';
					this.style.borderColor="#000";
					this.style.color="#000";
					if (l.parentNode!=main_ul) {
						this.style.fontWeight="bold";
						this.style.color="#28517f";
						this.style.borderColor="#28517f";
						this.style.fontWeight="normal";
						l.style.background="url(../img/gar.gif) left 0.4em no-repeat";
					}
				}
			}
		}
	}
}
function open_closetree () {
	var main_ul=document.getElementById('ttree');
	var imgs=main_ul.getElementsByTagName('IMG');
	var divs=main_ul.getElementsByTagName('DIV');
	//var img=document.getElementById(id);
	for (j=0; j<imgs.length;j++) {
		imgs[j].onclick=divs[j].onclick= function() {
			var parent=this.parentNode;
			if (this.nodeName=="DIV") {
				var ii=this.previousSibling;
				if(ii.nodeName!="IMG") {
					ii=ii.previousSibling;
				}
				
			}
			if (parent.hasChildNodes) {
				var nodes=parent.childNodes;
				 
				for (var z=0;z<nodes.length;z++) {
						if (nodes[z].nodeName=="UL") {
							k=1;
						}
				}
			
				if (k==1) {
					this.src="minus.gif";
					if (this.nodeName=="DIV") {
						
						ii.src=siteURL+"img/minus.gif";
					}
					k=0; 
				}
			 
				for (var i=0;i<nodes.length;i++) {
					if (nodes[i].nodeName=="UL") {
						if (nodes[i].style.display=='none') {
							nodes[i].style.display="block";
						}
						else {
							nodes[i].style.display="none";
							this.src=siteURL+"img/plus.gif";
							if (this.nodeName=="DIV") {
							ii.src=siteURL+"img/plus.gif";
							}
						}
					}
				}
			}
		}
	}
}
function open_ul(elem, id, dir, path){
	var l=elem.parentNode;
	var ul=l.getElementsByTagName('UL');
	var main_ul=document.getElementById('gallery');
	
	if(ul[0].innerHTML==''){
		dk_JsHttpRequest_foto(elem, id, dir, path);
		
	}else{
		if (ul[0].style.display=='none') {
			ul[0].style.display='block';
			elem.style.borderColor="#f8963d";
			elem.style.color="#f8963d";
			if (l.parentNode!=main_ul) {
				elem.style.fontWeight="bold";
				
				l.style.background="url("+siteURL+"/img/gar2.gif) left 0.2em no-repeat";
			}
			
		}
		else {
			ul[0].style.display='none';
			elem.style.borderColor="#000";
			elem.style.color="#000";
			if (l.parentNode!=main_ul) {
				elem.style.fontWeight="bold";
				elem.style.color="#28517f";
				elem.style.borderColor="#28517f";
				elem.style.fontWeight="normal";
				l.style.background="url("+siteURL+"/img/gar.gif) left 0.4em no-repeat";
			}
		}
	}
}
function close_all() {
	var video_list=$('.video-list').eq('0').find('.b-video');
	for (var i=0;i< video_list.length;i++) {
		video_list.eq(i).hide();
		
	}
	$('.video-list .b-video-theme span').css('border-bottom-width','1px');
	
}
function show_all() {
	var video_list=$('.video-list').eq('0').find('.b-video');
	for (var i=0;i< video_list.length;i++) {
		video_list.eq(i).show();
			
	}
	$('.video-list .b-video-theme span').css('border-bottom-width','0');
}
$(document).ready(function(){
    if($.browser.msie) {
    /* Turn BackgroundImageCache on */
    try {
      document.execCommand('BackgroundImageCache', false, true);
    } catch(e) {}

    /* Force reflow */

  }
    $('.b-tabs dt').click(
        function(e) {
          if  (!$(this).hasClass('b-selected')) {
            var parent=$(this).parents('.b-tabs');
            var i=parent.find('dt').index($(this));
            var dd=parent.find('dd');
            dd.hide();
            dd.eq(i).show();
            parent.find('dt.b-selected').removeClass('b-selected');
            $(this).addClass('b-selected');
            //ajax here
          }
        }
   );
   $('#message button[type="submit"]').click(function(el){
       return true;
   });
   if ($('.datepicker').length) {
    $('.datepicker').datepicker({
        showOn: 'button',
        constrainInput:false,
        buttonImage: '../img/datepicker.png',
        buttonImageOnly: true,
        showAnim: 'fadeIn',
        altField: '#first-data',
        yearRange: '2010:2012'});
    $('.datepicker2').datepicker({
        showOn: 'button',
        constrainInput:false,
        buttonImage: '../img/datepicker.png',
        buttonImageOnly: true,
        showAnim: 'fadeIn',
        altField: '#second-data'});
   }
    $('.b-popup .b-close').click(function(){
    $(this).parent().parent().hide();
    });
    $('.b-popup button[type="reset"]').click(function(){
        $(this).parents('.b-popup').hide();
        return false;
    });
    $('.b-delete').click(function(){
       var handler = $(this).attr("id");
       handler = handler.split("-");
       $("#remove_action").attr("value", handler[0]);
       $("#remove_attr").attr("value", handler[1]);
       $('#message').show();
       return false;
    });
    /*
    $('.b-sortable-data').tablesorter({
        // pass the headers argument and assing a object
        headers: {
            // assign the secound column (we start counting zero)
            0: { 
                // disable it by setting the property sorter to false
                sorter: false
            },
            // assign the third column (we start counting zero)
            2: {
                // disable it by setting the property sorter to false
                sorter: false
            }
        }
    });*/
});


	



