﻿function onSelectSiteChanged(selectSiteCtlId, selectedPath, selectedPathId)
{
    var paramsArr = new Array(2);
    
    paramsArr[0]=selectedPath;
    paramsArr[1]=selectedPathId;
     __doPostBack(selectSiteCtlId, paramsArr);
}

function __doPostBack(eventTarget, eventArgument) {
    var theform = document.form1;
 	theform.__EVENTTARGET.value = eventTarget;
 	theform.__EVENTARGUMENT.value = eventArgument;
 	theform.submit();
}



var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};

/*********************************************/


function getObject(id) {
    if(document.getElementById) {
        obj = document.getElementById(id);
    }
    else if(document.all) {
        obj = document.all.item(id);
    }
    else {
        obj = null;
    }
    return obj;
}
function loadDragElements() {
    _spBodyOnLoadWrapper();
    var theHandle = getObject("MSOTlPn_ToolPaneCaption");
    var theRoot = getObject("MSOTlPn_Tbl");
    if(theHandle != null && theRoot != null) {
        Drag.init(theHandle, theRoot);
    }
}


/*************************/




 var rotate_delay = 2000; // delay in milliseconds (5000 = 5 secs)
    current = 0;
    var imgSlider = null;
    var imgSliderbutton = null;
    var namesSlider = null;
    var datesSlider = null;
    var descSlider = null;
    var txtName = null;
    var txtDesc = null;
    var txtDate = null;
    
    function init()
    {
        if( imgSlider == null )
            imgSlider = document.getElementById('ddlslide');
        if( namesSlider == null )
            namesSlider = document.getElementById('ddlslidename');
       
        if( descSlider == null )
            descSlider = document.getElementById('ddlslidedesc');
            
        if( datesSlider == null )
            datesSlider = document.getElementById('ddlslidedate');
            
       if(imgSliderbutton == null )
            imgSliderbutton = document.getElementById('imgSliderbutton');
            
        if(txtName == null )
            txtName = document.getElementById('txtName');

        if(txtDesc == null )
            txtDesc = document.getElementById('txtDesc');

        if(txtDate == null )
            txtDate = document.getElementById('txtDate');

    }

    function getFormatDate(str)
    {
        if( str == null )
            return "";
        
        if( str.length > 10)
            return str.substring(0,10);
        else
           return str;
    }
    function next() {
        init();
        if( imgSlider != null)
        {   
            if (imgSlider[current+1]) {
                document.images.show.src = imgSlider[current+1].value;
                txtName.innerHTML = namesSlider[current+1].value;
                txtDesc.innerHTML = descSlider[current+1].value;
                txtDate.innerHTML = getFormatDate(datesSlider[current+1].value);
                imgSlider.selectedIndex = ++current;
           }
           else first();
        }
    }
    

    function previous() {
        init();
        if( imgSlider != null)
        {
            if (current-1 >= 0) {
                document.images.show.src = imgSlider[current-1].value;
                 txtName.innerHTML = namesSlider[current-1].value;
                txtDesc.innerHTML = descSlider[current-1].value;
                txtDate.innerHTML = getFormatDate(datesSlider[current-1].value);
                imgSlider.selectedIndex = --current;
        }
        else last();
        }
    }

    function first() {
        init();
        if( imgSlider != null)
        {
            current = 0;
            document.images.show.src = imgSlider[current].value;
            txtName.innerHTML = namesSlider[current].value;
                txtDesc.innerHTML = descSlider[current].value;
                txtDate.innerHTML = getFormatDate(datesSlider[current].value);
            imgSlider.selectedIndex = 0;
        }
    }
    function last() {
        init();
        if( imgSlider != null)
        {
            current = imgSlider.length-1;
            document.images.show.src = imgSlider[current].value;
            txtName.innerHTML = namesSlider[current].value;
                txtDesc.innerHTML = descSlider[current].value;
                txtDate.innerHTML = getFormatDate(datesSlider[current].value);
            imgSlider.selectedIndex = current;
        }
    }
    function ap(text) {
        init();
        if( imgSlider != null)
        {
            imgSliderbutton.value = (text == "Stop") ? "Start" : "Stop";
            rotate();
        }
    }
    function change() {
        init();
        if( imgSlider != null)
        {
            current = imgSlider.selectedIndex;
            document.images.show.src = imgSlider[current].value;
            txtName.innerHTML = namesSlider[current].value;
                txtDesc.innerHTML = descSlider[current].value;
                txtDate.innerHTML = getFormatDate(datesSlider[current].value);
        }
    }
    function rotate() {
        init();
        if( imgSlider != null)
        {
            if (imgSliderbutton.value == "Stop") {
                imgSliderbutton.src = "/TLVResources/Images/Slideshow/but_paus.gif";
                current = (current == imgSlider.length-1) ? 0 : current+1;
                document.images.show.src = imgSlider[current].value;
                txtName.innerHTML = namesSlider[current].value;
                txtDesc.innerHTML = descSlider[current].value;
                txtDate.innerHTML = getFormatDate(datesSlider[current].value);
                imgSlider.selectedIndex = current;
                window.setTimeout("rotate()", rotate_delay);
            }
            else
                imgSliderbutton.src = "/TLVResources/Images/Slideshow/but_play.gif";
       }
    }
    function SetImgSrc(oImg, sSrc)
    {
       if(oImg != null)
         oImg.src = "/TLVResources/Images/Slideshow/" + sSrc;
    }




		var tabsImages= null;
		var lastTab = 0;
		
		function InitializeTabsImgs()
		{
			tabsImages= new Array(6);
			tabsImages[0] = document.getElementById("PagesTab");
			tabsImages[1] = document.getElementById("NewsTab");
			tabsImages[2] = document.getElementById("EventsTab");
			tabsImages[3] = document.getElementById("ProjectsTab");
			tabsImages[4] = document.getElementById("UsersContentTab");
			tabsImages[5] = document.getElementById("CityVisitTab");
		}
		function SetSelected(tabIndex)
		{
			if (lastTab == 0 && tabIndex == 0)
			{    
			    tabsImages[tabIndex].src = tabsImages[tabIndex].src.replace("normal","press");
			}
			else if( tabsImages[lastTab] != null && tabsImages[tabIndex] !=  null)
		    {
		        tabsImages[tabIndex].src = tabsImages[tabIndex].src.replace("normal","press");			        
			    tabsImages[lastTab].src = tabsImages[lastTab].src.replace("press","normal");
    		    lastTab = tabIndex;
			}
		}		
		function ChangeTabBackground()
		{
			if( tabsImages == null )
				InitializeTabsImgs();
			
			var localURL = window.location.href;
			var firstIndex = localURL.indexOf("EN/",10)+3;
			var lastIndex = localURL.indexOf("/",firstIndex);
		
			localURL = localURL.substring(firstIndex, lastIndex);
			
			switch(localURL)
			{
				case "Pages": 
				SetSelected(0); 
				break;    
				case "News" : 
				SetSelected(1); 
				break;    
				case "Events": 
				SetSelected(2); 
				break;
				case "Projects": 
				SetSelected(3); 
				break;
			    case "UsersContent": 
			    SetSelected(4); 
			    break;
				case "CityVisit": 
				SetSelected(5); 
				break;	
				
				default:
				break;
			} 	
		}
		
function PrintPage(WindowUrl)
{

    try
    {
        var sUrl;
        sUrl = WindowUrl + "?IsPrint=true";
        window.open(sUrl,null,"status=no,toolbar=no,menubar=no,resizable=1,scrollbars=1, width=600, height=600");
    }
     catch(e)
    {
        // alert('PrintPage Error: ' + e.message + ' occurred.'); 
    }
}
function ChangeDivBg(divid,bgLink)
{

try
{
var  path,desc,commaindex;
commaindex = bgLink.indexOf(',',0);
path=bgLink.substring(0,commaindex);
desc=bgLink.substring(commaindex,bgLink.length-1);
var divBgTochange =document.getElementById(divid);
divBgTochange.style.backgroundImage ="url('"+path + "')";
}
catch(ex)
{}
}			