var mon_http_lookup = false;
var mon_http_post = false;
var mon_http_marker = false;
var mon_http_waypoint = false;

var mon_lookup_v_mon_url="";
var mon_lookup_v_mon_query_string="";
var mon_lookup_v_mon_return_lookup="";
var mon_current_return_lookup;
var mon_current_return_post;
    
function mon_init_ajax_lookup()
{
  		mon_http_lookup = false;
		if (window.XMLHttpRequest)
				  	{
	                mon_http_lookup = new XMLHttpRequest();
	                if (mon_http_lookup.overrideMimeType)
						{
	                    	mon_http_lookup.overrideMimeType('text/xml');
				        }
					}
				else if (window.ActiveXObject)
					{ //IE
			            try {
			                mon_http_lookup = new ActiveXObject("Msxml2.XMLHTTP");
			                } catch (e) {
			                	try {
			                        mon_http_lookup = new ActiveXObject("Microsoft.XMLHTTP");
			                        } catch (e) {}
			                	}

			        }

			        if (!mon_http_lookup) {
			                    alert('Oppss...unable to init Content AJAX !');
			                    return false;
			        }
}

function mon_init_ajax_post()
{
  		mon_http_post = false;
		if (window.XMLHttpRequest)
				  	{
	                mon_http_post = new XMLHttpRequest();
	                if (mon_http_post.overrideMimeType)
						{
	                    	mon_http_post.overrideMimeType('text/xml');
				        }
					}
				else if (window.ActiveXObject)
					{ //IE
			            try {
			                mon_http_post = new ActiveXObject("Msxml2.XMLHTTP");
			                } catch (e) {
			                	try {
			                        mon_http_post = new ActiveXObject("Microsoft.XMLHTTP");
			                        } catch (e) {}
			                	}

			        }

			        if (!mon_http_post) {
			                    alert('Oppss...unable to init Content AJAX !');
			                    return false;
			        }
}

function mon_init_ajax_marker()
{
  		mon_http_marker = false;
		if (window.XMLHttpRequest)
				  	{
	                mon_http_marker = new XMLHttpRequest();
	                if (mon_http_marker.overrideMimeType)
						{
	                    	mon_http_marker.overrideMimeType('text/xml');
				        }
					}
				else if (window.ActiveXObject)
					{ //IE
			            try {
			                mon_http_marker = new ActiveXObject("Msxml2.XMLHTTP");
			                } catch (e) {
			                	try {
			                        mon_http_marker = new ActiveXObject("Microsoft.XMLHTTP");
			                        } catch (e) {}
			                	}

			        }

			        if (!mon_http_marker) {
			                    alert('Oppss...unable to init Marker AJAX !');
			                    return false;
			        }
}


function mon_init_ajax_waypoint()
{
  		mon_http_waypoint = false;
		if (window.XMLHttpRequest)
				  	{
	                mon_http_waypoint = new XMLHttpRequest();
	                if (mon_http_waypoint.overrideMimeType)
						{
	                    	mon_http_waypoint.overrideMimeType('text/xml');
				        }
					}
				else if (window.ActiveXObject)
					{ //IE
			            try {
			                mon_http_waypoint = new ActiveXObject("Msxml2.XMLHTTP");
			                } catch (e) {
			                	try {
			                        mon_http_waypoint = new ActiveXObject("Microsoft.XMLHTTP");
			                        } catch (e) {}
			                	}

			        }

			        if (!mon_http_waypoint) {
			                    alert('Oppss...unable to init Waypoint AJAX !');
			                    return false;
			        }
}

//======================================================================================================================================================

function UpdateLOOKUPContents() {

       if (mon_http_lookup.readyState == 4) {
            if (mon_http_lookup.status == 200) {

              	var return_value =mon_http_lookup.responseText.split("<mon_ajax>");
          	 	if((return_value[0]=="YES")&&(return_value[2]=="DONE"))
          	 		{
	
					
					
					eval("document.getElementById('"+mon_current_return_lookup+"').innerHTML=return_value[1]");

				}
				else
				{
				  	alert("Oppss...unable to get back the valid content"+mon_http_lookup.responseText);
				}
				mon_terminate_ajax_lookup();
			
            } else {
                alert('Oppss...Unable to perform your action\nThere is problem with the network connection.');
            }
        }

}


//======================================================================================================================================================



