var Azertag={
    currentDate: null,
    calendarDate: null,
    currentDirectory: 'news',
    currentFuncRef: null,
    currentParition: null,
    currentPartitionCaption: null,
    HeadLinesObj: null,
    HeadLines: new Array(),
    parts:new Array(),
    getTempParts: function(){
        ajaxRequest("/jsp/AGetParts.jsp",'type=temp&lang='+Settings.lang,Azertag.afterGetTempParts);  
    },
    afterGetTempParts: function(originalRequest){
        document.getElementById('topContent').style.display = 'block';
	document.getElementById('newsBlock').style.display = 'block';
	document.getElementById('newsContent').style.display = 'block';
	document.getElementById('photoContent').style.display = 'block';
        //var parts = [Settings.mainPage[0], Settings.mainPage[1]];
        var doc = originalRequest.responseXML;
        if(doc != null){
           var partitions = doc.getElementsByTagName('partition');
           if(partitions.length>0){ 
              for(i=0; i<partitions.length; i++){
                  var partName = partitions[i].getAttribute("name");
                  var partNameId = partitions[i].getAttribute("id");
                  Azertag.parts[Azertag.parts.length] = {caption: partName, id: partNameId, actual: false}; 
              }
           }
        }
        /*for(i = 1; i < Settings.mainPage.length; i++){
        	Azertag.parts[Azertag.parts.length] = Settings.mainPage[i];
        }*/
        //parts[parts.length] = Settings.mainPage[2];
        //Settings.mainPage = parts;
        Azertag.getCurrentDate();
    },
    getCurrentDate: function(){
        ajaxRequest("/jsp/ACurrentDate.jsp",'',Azertag.afterGetCurrentDate);
    },
    indexPages: function(){
    	    window.location = "index_"+Settings.lang+".jsp";
    },
    afterGetCurrentDate: function(originalRequest){
    	
        var doc = originalRequest.responseXML;
        var response = doc.getElementsByTagName('response').length>0?doc.getElementsByTagName('response')[0]:null;
        if(response != null){
            Counter.get();
            var date = response.getAttribute('date');
            Search.currentDate = date;
            Azertag.calendarDate = Azertag.currentDate = date;
            if(Searched.isSearched){
            	    //Azertag.currentFuncRef = Azertag.indexPages; 
            	    iframeNewsLoad();
            }else{ 
            	    Partition.get2('1',Settings.mainLoadNews);
            	    MainPage.get();
            }
            Azertag.drawDate();//+
            DaysPhoto.get();//+
            Weather.get();//-
            Currency.get();//-
            //RunLine.get();//+
            Calendar.get();//-
            Notes.get();//+
            DayNews.get();
            Analyst.get();//+
            //LastNews.get();
            PhotoGallery.getSlide();
            Banners.get(Settings.mainPage.length-1);
            LentaNews.get();
        }     
    },
    drawDate: function(){
        var currentArray = Azertag.currentDate.split('-');
        var dateStr = currentArray[2] + ' ' + Settings.months[currentArray[1]-1] + ', ' + currentArray[0];

         document.getElementById('currentDate').innerHTML = dateStr;
    },
    topMenuRollover: function(evt,elem){
        if(evt.type=="mouseover"){
            elem.style.color = '#FF6801';
        }
        if(evt.type=="mouseout"){
            elem.style.color = '#0076CA';
        }
    },
    locOver: function(element){
        if(Azertag.currentDirectory != element.id.substr(4)){
             element.className = 'nonSelectedTabOver';
        }
    },
    locOut: function(element){
        if(Azertag.currentDirectory != element.id.substr(4)){
            element.className = 'nonSelectedTab';
        }
    },
    locClick: function(element){
        if(Azertag.currentDirectory != element){
            //document.getElementById('loc_'+Azertag.currentDirectory).className = 'nonSelectedTab';
            //element.className = 'selectedTab';
            //Azertag.currentDirectory = element.id.substr(4);
            if(Azertag.currentDirectory == 'news'){
                if(Azertag.currentPartition == null){
                    Azertag.currentFuncRef();
                }  
                else{
                    Azertag.currentFuncRef(Azertag.currentPartition, Azertag.currentPartitionCaption);
                }
            }
            if(Azertag.currentDirectory == 'gallery'){
                PhotoGallery.get(1); 
            }
        }
    }
}



var DaysPhoto = {
    photos: [],
    currentImg: 0,
    get: function(){
         ajaxRequest("/jsp/AGetPhotoOfTheDay.jsp","lang="+Settings.lang+"&date="+Azertag.currentDate, DaysPhoto.afterGet);
    },
    afterGet: function(originalRequest){
        var doc = originalRequest.responseXML;
        var items = doc.getElementsByTagName('item');
        for(i=0; i<items.length; i++){
            var id = items[i].getAttribute('fid');
            var date = items[i].getAttribute('fdate');
            var path = "" + items[i].getAttribute('fpath');
            var caption = items[i].firstChild.nodeValue;
            DaysPhoto.photos[DaysPhoto.photos.length] = {fid: id, fdate: date, fpath: path, fcaption: caption};           
        }
        DaysPhoto.run();
    },
    run: function(){
       if(DaysPhoto.photos.length > 0){
         var outHtml = '<img src="'+DaysPhoto.photos[DaysPhoto.currentImg].fpath+'" title="'+DaysPhoto.photos[DaysPhoto.currentImg].fcaption+'" width="185" border="0" onload="DaysPhoto.load();">';
         document.getElementById('daysPhoto').innerHTML = outHtml;
         if(DaysPhoto.currentImg < DaysPhoto.photos.length-1){
            DaysPhoto.currentImg++;
         }
         else{
            DaysPhoto.currentImg = 0;
         }
       } 
    },
    load: function(){
        if(DaysPhoto.photos.length > 1){
            window.setTimeout(DaysPhoto.run, 10000);
        }    
    }
}

