/*************************************************************************************************************************************/
/*************************************************************************************************************************************/
/*                                                    AJAX PART                                                                      */       
/*************************************************************************************************************************************/
/*************************************************************************************************************************************/
function trim(sstr) {
    var trimed = sstr.replace(/^\s+|\s+$/g, '') ;
    return trimed;

}

function checknumber(valuetocheck){
    var x=valuetocheck;
    var anum=/(^\d+$)|(^\d+\d+$)/;
    if (anum.test(x))
        testresult=true;
    else{
        testresult=false;
    }
    return (testresult);
}

function xmlhttpPost(strURL, updatecontainer, querystring) {
    
    
    var containerheight = 0;
    
    if(document.getElementById(updatecontainer).clientHeight) {
        containerheight = document.getElementById(updatecontainer).clientHeight;
    } 
    else 
    if(document.getElementById(updatecontainer).offsetHeight) {
        containerheight = document.getElementById(updatecontainer).offsetHeight;
    }
    

    document.getElementById("divloader").style.display="block";
    
    
    
    
    
    var xmlHttpReq2 = false;
    var self = this;
    
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
    
    self.xmlHttpReq2 = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {    
        self.xmlHttpReq2 = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    self.xmlHttpReq2.open('POST', strURL, true);
    
    self.xmlHttpReq2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
     
    self.xmlHttpReq2.onreadystatechange = function() {
        
        if (self.xmlHttpReq2.readyState == 4) {
            // SharpMap_SetOpacity(document.getElementById(updatecontainer),100);
            updatepage(updatecontainer, self.xmlHttpReq2.responseText);
            
        }
    }
    
    //SharpMap_SetOpacity(document.getElementById(updatecontainer),20);
    self.xmlHttpReq2.send(querystring);
}

function xmlhttpPostwithoutLoad(strURL, updatecontainer, querystring, scrolldown) {
    
    
    var xmlHttpReq2 = false;
    var self = this;
    
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
    
    self.xmlHttpReq2 = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {    
        self.xmlHttpReq2 = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    self.xmlHttpReq2.open('POST', strURL, true);
    
    self.xmlHttpReq2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
     
    self.xmlHttpReq2.onreadystatechange = function() {
        
        if (self.xmlHttpReq2.readyState == 4) {
            // SharpMap_SetOpacity(document.getElementById(updatecontainer),100);
            if (scrolldown) {
              updatepagescrolldown(updatecontainer, self.xmlHttpReq2.responseText);
            } else {
              updatepage(updatecontainer, self.xmlHttpReq2.responseText);
            }
            
        }
    }
    
    //SharpMap_SetOpacity(document.getElementById(updatecontainer),20);
    self.xmlHttpReq2.send(querystring);
}


function updatepage(updatecontainer, str){
    
   
    if (document.getElementById(updatecontainer)!=null) {
        document.getElementById(updatecontainer).innerHTML = trim(str);
        document.getElementById("divloader").style.display="none";
        
    }   
}

function updatepagescrolldown(updatecontainer, str){
    
   
    if (document.getElementById(updatecontainer)!=null) {
        document.getElementById(updatecontainer).innerHTML = trim(str);
        document.getElementById("divloader").style.display="none";
        document.getElementById(updatecontainer).scrollTop = document.getElementById(updatecontainer).scrollHeight;
    }   
}


function querystring( name ){  
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
    var regexS = "[\\?&]"+name+"=([^&#]*)";  
    var regex = new RegExp( regexS );  
    var results = regex.exec( window.location.href );  
    if( results == null )    
        return "";  
    else    
        return results[1];
}


function closediv(divname) {
    
    var divcontainer = document.getElementById(divname);
    if (divcontainer!=null) {
        divcontainer.style.display="none";
    }
}