function UpdateLOOKUPPOLYGONSContents() {

       if (mon_http_lookup.readyState == 4) {
            if (mon_http_lookup.status == 200) {

              	var return_value =mon_http_lookup.responseText.split("<mon_ajax>");
          	 	if((return_value[0]=="YES")&&(return_value[2]=="DONE"))
          	 		{
	
                        
					
                        eval("document.getElementById('"+mon_current_return_lookup+"').innerHTML=return_value[1]");
                        mon_place_polygons();
                                
                                
				}
				else
				{
				  	alert("Oppss...unable to get back the valid content"+mon_http_lookup.responseText);
				}
				mon_terminate_ajax_lookup();
			
            } else {
                alert('Oppss...Unable to perform your action\nThere is problem with the network connection.');
            }
        }

}


function UpdateLOOKUPRECTANGLESContents() {

       if (mon_http_lookup.readyState == 4) {
            if (mon_http_lookup.status == 200) {

              	var return_value =mon_http_lookup.responseText.split("<mon_ajax>");
          	 	if((return_value[0]=="YES")&&(return_value[2]=="DONE"))
          	 		{
	
					
					
                        eval("document.getElementById('"+mon_current_return_lookup+"').innerHTML=return_value[1]");
                        mon_place_rectangles();
                                
                                
				}
				else
				{
				  	alert("Oppss...unable to get back the valid content"+mon_http_lookup.responseText);
				}
				mon_terminate_ajax_lookup();
			
            } else {
                alert('Oppss...Unable to perform your action\nThere is problem with the network connection.');
            }
        }

}


function UpdatePOSTContents() {

       if (mon_http_post.readyState == 4) {
        
        
            if (mon_http_post.status == 200) {

              	var return_value =mon_http_post.responseText.split("<mon_ajax>");
          	 	if((return_value[0]=="YES")&&(return_value[2]=="DONE"))
          	 		{
	
					eval("document.getElementById('"+mon_current_return_post+"').innerHTML=return_value[1]");
                    
                    

				}
				else
				{
				  	alert("Oppss...unable to get back the valid content"+mon_http_post.responseText);
				}
				mon_terminate_ajax_post();
			
            } else {
                alert('Oppss...Unable to perform your action\nThere is problem with the network connection.');
            }
        }

}


function UpdateMARKERContents() {

       if (mon_http_marker.readyState == 4) {
            if (mon_http_marker.status == 200) {

              	var return_value =mon_http_marker.responseText.split("<mon_ajax>");
          	 	if((return_value[0]=="YES")&&(return_value[2]=="DONE"))
          	 	{
	
					//alert(return_value[1]);
                    mon_remove_polyline();
                    mon_clear_markers();
                    mon_undraw_box();
                    mon_place_markers(return_value[1]);
					//eval("document.getElementById('"+mon_current_return_lookup+"').innerHTML=return_value[1]");

				}
				else
				{
				  	alert("Oppss...unable to get back the valid content"+mon_http_marker.responseText);
				}
				mon_terminate_ajax_marker();
			
            } else {
                alert('Oppss...Unable to perform your action\nThere is problem with the network connection.');
            }
        }

}


function UpdateWAYPOINTContents() {

       if (mon_http_waypoint.readyState == 4) {
            if (mon_http_waypoint.status == 200) {

              	var return_value =mon_http_waypoint.responseText.split("<mon_ajax>");
          	 	if((return_value[0]=="YES")&&(return_value[2]=="DONE"))
          	 	{
	
					
                   mon_remove_polyline();
                   
                   mon_clear_markers();
                   mon_undraw_box();
                    mon_place_waypoint(return_value[1]);
					//eval("document.getElementById('"+mon_current_return_lookup+"').innerHTML=return_value[1]");

				}
				else
				{
				  	alert("Oppss...unable to get back the valid content"+mon_http_waypoint.responseText);
				}
				mon_terminate_ajax_waypoint();
			
            } else {
                alert('Oppss...Unable to perform your action\nThere is problem with the network connection.');
            }
        }

}


function UpdateKPIREGIONContents() {

       if (mon_http_waypoint.readyState == 4) {
            if (mon_http_waypoint.status == 200) {

              	var return_value =mon_http_waypoint.responseText.split("<mon_ajax>");
          	 	if((return_value[0]=="YES")&&(return_value[2]=="DONE"))
          	 	{
	
					
                   //mon_remove_polyline();
                   //mon_clear_markers();
                mon_undraw_box();
                    mon_place_kpi_region(return_value[1]);
					//eval("document.getElementById('"+mon_current_return_lookup+"').innerHTML=return_value[1]");

				}
				else
				{
				  	alert("Oppss...unable to get back the valid content"+mon_http_waypoint.responseText);
				}
				mon_terminate_ajax_waypoint();
			
            } else {
                alert('Oppss...Unable to perform your action\nThere is problem with the network connection.');
            }
        }

}



//======================================================================================================================================================


function mon_terminate_ajax_lookup()
{
  mon_http_lookup=null;
}