var PhotoGallery = {
    get: function(arg){
    	//document.getElementById('calendarCaption').innerHTML = Settings.archivePhoto;
        Azertag.currentDirectory == 'gallery';
    	Azertag.locClick("gallery");
    	PhotoGallery.parttittion=""+arg;
        document.getElementById('photoContent').innerHTML = '';
        Azertag.currentDirectory = 'photoContent';
        
        if(document.getElementById('contentSearch') != null)
        	document.getElementById('contentSearch').style.display = 'none';
        document.getElementById('photoContent').style.display = 'block';
        document.getElementById('topContent').style.display = 'none';
	document.getElementById('newsBlock').style.display = 'none';
	document.getElementById('newsContent').style.display = 'none';
	document.getElementById('calendarContent').style.display = 'none';
	
        //document.getElementById('loc_news').className = 'nonSelectedTab';
        //document.getElementById('loc_gallery').className = 'selectedTab';
        ajaxRequest("/jsp/AGetGalleryPartitions.jsp","lang="+Settings.lang+"&part="+arg, PhotoGallery.afterGetPartitions);
    },
    afterGetPartitions: function(originalRequest){
        var doc = originalRequest.responseXML; 
        var partitions = doc.getElementsByTagName("partition"); 
        if(partitions.length > 0){
            for(i = 1; i<partitions.length; i++){
                var element = document.createElement('div');
                outHTML =  '<div class="art-Block"><div class="art-Block-body"><div class="art-BlockHeader4"><div class="l"></div><div class="r"></div><div class="t" >'+partitions[i].getAttribute("name")+'</div></div>';
                outHTML += '<div class="art-BlockContent4"><div class="art-BlockContent4-tl"></div><div class="art-BlockContent4-tr"></div><div class="art-BlockContent4-bl"></div><div class="art-BlockContent4-br"></div><div class="art-BlockContent4-tc"></div><div class="art-BlockContent4-bc"></div><div class="art-BlockContent4-cl"></div><div class="art-BlockContent4-cr"></div><div class="art-BlockContent4-cc"></div><div class="art-BlockContent4-body">';
                outHTML += '<div class="mainBorder" id="photoContainer_'+partitions[i].getAttribute("id")+'" style="display: none; width:100%;">'+
                       '<div id="photos_'+partitions[i].getAttribute("id")+'"></div></div><div style="height:10px;"></div></div>';
                outHTML += '</div></div></div></div><div class="art-Header" style="height:3px;"></div>';
                element.innerHTML = outHTML;
                
                document.getElementById('photoContent').appendChild(element);
                ajaxRequest("/jsp/AGetGallery.jsp","lang="+Settings.lang+"&partition="+partitions[i].getAttribute("id")+"&date="+Azertag.currentDate, PhotoGallery.afterGet);
            }    
        }  
    },
    parttittion:null,
    afterGet: function(originalRequest){
    	    
        var doc = originalRequest.responseXML;
        var partitions = doc.getElementsByTagName('partition');
        var part = (partitions.length>0)? partitions[0].getAttribute('id'): null;
        if(part == null) return;
        var items = doc.getElementsByTagName('item');
        var columns = 3;
        if(items.length > 0){
            var rows = (items.length%columns > 0) ? (Math.floor(items.length/columns)+1) : (Math.floor(items.length/columns));
            var outHTML = '<table border="0" cellpadding="5" cellspacing="5" width="100%">';
            for(i=0; i<items.length; i++){
                var id = items[i].getAttribute('fid');
                var date = items[i].getAttribute('fdate');
                var path = items[i].getAttribute('fpath');
                var width = items[i].getAttribute('width');
                var height = items[i].getAttribute('height');
                var access = items[i].getAttribute('access');
                var partdate = items[i].getAttribute('partdate');
                var caption = items[i].firstChild.nodeValue;
                var row = ((i+1)%columns > 0) ? (Math.floor((i+1)/columns)+1) : (Math.floor((i+1)/columns));
                var column = Math.floor((i)%columns)+1;
                var img = '';
                if(PhotoGallery.parttittion == "10"){
                 access = 'true';
                 img = '<div><img src="/jsp/AGetGalleryThumbnail.jsp?width='+width+'&height='+height+'&path='+path+'" onMouseOut="hidePic()" onMouseOver="openbox(this);" fid="'+id+'" fdate="'+date+'" style="cursor:pointer; border:1px solid #DBDBDB;" title="'+caption+'" dwidth="'+width+'" dheight="'+height+'" partition="'+part+'" partdate="'+partdate+'"/></div>';
                 }
                if(access == 'false') img = '<img src="/jsp/AGetGalleryThumbnail.jsp?width='+width+'&height='+height+'&path='+path+'" title="'+caption+'" style="border:1px solid #DBDBDB;">';
                else if(PhotoGallery.parttittion != "10") img = '<img src="/jsp/AGetGalleryThumbnail.jsp?width='+width+'&height='+height+'&path='+path+'" onclick="PhotoGallery.getFull(this);" fid="'+id+'" fdate="'+date+'" style="cursor:pointer; border:1px solid #DBDBDB;" title="'+caption+'" dwidth="'+width+'" dheight="'+height+'" partition="'+part+'" partdate="'+partdate+'">';
                if(column == 1) outHTML +='<tr><td align="center" class="photoContainer">'+img+'</td>';
                else if(column == columns) outHTML +='<td align="center" class="photoContainer">'+img+'</td></tr>';
                else outHTML +='<td align="center" class="photoContainer">'+img+'</td>';
                if(row == rows && column < columns && i == (items.length-1)){
                    for(j=1; j<=(columns-column); j++){
                        outHTML +='<td>&nbsp;</td>';
                    }    
                    outHTML += '</tr>';
                }
            }
            outHTML += '</table>';
            
            document.getElementById('photos_'+part).innerHTML = outHTML;
            
            document.getElementById('photoContainer_'+part).style.display = 'block';
        }
    },
    getSlide: function(){
                ajaxRequest("/jsp/AGetGallery.jsp","lang="+Settings.lang+"&partition=8"+"&date="+Azertag.currentDate, PhotoGallery.afterGetSlide);
                
    },
    afterGetSlide: function(originalRequest){ 
        var doc = originalRequest.responseXML;
        var partitions = doc.getElementsByTagName('partition');
        var part = (partitions.length>0)? partitions[0].getAttribute('id'): null;
        if(part == null) return;
        var items = doc.getElementsByTagName('item');
        var columns = 4;
        if(items.length > 0){
            var rows = (items.length%columns > 0) ? (Math.floor(items.length/columns)+1) : (Math.floor(items.length/columns));
            var outHTML = '<div id="slide-show"><ul id="slide-images">';
            for(i=0; i<items.length; i++){
                var id = items[i].getAttribute('fid');
                var date = items[i].getAttribute('fdate');
                var path = items[i].getAttribute('fpath');
                var width = items[i].getAttribute('width');
                var height = items[i].getAttribute('height');
                var access = items[i].getAttribute('access');
                var partdate = items[i].getAttribute('partdate');
                var caption = items[i].firstChild.nodeValue;
                var row = ((i+1)%columns > 0) ? (Math.floor((i+1)/columns)+1) : (Math.floor((i+1)/columns));
                var column = Math.floor((i)%columns)+1;
                var img = '';
                if(access == 'false') img = '<li><img src="'+path+'" alt="'+caption+'" title="'+caption+'" /></li>';
                else img = '<li><img src="'+path+'" alt="'+caption+'" title="'+caption+'" /></li>';
                outHTML+=img;
            }
            outHTML += '</ul></div>';
            document.getElementById('BakuToday'+part).innerHTML = outHTML;
            if(part != "9" ) {
            	ajaxRequest("/jsp/AGetGallery.jsp","lang="+Settings.lang+"&partition=9"+"&date="+Azertag.currentDate, PhotoGallery.afterGetSlide);
            }
            init();
            //document.getElementById('BakuToday'+part).style.display = 'block';
        }
    },
    getFull: function(element){
       var width = element.getAttribute('dwidth');
       var height = element.getAttribute('dheight');
       var title = element.getAttribute('title');
       var fid =  element.getAttribute('fid');
       var fdate =  element.getAttribute('fdate');
       var partition =  element.getAttribute('partition');
       var rdate = element.getAttribute('partdate');
       var lang = Settings.lang;
       var maxSize = 600;
       if(width >= height &&  width > maxSize){
           height = Math.floor(height*maxSize/width);
           width = maxSize;
       }
       else if(width < height &&  height > maxSize){
           width = Math.floor(width*maxSize/height);
           height = maxSize;
       }
       var content = '<div><img src="/jsp/AGetGalleryFull.jsp?partition='+partition+'&rdate='+rdate+'&lang='+lang+'&fid='+fid+'&fdate='+fdate+'" title="'+title+'" style="border: solid 1px black;" width="100%" height="100%"></div>';
       PopupWindow.openPhoto(width,height,title,content);
    },
   gClose: function(element){
   //PopupWindow.oWindowPhoto.document.close();
   //PopupWindow.oWindowContent.close();
   PopupWindow.oWindowPhoto.close();
   
   } 	
}

