// JavaScript Document    

    //Function to switch watermark input controls
    function removeWatermark(textbox, show) {    
        textbox.style.display = 'none';
        document.getElementById(show).style.display = 'block';
        document.getElementById(show).focus();
    }

    function resetWatermark(textbox, show) {    
        if (textbox.value == '') {
            textbox.style.display = 'none';
            document.getElementById(show).style.display = 'block';
        }
    }    
    
    function popUp(URL, width, height) {
        day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=" + width + ",height=" + height + "');");
    };
	
	function getXmlHttpRequestObject() {
		if (window.XMLHttpRequest) {
			return new XMLHttpRequest();
		} else if(window.ActiveXObject) {
			return new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			alert("Uw browser is verouderd, installeer a.u.b. een nieuwere versie.");
		}
	}

	//Our XmlHttpRequest object to get the auto suggest
	var searchReq = getXmlHttpRequestObject();
	var searchReq2 = getXmlHttpRequestObject();
	
	//Called from keyup on the search textbox.
	//Starts the AJAX request.
	function submitLoginForm() {
		
		document.getElementById('loginstatusTD').innerHTML = '<img src="img/loading.gif"  />'; 
		if (searchReq.readyState == 4 || searchReq.readyState == 0) {
			var str = escape(document.getElementById('ucLogin_txtEmail').value);
			var str2 = escape(document.getElementById('ucLogin_txtPassword').value);
			
			//alert(''+str+''+ str +'')
			searchReq.open("GET", 'Ajax.aspx?u=' + str + '&p='+ str2 +'', true);
			searchReq.onreadystatechange = handleSearchSuggest; 
			searchReq.send(null);
		}		
	}


	//Called from keyup on the search textbox.
	//Starts the AJAX request.
	function submitLogout() {
		
		//document.getElementById('loginstatusTD').innerHTML = '<img src="img/loading.gif"  />'; 
		if (searchReq.readyState == 4 || searchReq.readyState == 0) {
			
			//alert(''+str+''+ str +'')
			searchReq2.open("GET", 'Ajax.aspx?logout=yes', true);
			searchReq2.onreadystatechange = handleLogout; 
			searchReq2.send(null);
		}		
	}
	

	//Called when the AJAX response is returned.
	function handleSearchSuggest() {
		if (searchReq.readyState == 4) {
			// document.getElementById('loginstatusTR').display = 'block';
			var ss = document.getElementById('loginstatusTD');
			ss.innerHTML = '';
			var str = searchReq.responseText;

			ss.innerHTML += str;
	
			if(str == 'yes'){
				//window.location.href= 'home.aspx';
				window.location.reload();
			};
		};
	};
	
	

	//Called when the AJAX response is returned.
	function handleLogout() {
		if (searchReq.readyState == 4) {
			// document.getElementById('loginstatusTR').display = 'block';
			//ar ss = document.getElementById('loginstatusTD');
			//ss.innerHTML = '';
			var str = searchReq.responseText;

			//ss.innerHTML += str;
	        alert(str);
			if(str == 'logout'){
				//window.location.href= 'home.aspx';
				window.location.reload();
			};
		};
	};
	
	//For using multiple javascript onload events
    function addLoadEvent(func) {   
        var oldonload = window.onload;   
        if (typeof window.onload != 'function') {   
            window.onload = func;   
        } else {   
            window.onload = function() {   
                if (oldonload) {   
                    oldonload();   
                }   
                func();
            }
        }
    }