var ContentLayer = {};
var CheckVisibility = false;
var ChekVideo = false;


ContentLayer.RenderLayer = function(Template, Object, RecordID) {
document.getElementById('ShadowClickArea').style.display = 'block';
if(CheckVisibility == true){    
ChekVideo = false;
var request = new CHttpRequest();
	document.getElementById('ElementLayer').innerHTML = '';
    request.QueryString = "AjaxType=HTML&RequestFile=Templates." + Template + "&MethodName=XTemplateRender";
    request.AsyncCall = true;
    request.OnResponse = ContentLayer.ShowProductContent_Callback;
    if (Object.length > 1)
        request.AddProperty("Arguments[Object]", Object);

    if (Template.length > 1)
        request.AddProperty("Arguments[Template]", Template);

    if (RecordID != null)
        request.AddProperty("Arguments[RecordID]", RecordID);
    request.Send();    
    
    
    document.getElementById('ShadowLayer').style.display = 'block';
    document.getElementById('ElementLayer').style.display = 'block';    

}else{
    CheckVisibility = true;
    scrollTo(0, 0);
    var bIE6 = false;
    if (navigator.appName == "Microsoft Internet Explorer") {
        bIE6 = true;
    }
    var BodyTag = document.getElementsByTagName("BODY")[0];

    var ShadowLayer = document.createElement("DIV");
    
    if (bIE6) {
        ShadowLayer.style.position = "absolute";
    } else {
        ShadowLayer.style.position = "fixed";
    }				
		
    ShadowLayer.style.top = "0px";
    ShadowLayer.style.left = "0px";
    ShadowLayer.style.zIndex = 500;
    ShadowLayer.style.width = "100%";

    ShadowLayer.style.height = (document.getElementById('MainContainer').offsetHeight+100) + 'px';     

    ShadowLayer.style.opacity = ".60";
    ShadowLayer.style.filter = "alpha(opacity=60)";
    ShadowLayer.style.MozOpacity = "0.6";
    ShadowLayer.id = "ShadowLayer";
    ShadowLayer.style.backgroundColor = "#000000";        
    var ElementLayer = document.createElement("DIV");
    if (bIE6) {
        ElementLayer.style.position = "absolute";
    } else {
        ElementLayer.style.position = "absolute";
    }    
    ElementLayer.id = "ElementLayer";            
    
    ElementLayer.style.textAlign = "center";
    ElementLayer.style.height = "600px";
    
    
    var browserName=navigator.appName; 
var docWidth = document.body.offsetWidth;
var MainConWidth  = document.getElementById('MainContainer').offsetWidth;
if (browserName=="Netscape"){ 
   ElementLayer.style.marginLeft = parseInt(((document.body.clientWidth - 980)/2))+"px";   
}else{ 
   if (browserName=="Microsoft Internet Explorer"){            
        ElementLayer.style.left = "0px";   
        ChekVideo = true;        
    }else{
        ElementLayer.style.marginLeft = parseInt(((document.body.clientWidth - 980)/2))+"px";
   }
}

    var TopMargin = (((document.body.offsetHeight - 600) / 2) - 44) ;
    if(  TopMargin  < 0){
      TopMargin = 20 ;
    }
    ElementLayer.style.top = TopMargin + "px";

   // ElementLayer.style.top = "0";
    ElementLayer.style.left = "0";

    ElementLayer.style.zIndex = 502;
    BodyTag.appendChild(ShadowLayer);
    BodyTag.appendChild(ElementLayer);

    var request = new CHttpRequest();
    request.QueryString = "AjaxType=HTML&RequestFile=Templates." + Template + "&MethodName=XTemplateRender";
    request.AsyncCall = true;
    request.OnResponse = ContentLayer.ShowProductContent_Callback;
    if (Object.length > 1)
        request.AddProperty("Arguments[Object]", Object);

    if (Template.length > 1)
        request.AddProperty("Arguments[Template]", Template);

    if (RecordID != null)
        request.AddProperty("Arguments[RecordID]", RecordID);
    request.Send();    
    }
   
}

ContentLayer.ShowProductContent_Callback = function(request, state){
    if(document.getElementById('ElementLayer')){
	        elem = document.getElementById('ElementLayer');
	        elem.innerHTML = request.responseText;	
	        state.disabled = false;
    		  
            var browserName=navigator.appName; 
            if (browserName=="Netscape"){ 
               
            }else{ 
               if (browserName=="Microsoft Internet Explorer"){    
                    
                        var nHeight = elem.clientHeight;
                        var vscroll = (document.all ? document.body.parentNode.scrollTop : window.pageYOffset);
                        var nTopMargin = (((screen.availHeight-120)-(nHeight))/2)+vscroll - 70;
	                    elem.style.marginTop = nTopMargin + 'px';
    	            
                    // krupka za videoto pod IE za da izravni 6irinata s drugite layeri. Opravi kato ima vreme
                    if(document.getElementById('VideoTable')){
                        if( ChekVideo == true){
                            ChekVideo = false;                
                              document.getElementById('VideoTable').style.marginLeft = parseInt(((document.body.clientWidth - 980)/2))+"px";
                                    }
                                }
                                    
                        }else{        
                        }     
              } 
      }else{

      }// kum naj-gorniq if
}

ContentLayer.CloseLayer = function(){
    document.getElementById('ElementLayer').style.display = 'none';
    document.getElementById('ShadowClickArea').style.display = 'none';
    document.getElementById('ShadowLayer').style.display = 'none';    
}