Calendar = {
    data:{fromYear:2003, year:null, month:null, day:null, monthsNames:null, weekDays:null, clickYear:null, clickMonth:null, clickDay:null},
    monthNum:1,
    get: function(){
    	document.getElementById("calendarCaption").innerHTML = Settings.archiveNews;//archivePhoto
        container = 'calendar';
        var currentArray = Azertag.currentDate.split('-');
        Calendar.data.monthsNames = Settings.calendarMonths;
        Calendar.data.weekDays = Settings.weekDays; 
        Calendar.data.clickYear = Calendar.data.year = currentArray[0];
        Calendar.data.clickMonth = Calendar.data.month = currentArray[1];
        Calendar.data.clickDay = Calendar.data.day = currentArray[2];
        var monthSelect = '';//'<select onchange="Calendar.changeMonth(this);" id="calMonth" class="CalendarSelect">';
        for(i = 0; i<Calendar.data.monthsNames.length; i++){
        	if(i == Calendar.data.month-1){
        		monthSelect += '<span class="monthSelect" id="monthSelectId">'+Calendar.data.monthsNames[i]+'</span>';
        		Calendar.monthNum = i+1;
                }
                //monthSelect += '<option value="'+(i+1)+'" selected>'+Calendar.data.monthsNames[i]+'</option>';
            //else 
                //monthSelect += '<option value="'+(i+1)+'">'+Calendar.data.monthsNames[i]+'</option>';
        }
        //monthSelect += '</select>';
        var yearSelect = '';//'<select onchange="Calendar.changeYear(this);" id="calYear" class="CalendarSelect">>';

        for(i = Calendar.data.year; i>=Calendar.data.fromYear; i--){
            yearSelect += '<option value="'+i+'">'+ i+'</option>';
        }

        document.getElementById(container).innerHTML = '<table border="0" cellpadding="0" cellspacing="0" width="100%" height="173px">'+
        '<tr><td><tr><td align="right" style="width:35px;"><img src="images/calendar_l.gif" style="cursor:pointer" onclick="Calendar.setMonth(true)"/></td><td align="center" style="width:120px;">'+monthSelect+'</td><td style="width:30px;"><img src="images/calendar_r.gif" style="cursor:pointer" onclick="Calendar.setMonth(false)" /></td></tr>'+
                                     
                                     '<tr><td id="inCalCont" colspan="3" valign="middle" height="135px"></td></tr>'+
                                     '<tr><td colspan="7" align="right">'+
                                     //'<span id="yearSelectId" style="cursor:pointer" onclick="openboxYear(\''+yearSelect+'\');">'+Calendar.data.year+'</span>'+
                                     '<select class="calYearSel" onchange="Calendar.changeYear(this.value);">'+yearSelect+'</select>'+
                                     '</td></tr>'+
                                 '</table>';
        Calendar.setCal(this.data.year, this.data.month, this.data.day);                          
    },
    get2: function(){
    	document.getElementById("calendarCaption").innerHTML = Settings.archivePhoto;//
        container = 'calendar';
        var currentArray = Azertag.currentDate.split('-');
        Calendar.data.monthsNames = Settings.calendarMonths;
        Calendar.data.weekDays = Settings.weekDays; 
        Calendar.data.clickYear = Calendar.data.year = currentArray[0];
        Calendar.data.clickMonth = Calendar.data.month = currentArray[1];
        Calendar.data.clickDay = Calendar.data.day = currentArray[2];
        var monthSelect = '';//'<select onchange="Calendar.changeMonth(this);" id="calMonth" class="CalendarSelect">';
        for(i = 0; i<Calendar.data.monthsNames.length; i++){
        	if(i == Calendar.data.month-1){
        		monthSelect += '<span class="monthSelect" id="monthSelectId">'+Calendar.data.monthsNames[i]+'</span>';
        		Calendar.monthNum = i+1;
                }
                //monthSelect += '<option value="'+(i+1)+'" selected>'+Calendar.data.monthsNames[i]+'</option>';
            //else 
                //monthSelect += '<option value="'+(i+1)+'">'+Calendar.data.monthsNames[i]+'</option>';
        }
        //monthSelect += '</select>';
        var yearSelect = '';//'<select onchange="Calendar.changeYear(this);" id="calYear" class="CalendarSelect">>';
        
        for(i = Calendar.data.year; i>=Calendar.data.fromYear; i--){
            yearSelect += '<option value="'+i+'">'+ i+'</option>';
        }
        document.getElementById(container).innerHTML = '<table border="0" cellpadding="0" cellspacing="0" width="100%" height="173px">'+
        '<tr><td><tr><td align="right"><img src="images/calendar_l.gif" style="cursor:pointer" onclick="Calendar.setMonth(true)"/></td><td align="center" style="width:100px;">'+monthSelect+'</td><td><img src="images/calendar_r.gif" style="cursor:pointer" onclick="Calendar.setMonth(false)" /></td></tr>'+
                                     
                                     '<tr><td id="inCalCont" colspan="3" valign="middle" height="135px"></td></tr>'+
                                     '<tr><td colspan="7" align="right">'+
                                     //'<span id="yearSelectId" style="cursor:pointer" onclick="openboxYear(\''+yearSelect+'\');">'+Calendar.data.year+'</span>'+
                                     '<select class="calYearSel" visible ="false" onchange="Calendar.changeYear(this.value);">'+yearSelect+'</select>'+
                                     '</td></tr>'+
                                 '</table>';
        Calendar.setCal(this.data.year, this.data.month, this.data.day);                          
    },
    setCal: function(year, month, day){
        var date = -100, firstDay; 
        var now = new Date(Calendar.data.year, Calendar.data.month-1, Calendar.data.day);
        if((year*1 > Calendar.data.year*1) || (year*1 == Calendar.data.year*1 && (month*1 > Calendar.data.month*1))) date=100;
        if(year*1 == Calendar.data.year*1 && month*1 == Calendar.data.month*1) date = now.getDate();
        if((firstDay = new Date(year*1, month*1-1, 1).getDay()) == 0) firstDay = 7;
        var maxDays = [31,(year%4 == 0) ? 29 : 28,31,30,31,30,31,31,30,31,30,31];
        var days = maxDays[month-1]; 
        Calendar.drawCal(firstDay, days, date, month*1, year);
    },
    changeYear: function(years){

    	hideYearHid()
        Calendar.data.clickYear = years;
        //document.getElementById('yearSelectId').innerHTML = years;
        //Calendar.data.clickMonth = document.getElementById('calMonth').value
        Calendar.setCal(Calendar.data.clickYear, Calendar.data.clickMonth, Calendar.data.clickDay);
    },
    setMonth: function(updown){
    	    if(updown){
    	    	    if(Calendar.monthNum != 1){
    	    	    	    Calendar.monthNum--;
    	    	    	    document.getElementById('monthSelectId').innerHTML = Calendar.data.monthsNames[Calendar.monthNum-1];
    	    	    	    Calendar.changeMonth();
    	    	    }
    	    }else{
    	    	    if(Calendar.monthNum != 12){
    	    	    	    Calendar.monthNum++;
    	    	    	    document.getElementById('monthSelectId').innerHTML = Calendar.data.monthsNames[Calendar.monthNum-1];
    	    	    	    Calendar.changeMonth();
    	    	    }
    	    }
    },
    changeMonth:  function(){
        //Calendar.data.clickYear = document.getElementById('calYear').value
        Calendar.data.clickMonth = Calendar.monthNum;
        Calendar.setCal(Calendar.data.clickYear, Calendar.data.clickMonth, Calendar.data.clickDay);
    },
    drawCal: function(firstDay, lastDate, date, month, year){
        var monthName = Calendar.data.monthsNames[month-1];
        var text = '<table border="0" cellpadding="1" cellspacing="1" width="100%">'+
                   '<tr align="center" valign="center">';
        for (var dayNum = 0; dayNum < 6; ++dayNum) {
            text += '<td class="TabWeekDays" align="right" valign="top"><div style="width:19px;">' + Calendar.data.weekDays[dayNum] + '<div></td>';
        }
        text += '<td class="TabWeekSunDay" align="right" valign="top"><div style="width:19px;">' + Calendar.data.weekDays[6] + '</div></td>';
        text += '</tr>';
        var digit = 1;
        var curCell = 1;
        for(var row = 1; row <= Math.ceil((lastDate + firstDay - 1)/7); ++row) {
            text += '<tr align="right" valign="top">';
            for(var col = 1; col <= 7; ++col) {
                if(curCell < firstDay) {
                    text += '<td class="EmptyCell">&nbsp;</td>';
                    curCell++;
                    continue;
                }
                if(digit > lastDate) {
                    text += '<td class="EmptyCell">&nbsp;</td>';
                    continue;
                }
		if(date==100) {
                    text += '<td class="TabNextdayCell">'+digit+'</td>';
                }
                else
                if(date==-100 || digit < date || digit == date) {
                    var lmdate = year+'-'+(month>9?month:'0'+month)+'-'+(digit>9?digit:'0'+digit);
                    if(lmdate == Azertag.calendarDate) text += '<td class="TabTodayCell" onmouseover="Calendar.light(this);" onmouseout="Calendar.dark(this);"'+
                                                       'onclick="Calendar.load(this, '+digit+');" date="'+lmdate+'" id="cal_'+(lmdate.replace(/-/g,'_'))+'">'+digit+'</td>';
 
                    else  text += '<td class="TabColumnCell" onmouseover="Calendar.light(this);" onmouseout="Calendar.dark(this);"'+
                                 'onclick="Calendar.load(this, '+digit+');" date="'+lmdate+'" id="cal_'+(lmdate.replace(/-/g,'_'))+'">'+digit+'</td>';
                } 
                /*else if(digit == date) {
                    var lmdate = year+'-'+((month+1)>9?month+1:'0'+(month+1))+'-'+(digit>9?digit:'0'+digit);
                    if(lmdate == Azertag.calendarDate) text += '<td class="TabColumnCell">'+digit+'</td>';
                    else text += '<td class="TabTodayCell">'+digit+'</td>';
                }*/ 
                else {
                    text += '<td class="TabNextdayCell">'+digit+'</td>';
                }	
                digit++;
            }
        }
        text += '</table>';
        document.getElementById('inCalCont').innerHTML = text;
    },
    light: function(element){
        if(element.getAttribute('date') != Azertag.calendarDate){
            element.className = 'TabColumnCellOver';
        }    
    },
    dark: function(element){
        if(element.getAttribute('date') != Azertag.calendarDate){
           element.className = 'TabColumnCell';
        }    
    },
    load: function(element,digit){
       Calendar.data.clickDay = digit;
       var myDate = element.getAttribute('date');
       if(Azertag.calendarDate != myDate){
          var lastObj = document.getElementById('cal_'+Azertag.calendarDate.replace(/-/g, '_'));
          if(lastObj != null) lastObj.className = 'TabColumnCell';
          Azertag.calendarDate = Azertag.currentDate = myDate;
          element.className = 'TabTodayCell';
          if(Azertag.currentDirectory == 'news'){
             if(Azertag.currentPartition == null){
                //Partition.get2('1',Settings.mainLoadNews);
                Azertag.currentFuncRef();
             }
             else{
                 Azertag.currentFuncRef(Azertag.currentPartition, Azertag.currentPartitionCaption);
                 //Partition.get2('1',Settings.mainLoadNews);
             }
          }
          if(Azertag.currentDirectory == 'photoContent'){
             PhotoGallery.get(1);
          }
       }       
    }
}
var newsContents = "";
var newsCloseCaps = "";
var newsTitles = "";