function mon_terminate_ajax_post()
{
  mon_http_post=null;
}

function mon_terminate_ajax_marker()
{
  mon_http_marker=null;
}

function mon_terminate_ajax_waypoint()
{
  mon_http_waypoint = null;
}

//======================================================================================================================================================




function mon_send_get_lookup_polygons(mon_url,mon_query_string,mon_return_lookup){

    mon_clear_markers();
	document.getElementById(mon_return_lookup).innerHTML="<span class='fa fa-spin fa-circle-o-notch fa-3x'></span>";
	mon_lookup_v_mon_url=mon_url;
	mon_lookup_v_mon_query_string=mon_query_string;
	mon_lookup_v_mon_return_lookup=mon_return_lookup;
	mon_lookup_v_status=true;
	
    
    if(mon_lookup_v_status)
			{
                            
				mon_lookup_v_status=false;
				mon_current_return_lookup=mon_lookup_v_mon_return_lookup;
			  	mon_init_ajax_lookup();
			  	mon_http_lookup.onreadystatechange = UpdateLOOKUPPOLYGONSContents;
                                
			  	mon_http_lookup.open('GET', mon_lookup_v_mon_url+mon_lookup_v_mon_query_string, true);
				mon_http_lookup.send(null);
				
			
			}
	//window.setTimeout("mon_send_get_lookup_now()",1000);

}




function mon_send_get_lookup_rectangle(mon_url,mon_query_string,mon_return_lookup){

    mon_clear_markers();
	document.getElementById(mon_return_lookup).innerHTML="<span class='fa fa-spin fa-circle-o-notch fa-3x'></span>";
	mon_lookup_v_mon_url=mon_url;
	mon_lookup_v_mon_query_string=mon_query_string;
	mon_lookup_v_mon_return_lookup=mon_return_lookup;
	mon_lookup_v_status=true;
	
    
    if(mon_lookup_v_status)
			{
                            
				mon_lookup_v_status=false;
				mon_current_return_lookup=mon_lookup_v_mon_return_lookup;
			  	mon_init_ajax_lookup();
			  	mon_http_lookup.onreadystatechange = UpdateLOOKUPRECTANGLESContents;
                                
			  	mon_http_lookup.open('GET', mon_lookup_v_mon_url+mon_lookup_v_mon_query_string, true);
				mon_http_lookup.send(null);
				
			
			}
	//window.setTimeout("mon_send_get_lookup_now()",1000);

}




function mon_send_get_lookup(mon_url,mon_query_string,mon_return_lookup){

    mon_clear_markers();
	document.getElementById(mon_return_lookup).innerHTML="<span class='fa fa-spin fa-circle-o-notch fa-3x'></span>";
	mon_lookup_v_mon_url=mon_url;
	mon_lookup_v_mon_query_string=mon_query_string;
	mon_lookup_v_mon_return_lookup=mon_return_lookup;
	mon_lookup_v_status=true;
	
    
    if(mon_lookup_v_status)
			{
                            
				mon_lookup_v_status=false;
				mon_current_return_lookup=mon_lookup_v_mon_return_lookup;
			  	mon_init_ajax_lookup();
			  	mon_http_lookup.onreadystatechange = UpdateLOOKUPContents;
                                
			  	mon_http_lookup.open('GET', mon_lookup_v_mon_url+mon_lookup_v_mon_query_string, true);
				mon_http_lookup.send(null);
				
			
			}
	//window.setTimeout("mon_send_get_lookup_now()",1000);

}



function mon_send_get_lookup_now(){

            /*
			if(mon_lookup_v_status)
			{
                            
				mon_lookup_v_status=false;
				mon_current_return_lookup=mon_lookup_v_mon_return_lookup;
			  	mon_init_ajax_lookup();
			  	mon_http_lookup.onreadystatechange = UpdateLOOKUPContents;
                                
			  	mon_http_lookup.open('GET', mon_lookup_v_mon_url+mon_lookup_v_mon_query_string, true);
				mon_http_lookup.send(null);
				
			
			}
			*/
}






