﻿

var XmlHttp;
function CreateXmlHttp()
{
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
}

function HandleResponseDropDown(TheDiv)
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{			
			HandleRDDRetV(XmlHttp.responseXML.documentElement);
		}
		else
		{
			alert("There was a problem retrieving data from the server.\n\nRefress the page" );
		}
	}
}
//var HandleResponseAction = 0;
function HandleResponseDiv()
{

	if(XmlHttp.readyState == 4)
	{
		if(XmlHttp.status == 200)
		{		
		if (HandleResponseAction == 0) 
		    generateGridReturnVal(XmlHttp.responseText);
		else if (HandleResponseAction == 1) 
		    generateGridReturnVal2(XmlHttp.responseText);	    
		}
		else
		{
			alert("There was a problem retrieving data from the server.\n\nRefress the page" );
		}
	}
}
function generateGrid(TheUrl,Action)
{
	CreateXmlHttp();
	if(XmlHttp)
	{
	    HandleResponseAction = Action
		XmlHttp.onreadystatechange = HandleResponseDiv;
		XmlHttp.open("GET", TheUrl,  true);
		XmlHttp.send(null);		
	}
    return false;
}


	





function ModalShow()
{
    var Modaldiv=document.getElementById('ModalPageLayer');
    Modaldiv.className = 'modalBackground';
    Modaldiv.style.display = '';
    
    var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	if (arrayPageSize[1] < 1200)
	arrayPageSize[1] = 1200;
	
	Modaldiv.style.height = (arrayPageSize[1] + 'px');
}

function ModalHidde()
{
    var Modaldiv=document.getElementById('ModalPageLayer');
    Modaldiv.className = 'modalBackgroundHidden';
    Modaldiv.style.display = 'none';
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function DivPopUpShow(LayerID,height,witdh,css)
{
//    var divLayer = document.getElementById(LayerID);


}

function DivPopUpHide(LayerID,height,witdh,css)
{
//    var divLayer = document.getElementById(LayerID);
}
function ShowSmallLoading(theObject)
{
    document.getElementById(theObject).innerHTML = "<div align='center' valign='middle' style='width: 50px; height: 100px; background-color:#FFFFFF;'><img alt='Loading Data' src='../images/loading.gif' /></div>";
}
function ShowLoading(theObject)
{
    document.getElementById(theObject).innerHTML = "<div align='center' valign='middle' style='width: 50px; height: 100px; background-color:#FFFFFF;'><img alt='Loading Data' src='../images/loading_medium.gif' /></div>";
}
function ShowBigLoading(theObject)
{
    document.getElementById(theObject).innerHTML = "<div align='center' valign='middle' style='width: 480px; height: 100px; background-color:#FFFFFF;'><img alt='Loading Data' src='../images/loadingBig.gif' /></div>";
}
	function checkDate(fld) {
    var mo, day, yr;
    
    var entry = document.getElementById(fld).value;
    entry = entry.replace(".","/");
    entry = entry.replace(".","/");

    var re = /\b\d{1,2}[\/-]\d{1,2}[\/-]\d{4}\b/;
    if (re.test(entry)) {
        var delimChar = (entry.indexOf("/") != -1) ? "/" : "-";
        var delim1 = entry.indexOf(delimChar);
        var delim2 = entry.lastIndexOf(delimChar);
        day = parseInt(entry.substring(0, delim1), 10);
        mo = parseInt(entry.substring(delim1+1, delim2), 10);
        yr = parseInt(entry.substring(delim2+1), 10);
        var testDate = new Date(yr, mo-1, day);
        //alert(testDate)
        if (testDate.getDate() == day) {
            if (testDate.getMonth() + 1 == mo) {
                if (testDate.getFullYear() == yr) 
                {
                    var stringDate = testDate.getDate()+"."+(testDate.getMonth()+1)+"."+testDate.getFullYear();
                    document.getElementById(fld).value = stringDate;
                    //alert(stringDate);
                    return true;
                    
                } 
                else {
                    alert("There is a problem with the year entry.");
                }
            } else {
                alert("There is a problem with the month entry.");
            }
        } else {
            alert("There is a problem with the date entry.");
        }
    } else {
        alert("Incorrect date format. Enter as dd.mm.yyyy");
    }
    return false;
}