PopupWindow = { 
	oWindowContent: null,
	oWindowPhoto: null,
    openContent: function(width, height, caption, content){
    if(PopupWindow.oWindowContent != null)PopupWindow.oWindowContent.close();
	var iLeft = (self.screen.width  - width ) / 2;
        var iTop  = (self.screen.height - height ) / 2;
        var sOptions = "toolbar=no,status=no,resizable=no,dependent=yes,scrollbars=1";
            sOptions += ",width=" + width;
            sOptions += ",height=" + height;
            sOptions += ",left=" + iLeft;
            sOptions += ",top=" + iTop;
    
	newsContents = content+"";
	newsCloseCaps = Settings.closeCap+"";
	newsTitles = caption.substr(0,60);
	
    PopupWindow.oWindowContent = window.open("/jsp/shownews.jsp?id="+News.newsIds+"&cdate="+News.newsDates+"&lang="+Settings.lang, '', sOptions);
	//PopupWindow.oWindowContent.document.open();
	
	var html = '<html><head><META http-equiv="Content-Type" content="text/html; charset=utf-8">'+
		   '<link rel="stylesheet" href="Azertag.css"></link><script language="JavaScript" type="text/javascript" src="/conf/PopupWindow.js"></script><script language="JavaScript" type="text/javascript" src="conf/prototype.js"></script><script language="JavaScript" type="text/javascript" src="conf/News.js"></script><script language="JavaScript">function ajaxRequest(murl, params, responseFunction){ var url = murl; var pars = params; var myAjax = new Ajax.Request( url, {     method: \'post\',     parameters: pars,     onComplete: responseFunction }); }</script></head><title>'+caption.substr(0,60)+'</title><body style="padding:0px; margin:0px;"><div class="popupContainer">'+content+
                   '<table border="0" width="100%"><tr><td width="100%" align="right"><table border="0"><tr>'+
                        '<td valign="middle"><a href="javascript: window.close();" class="popupAction"><img src="images/close.gif" class="popupIcon">'+Settings.closeCap+'</a></td>'+
                   '</tr></table></td></tr></table>'+ 
                   '</div></body></html>';
         
	//PopupWindow.oWindowContent.document.write(html);
	//PopupWindow.oWindowContent.document.close();
	//alert(PopupWindow.oWindowContent.document.replace(""))
   },
   openPhoto: function(width, height, caption, content){ 
	var iLeft = (self.screen.width  - width ) / 2;
        var iTop  = (self.screen.height - height ) / 2;
        var sOptions = "toolbar=no,status=no,resizable=no,dependent=yes,scrollbars=0";
            sOptions += ",width=" + width;
            sOptions += ",height=" + height;
            sOptions += ",left=" + iLeft;
            sOptions += ",top=" + iTop;
    PopupWindow.oWindowPhoto = window.open("", '', sOptions);
	PopupWindow.oWindowPhoto.document.open();
	var html = '<html><head><META http-equiv="Content-Type" content="text/html; charset=utf-8">'+
		   '<link rel="stylesheet" href="Azertag.css"></link></head><title>'+caption+'</title><body style="padding:0px; margin:0px;"><div style="width:100%; height:100%; overflow: hidden;">'+content+'</div></body></html>';
	PopupWindow.oWindowPhoto.document.write(html);
	PopupWindow.oWindowPhoto.document.close();
   }
}
Counter={
    get: function(){
        ajaxRequest("/jsp/ACounter.jsp",'',Counter.afterGet);
    },
    afterGet: function(originalRequest){ 
        var doc = originalRequest.responseXML;
        var counter = doc.getElementsByTagName('counter')[0];
        var current = counter.getAttribute('current');
        var total = counter.getAttribute('total');
        document.getElementById('counter').innerHTML = '['+current+'~'+total+']';
    }
}
Banners={
    get: function(limit){
        ajaxRequest("/jsp/AGetBanners.jsp",'part=0&limit='+limit,Banners.afterGet);
        ajaxRequest("/jsp/AGetBanners.jsp",'part=1&limit=4',Banners.afterGet);
    },
    afterGet: function(originalRequest){ 
        var doc = originalRequest.responseXML;
        var partid = doc.getElementsByTagName('partition')[0].getAttribute('id');
        var items = doc.getElementsByTagName("item");  
        var outHtml = '';
        var outHtml = '';
        for(i=0; i<items.length; i++){
            var fpath =   items[i].getAttribute("fpath");
            var width =   items[i].getAttribute("width");
            var height =  items[i].getAttribute("height");
            var url =    items[i].getAttribute("url");
            var caption = items[i].firstChild.nodeValue;
            var element = '';
            if(fpath.search(/\.swf$/) !=-1){
               element ='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="'+width+'" height="'+height+'" id="myMovieName"><PARAM NAME="movie" VALUE="'+fpath+'">'+
                     '<embed src="'+fpath+'" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"></embed></OBJECT>';
            }
            else{
               element = '<img src="'+fpath+'" width="'+width+'" height="'+height+'" border="0">';
            }
            if(url != '') element = '<a href="'+url+'" target="_blank" border="0">'+element+'</href>';
            if(partid == 1){
                outHtml += '<div style="margin: 5px;">'+element+'</div>';
                if(i == items.length-1){
                    document.getElementById('rightBanners').innerHTML = outHtml;
                }
            }
            else if(partid == 0){
                document.getElementById('banner_'+i).innerHTML = element;
            }
        }
    }
}