function mon_submit_form(form_name,form_action,div_return)
{
        
  
  var field_type;
  var field_name;
  var field_value;
  var submit_string;
  var temp_value;

  submit_string="";
  
  	eval("var form_elements_total=document."+form_name+".elements.length;");
  
    
  for(var i=0;i<form_elements_total;i++)
  	{
		try{
			eval("field_type=document."+form_name+".elements["+i+"].type;");
			eval("field_name=document."+form_name+".elements["+i+"].name;");
			eval("field_value=document."+form_name+".elements["+i+"].value;");

		  	if((field_type=="hidden")||(field_type=="text")||(field_type=="password")||(field_type=="textarea")||(field_type=="select-one")||(field_type=="radio"))
			    {

			    	//alert("Name:"+field_name+"\nType:"+field_type+"\nValue:"+field_value);
					submit_string=submit_string+field_name+"="+encodeURIComponent(field_value)+"&";
				}
			if(field_type=="file")
			    {

			    	//alert("Name:"+field_name+"\nType:"+field_type+"\nValue:"+field_value);
					submit_string=submit_string+field_name+"="+field_value+"&";
				}
			if(field_type=="checkbox")
				{
				  temp_value="";
				  eval("if(document."+form_name+"."+field_name+".checked){temp_value=field_value;}")

					submit_string=submit_string+field_name+"="+temp_value+"&";
				}

    	}
    	catch(e)
    	{

		}
	}



	mon_send_get_post(form_action,submit_string,div_return);


}




function mon_send_get_post(mon_url,mon_query_string,mon_return_post){


    //mon_clear_markers();
	document.getElementById(mon_return_post).innerHTML="<span class='fa fa-spin fa-circle-o-notch fa-3x'></span>";
	mon_lookup_v_mon_url=mon_url;
	mon_lookup_v_mon_query_string=mon_query_string;
	mon_lookup_v_mon_return_lookup=mon_return_post;
	mon_lookup_v_status=true;
	
    
    if(mon_lookup_v_status)
			{
                
                
			
				mon_lookup_v_status=false;
				mon_current_return_post   = mon_lookup_v_mon_return_lookup;
			  	mon_init_ajax_post();
			  	mon_http_post.onreadystatechange = UpdatePOSTContents;
                mon_http_post.open('POST', mon_lookup_v_mon_url, true);
                mon_http_post.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				mon_http_post.send(mon_lookup_v_mon_query_string);
				
			
			}
	//window.setTimeout("mon_send_get_lookup_now()",1000);

}














function mon_send_get_marker(mon_url,mon_query_string){
	
    mon_init_ajax_marker();
    mon_http_marker.onreadystatechange = UpdateMARKERContents;
	mon_http_marker.open('GET', mon_url+mon_query_string, true);
	mon_http_marker.send(null);
    

}

function mon_send_get_waypoint(mon_url,mon_query_string){
	
    mon_init_ajax_waypoint();
    mon_http_waypoint.onreadystatechange = UpdateWAYPOINTContents;
	mon_http_waypoint.open('GET', mon_url+mon_query_string, true);
	mon_http_waypoint.send(null);
    

}


function mon_send_get_kpi_region(mon_url,mon_query_string){
	
    mon_init_ajax_waypoint();
    mon_http_waypoint.onreadystatechange = UpdateKPIREGIONContents;
	mon_http_waypoint.open('GET', mon_url+mon_query_string, true);
	mon_http_waypoint.send(null);
    
    
    

}
//======================================================================================================================================================



function mon_add_div_content(div_id,div_content)
{

  document.getElementById(div_id).innerHTML=div_content;
}

function mon_remove_div_content(div_id)
{
  document.getElementById(div_id).innerHTML="";
}

function mon_show_div(div_id)
{
   
   document.getElementById(div_id).style.visibility="visible";
   document.getElementById(div_id).style.position="static";
  	document.getElementById(div_id).style.display="block";
}

function mon_hide_div(div_id)
{
  
  	document.getElementById(div_id).style.visibility="hidden";
    document.getElementById(div_id).style.position="absolute";
  	document.getElementById(div_id).style.display="none";
}



function show_loading()
{
	var scroll_top=document.body.scrollTop;

	//var scroll_top=window_height/2-100+document.body.scrollTop;

	
//	document.getElementById("div_loading").style.top=scroll_top+"px";
  	document.getElementById("div_loading").style.visibility="visible";
  	
  	var window_width=document.body.clientWidth;
	var window_height=document.body.clientHeight;
	
  	document.getElementById("div_loading").style.left=window_width/2-300+"px";
  	document.getElementById("div_loading").style.left=0+"px";
  	document.getElementById("div_loading").style.height=window_height+scroll_top+"px";
//	alert(document.body.clientWidth);
  	window.status="Loading...";
}

function hide_loading()
{
  	window.setTimeout("hide_loading_now()",100);

}
function hide_loading_now(){

  document.getElementById("div_loading").style.visibility="hidden";
  document.getElementById("div_loading").style.height=200+"px";
  window.status="Loaded";
}

function show_display_loading(){

    document.getElementById("div_display_content").innerHTML="<center><br><br><img src='images/loading.gif' ><br><br><font color=000000><b>Loading Data...</b></font></center>";
  window.status="Loading";
}

function hide_display_loading(){

  window.status="Loaded";
}