StaticInfo={
    load: function(cat){
    	ajaxRequest("/jsp/AStaticAzer.jsp","lang="+Settings.lang+"&cat="+cat, StaticInfo.afterLoad);
    },
    afterLoad: function(originalRequest){ //alert(originalRequest.responseTEXT);
        document.getElementById('news').innerHTML = originalRequest.responseTEXT;
    }
}
function ajaxRequest(murl, params, responseFunction){
    var url = murl;
    var pars = params;
    var myAjax = new Ajax.Request(
    url,
    {
        method: 'post',
        parameters: pars,
        onComplete: responseFunction
    });
}

window.onload = function(){Azertag.getTempParts();}


function openBanner(cat){
		var width = 600;
		var height = 500;
		var iLeft = (self.screen.width  - width ) / 2;
        var iTop  = (self.screen.height - height ) / 2;
        var sOptions = "toolbar=no,status=no,resizable=no,dependent=yes,scrollbars=yes";
            sOptions += ",width=" + width;
            sOptions += ",height=" + height;
            sOptions += ",left=" + iLeft;
            sOptions += ",top=" + iTop;
        var oWindow = window.open("/jsp/AGreatAbout.jsp?lang="+Settings.lang+"&cat="+cat+"&page=1", '', sOptions);
}

var CaptionIframe = "";
function iframeLoad(cat, caption){
	CaptionIframe = caption;
	if(document.getElementById('contentSearch') != null)
		document.getElementById('contentSearch').style.display = 'none';
	document.getElementById("staticInfo").src="/jsp/AStaticAzer.jsp?lang="+Settings.lang+"&cat="+cat;
    }
function iframeNewsLoad(){
	
	document.getElementById('newsBlock').style.display = 'none';
	document.getElementById('newsContent').style.display = 'none';
        document.getElementById('topContent').style.display = 'none';
	document.getElementById('photoContent').style.display = 'none';
	document.getElementById('calendarContent').style.display = 'none';
	//document.getElementById("searchInfo").src="/jsp/AShowSearched.jsp?id="+Searched.newsId+"&cdate="+Searched.newsDate+"&lang="+Settings.lang;
    }
function showIframeLoad(cat){
		var width = 600;
		var height = 500;
		var iLeft = (self.screen.width  - width ) / 2;
        var iTop  = (self.screen.height - height ) / 2;
        var sOptions = "toolbar=no,status=no,resizable=no,dependent=yes,scrollbars=yes";
            sOptions += ",width=" + width;
            sOptions += ",height=" + height;
            sOptions += ",left=" + iLeft;
            sOptions += ",top=" + iTop;
        var oWindowload = window.open("/jsp/AOpenBanner.jsp?lang="+Settings.lang+"&cat="+cat, '', sOptions);
    }
    
function afterLoadIframe(){
	
	document.getElementById('newsContent').style.display = 'block';
	document.getElementById('newsBlock').style.display = 'none';
        document.getElementById('topContent').style.display = 'none';
	document.getElementById('photoContent').style.display = 'none';
	if(document.getElementById('calendarContent') != null)
		document.getElementById('calendarContent').style.display = 'none';
	//alert(window.frames[ "staticInfo" ].document.body.innerHTML)
	
		outHTML = '<div class="art-Block">';
		outHTML += '<div class="art-Block-body">';
		outHTML += '<div class="art-BlockHeader4">';
		outHTML += '<div class="l"></div>';
		outHTML += '<div class="r"></div>';
		outHTML += '<div class="t">'+CaptionIframe+'</div>';
		outHTML += '</div>';
		outHTML += '<div class="art-BlockContent4">';
		outHTML += '<div class="art-BlockContent4-tl"></div>';
		outHTML += '<div class="art-BlockContent4-tr"></div>';
		outHTML += '<div class="art-BlockContent4-bl"></div>';
		outHTML += '<div class="art-BlockContent4-br"></div>';
		outHTML += '<div class="art-BlockContent4-tc"></div>';
		outHTML += '<div class="art-BlockContent4-bc"></div>';
		outHTML += '<div class="art-BlockContent4-cl"></div>';
		outHTML += '<div class="art-BlockContent4-cr"></div>';
		outHTML += '<div class="art-BlockContent4-cc"></div>';
		outHTML += '<div class="art-BlockContent4-body">';
		
		outHTML += window.frames[ "staticInfo" ].document.body.innerHTML;
		
		outHTML += '</div></div></div></div>';
        document.getElementById('newsContent').innerHTML = outHTML;
    }
function afterLoadNewsIframe(){
	
	document.getElementById('newsContent').style.display = 'block';
	document.getElementById('newsBlock').style.display = 'none';
        document.getElementById('topContent').style.display = 'none';
	document.getElementById('photoContent').style.display = 'none';
	document.getElementById('calendarContent').style.display = 'none';
	//alert(window.frames[ "staticInfo" ].document.body.innerHTML)
	alert("wndc;qwdc"+window.frames[ "searchInfo" ].document.body.innerHTML)
		
        document.getElementById('newsContent').innerHTML = window.frames[ "searchInfo" ].document.body.innerHTML;
    }


var x,y,a,b,timer,thisbox,isbox,urlimg;
var posleftvorher;

var box;

if (document.layers) {
	var left_pos=".left=";
	var top_pos=".top=";
	var doc="document.";
	var stl="";
}

if (document.all) {
	var left_pos=".pixelLeft=";
	var top_pos=".pixelTop=";
	var doc="";
	var stl=".style";
}
function openbox(element) {
	
       var width = self.screen.width;//element.getAttribute('dwidth');
       var height = self.screen.height;//element.getAttribute('dheight');
       var title = element.getAttribute('title');
       var fid =  element.getAttribute('fid');
       var fdate =  element.getAttribute('fdate');
       var partition =  element.getAttribute('partition');
       var rdate = element.getAttribute('partdate');
       var lang = Settings.lang;
       /*var maxSize = 400;
       if(width >= height &&  width > maxSize){
           height = Math.floor(height*maxSize/width);
           width = maxSize;
       }
       else if(width < height &&  height > maxSize){
           width = Math.floor(width*maxSize/height);
           height = maxSize;
       }
       var content = '<div><img width='+width*1.2+' height='+height*1.2+' src="/jsp/AGetGalleryFull.jsp?partition='+partition+'&rdate='+rdate+'&lang='+lang+'&fid='+fid+'&fdate='+fdate+'" title="'+title+'" style="border: solid 1px black;" width="100%" height="100%"></div>';
       
	isbox = element
		if(document.layers) {
			box = document.popupbox
			box.visibility="visible"
			document.popupbox.document.write(content)
			document.popupbox.document.close()
			document.popupbox.left=x+25
			document.popupbox.top=y
		}

		if(document.all) {
			box = document.all.popupbox.style
			box.visibility="visible";
			popupbox.innerHTML=content;
			eval(doc+"popupbox"+stl+left_pos+(x+25))
			eval(doc+"popupbox"+stl+top_pos+y)
			timer=setTimeout("isOpenbox()",50)
		}*/
		
		
	_x=window.event.clientX;
	_y=window.event.clientY;
	_dx=5 
	left=false;right=false; 
	if(_dx+_x+myalt.clientWidth>document.body.clientWidth){_x=document.body.clientWidth-myalt.clientWidth-_dx;left=true;} 
	if(_dx+_y+myalt.clientHeight>document.body.clientHeight){_y=document.body.clientHeight-myalt.clientHeight-_dx;right=true;} 
	if(left&&right)_y=document.body.clientHeight-myalt.clientHeight-_dx*4; 
	myalt.style.left=_x;
	myalt.style.top=_y+document.body.scrollTop; 
	if(hide){ 
	var content = '<div><img src="/jsp/AGetGalleryFull.jsp?partition='+partition+'&rdate='+rdate+'&lang='+lang+'&fid='+fid+'&fdate='+fdate+'" title="'+title+'" style="border: solid 1px black;"></div>';
	myalt.innerHTML=content;
	myalt.style.visibility="visible"; 
	hide=false; 
	} 

}
/*
function openbox(element) {
	
       var width = self.screen.width;//element.getAttribute('dwidth');
       var height = self.screen.height;//element.getAttribute('dheight');
       var title = element.getAttribute('title');
       var fid =  element.getAttribute('fid');
       var fdate =  element.getAttribute('fdate');
       var partition =  element.getAttribute('partition');
       var rdate = element.getAttribute('partdate');
       var lang = Settings.lang;
       var maxSize = 400;
       if(width >= height &&  width > maxSize){
           height = Math.floor(height*maxSize/width);
           width = maxSize;
       }
       else if(width < height &&  height > maxSize){
           width = Math.floor(width*maxSize/height);
           height = maxSize;
       }
       var content = '<div><img width='+width*1.2+' height='+height*1.2+' src="/jsp/AGetGalleryFull.jsp?partition='+partition+'&rdate='+rdate+'&lang='+lang+'&fid='+fid+'&fdate='+fdate+'" title="'+title+'" style="border: solid 1px black;" width="100%" height="100%"></div>';
       
	isbox = element
		if(document.layers) {
			box = document.popupbox
			box.visibility="visible"
			document.popupbox.document.write(content)
			document.popupbox.document.close()
			document.popupbox.left=x+25
			document.popupbox.top=y
		}

		if(document.all) {
			box = document.all.popupbox.style
			box.visibility="visible";
			popupbox.innerHTML=content;
			eval(doc+"popupbox"+stl+left_pos+(x+25))
			eval(doc+"popupbox"+stl+top_pos+y)
			timer=setTimeout("isOpenbox()",50)
		}

}
*/
function openbox2(element) {
	
       var width = element.getAttribute('width');
       var height = element.getAttribute('height');
       var srcimgs = element.getAttribute('src');
       srcimgs = srcimgs.replace(/\.jpg/g,"_g.jpg");
       var maxSize = 600;
       if(width >= height &&  width > maxSize){
           height = Math.floor(height*maxSize/width);
           width = maxSize;
       }
       else if(width < height &&  height > maxSize){
           width = Math.floor(width*maxSize/height);
           height = maxSize;
       }
       var content = '<div><img src="'+srcimgs+'" style="border: solid 1px black;"></div>';
       
	isbox = element
		if(document.layers) {
			box = document.popupbox
			box.visibility="visible"
			document.popupbox.document.write(content)
			document.popupbox.document.close()
			document.popupbox.left=x+25
			document.popupbox.top=y
		}

		if(document.all) {
			box = document.all.popupbox.style
			box.visibility="visible";
			popupbox.innerHTML=content;
			eval(doc+"popupbox"+stl+left_pos+(x+25))
			eval(doc+"popupbox"+stl+top_pos+y)
			timer=setTimeout("isOpenbox()",50)
		}

}
function isOpenbox() {
	
		if(document.layers) {
			box = document.popupbox
			document.popupbox.document.close()
			document.popupbox.left=x+25
			document.popupbox.top=y
		}

		if(document.all) {
			box = document.all.popupbox.style
			eval(doc+"popupbox"+stl+left_pos+(x+25))
			eval(doc+"popupbox"+stl+top_pos+y)
			timer=setTimeout("isOpenbox()",50);
		}

}

function closebox(){
		clearTimeout(timer);
		box.visibility="HIDDEN";
}

function handlerMM(e){
	//x = (document.layers) ? e.pageX : event.clientX;
	//y = (document.layers) ? e.pageY : event.clientY;
}
if (document.layers){
	document.captureEvents(Event.MOUSEMOVE);
}
//document.onmousemove = handlerMM;

var hide=true;
function movePic(element){ 
	_x=window.event.clientX; 
	_y=window.event.clientY; 
       var srcimgs = element.getAttribute('src');
       srcimgs = srcimgs.replace(/\.jpg/g,"_g.jpg");
	_dx=5 
	left=false;right=false; 
	if(_dx+_x+myalt.clientWidth>document.body.clientWidth){_x=document.body.clientWidth-myalt.clientWidth-_dx;left=true;} 
	if(_dx+_y+myalt.clientHeight>document.body.clientHeight){_y=document.body.clientHeight-myalt.clientHeight-_dx;right=true;} 
	if(left&&right)_y=document.body.clientHeight-myalt.clientHeight-_dx*4; 
	myalt.style.left=_x;
	myalt.style.top=_y+document.body.scrollTop; 
	if(hide){ 
	var content = '<div><img src="'+srcimgs+'" style="border: solid 1px black;"></div>';
	myalt.innerHTML=content;
	myalt.style.visibility="visible"; 
	hide=false; 
	} 
} 
function hidePic(){
	myalt.style.visibility="hidden"; 
	myalt.innerHTML=""; 
	myalt.style.top=0; 
	myalt.style.left=0; 
	hide=true; 
} 


var hideYear=true;
function openboxYear(textYear) {
       var width = self.screen.width;
       var height = self.screen.height;
       var text = textYear.split(',');
       var lang = Settings.lang;
	//alert(textYear);
	_x=event.clientX+(document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft; 
	_y=event.clientY+(document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop; 
	var myaltYear = document.getElementById('myaltYear');

	myaltYear.style.left=_x;
	myaltYear.style.top=_y
	if(hideYear){
		var content = '';
		
		for(i=text.length-2; i>=0; i--){
			content += '<div  style="border-width:1px;border-style:solid;background-color:#fff;cursor:pointer" onclick="Calendar.changeYear('+text[i]+');" onmouseover="changecolor(this);" onmouseout="changecolor2(this);">'+text[i]+'</div>';
		}
		myaltYear.innerHTML='<div style="border-width:1px;border-style:solid;border-color:#f1f1f1">'+content+'</div>';
		content='';
		//alert(myaltYear.innerHTML);
		myaltYear.style.visibility="visible"; 
		hideYear=false; 
	} 

}
function hideYearHid(){
	var myaltYear = document.getElementById('myaltYear');
	myaltYear.style.visibility="hidden"; 
	myaltYear.innerHTML=""; 
	myaltYear.style.top=0; 
	myaltYear.style.left=0;
	hideYear=true; 
} 
function changecolor(elem){
	elem.style.color='#fff';
	elem.style.backgroundColor='#0000ff';
}
function changecolor2(elem){
	elem.style.color='#000';
	elem.style.backgroundColor='#fff';
}

function setHomePageYou(){
	document.style.behavior='url(#default#homepage)';
	document.setHomePage('http://www.azertag.com/index_'+Settings.lang+'.html');
}
function addBookmark()
{
  url = 'http://www.azertag.com/index_'+Settings.lang+'.html'
  title = Settings.siteName;
  if (!url) url = location.href;
  if (!title) title = document.title;

  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");

  else if (typeof window.external == "object") window.external.AddFavorite(url, title);

  else if (window.opera && document.createElement)
  {
    var a = document.createElement('A');
    if (!a) return false; //IF Opera 6
    a.setAttribute('rel','sidebar');
    a.setAttribute('href',url);
    a.setAttribute('title',title);
    a.click();
  }
}

