var mon_logout_flag=false;

var mon_http_menu = false;
var mon_http_main = false;
var mon_http_tab_content= false;
var mon_http_display = false;

var mon_tab_name = new Array();
var mon_tab_url = new Array();
var mon_tab_query_string = new Array();
var mon_tab_content = new Array();
var mon_tab_status = new Array();
var mon_tab_div_id = new Array();


var mon_temp_tab_name = new Array();
var mon_temp_tab_url = new Array();
var mon_temp_tab_query_string = new Array();
var mon_temp_tab_content = new Array();
var mon_temp_tab_status = new Array();
var mon_temp_tab_div_id = new Array();


var mon_additional_tab_total;
var tab_adding_id;
var mon_current_selected_tab;

var mon_return_content_div_id;


var mon_current_field_return_form;
var mon_current_field_return_field;

var tab_limit=8;
mon_current_selected_tab=0;
tab_adding_id=0;
mon_additional_tab_total=0;





var mon_mouse_y;
var mon_mouse_x;


var mon_next_focus_field;
var div_display_content;



N = (document.all) ? 0 : 1;

if (N) {
	document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
}

function mon_get_mouse_position(e)
{
	if (N)
		{
			mon_mouse_y = e.pageY;
			mon_mouse_x = e.pageX;
		}
	else{
			mon_mouse_x = event.clientX + document.body.scrollLeft;
			mon_mouse_y = event.clientY + document.body.scrollTop;
  		}
}
document.onmousedown = mon_get_mouse_position;




function mon_pop_display(content){
	div_display_content=content;
	document.getElementById("div_display").style.visibility="visible";
//	document.getElementById("div_display").style.left=""+(mon_mouse_x-200)+"px";
//	document.getElementById("div_display").style.top=""+(2+mon_mouse_y)+"px";

	//document.getElementById("div_display").style.left=""+(10)+"px";
	//document.getElementById("div_display").style.top=""+(100)+"px";
	window.setTimeout("mon_pop_display_now()",200);


}

function mon_pop_display_now()
{

	document.getElementById("div_display_content").innerHTML=div_display_content;
}


function mon_init_ajax_field()
{

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

			        }

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

function mon_init_ajax_help()
{

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

			        }

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



function mon_init_ajax_menu()
{

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

			        }

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


function mon_init_ajax_display()
{

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

			        }

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




function mon_init_ajax_main()
{
		mon_http_main = false;

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

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



function mon_init_ajax_tab_content()
{
		mon_http_tab_content = false;

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

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




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 Field AJAX !');
			                    return false;
			        }
}



function mon_terminate_ajax_field()
{
  mon_http_field=null;
}

function mon_terminate_ajax_display()
{
  mon_http_display=null;
}

function mon_terminate_ajax_help()
{
  mon_http_help=null;
}


function mon_terminate_ajax_menu()
{
  mon_http_menu=null;
}

function mon_terminate_ajax_main()
{
  mon_http_main=null;
}

function mon_terminate_ajax_tab_content()
{
  mon_http_tab_content=null;
}




function mon_terminate_ajax_lookup()
{
  mon_http_lookup=null;
}


function mon_clear_dropdown(mon_form,mon_field)
{
  	//eval("for (var i=0; i < document."+mon_form+"."+mon_field+".length; i++){document."+mon_form+"."+mon_field+".options[i]=null;}")
	eval("do{document."+mon_form+"."+mon_field+".options[0]=null;}while(document."+mon_form+"."+mon_field+".length>0);")
}


function UpdateFIELDContents() {
	show_loading();
       if (mon_http_field.readyState == 4) {
            if (mon_http_field.status == 200) {

              	var return_value =mon_http_field.responseText.split("<mon_ajax>");
          	 	if((return_value[0]=="YES")&&(return_value[2]=="DONE"))
          	 		{

				    	var option_array=return_value[1].split("<option>");


				    	 	mon_clear_dropdown(mon_current_field_return_form,mon_current_field_return_field);

					  		for (var i=0; i < option_array.length; i++) {

								var option_item=option_array[i].split("|");

								var option_obj = new Option(option_item[0], option_item[1]);

							    eval("document."+mon_current_field_return_form+"."+mon_current_field_return_field+".options["+i+"]=option_obj");


						   }




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

}



function UpdateHELPContents() {

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

              	var return_value =mon_http_help.responseText.split("<mon_ajax>");
          	 	if((return_value[0]=="YES")&&(return_value[2]=="DONE"))
          	 		{
				    document.getElementById("div_help_content").innerHTML=return_value[1];

					}
				else
					{
				  	alert("Oppss...unable to get back the valid content"+mon_http_help.responseText);
					}
				mon_terminate_ajax_help();

            } else {
               alert('Oppss...Unable to perform your action\nThere is problem with the network connection.');
            }

        }

}





function mon_save_notepad(){

 	var notepad_c=escape(document.notepad_form.notepad_content.value);
  	mon_send_post("notepad/index.php","&c="+notepad_c,"div_notepad_status");

}




function UpdateNotePadContents() {
  	show_loading();
       if (mon_http_main.readyState == 4) {
            if (mon_http_main.status == 200) {
              	var return_value =mon_http_main.responseText.split("<mon_ajax>");
          	 	if((return_value[0]=="YES")&&(return_value[2]=="DONE"))
          	 		{

				    document.getElementById(mon_return_content_div_id).innerHTML=return_value[1];
					}
				else
					{
				  	alert("Oppss...unable to get back the valid content\n\nIt shows that:\n\n"+mon_http_main.responseText);
					}
				mon_terminate_ajax_main();
				hide_loading();
            } else {
                alert('Oppss...Unable to perform your action\nThere is problem with the network connection.');
            }
            hide_loading();
        }

}


function UpdateMENUContents() {
  	show_loading();
        if (mon_http_menu.readyState == 4) {
            if (mon_http_menu.status == 200) {

              	var return_value =mon_http_menu.responseText.split("<mon_ajax>");
          	 	if((return_value[0]=="YES")&&(return_value[2]=="DONE"))
          	 		{
				    document.getElementById("div_menu").innerHTML=return_value[1];

					}
				else
					{
				  	alert("Oppss...unable to get back the valid content"+mon_http_menu.responseText);
					}
				mon_terminate_ajax_menu();
				hide_loading();
				mon_animate_menu("IN","div_menu");
            } else {
               alert('Oppss...Unable to perform your action\nThere is problem with the network connection.');

            }

        	hide_loading();

        }

}


function UpdateDISPLAYContents() {
  	show_display_loading();
        if (mon_http_display.readyState == 4) {
            if (mon_http_display.status == 200) {

              	var return_value =mon_http_display.responseText.split("<mon_ajax>");
          	 	if((return_value[0]=="YES")&&(return_value[2]=="DONE"))
          	 		{
          	 		 	//document.getElementById("div_display").innerHTML=return_value[1];
          	 		 	mon_pop_display(return_value[1]);

          	 		 	//mon_pop_display(return_value[1]);


					}
				else
					{
				  	alert("Oppss...unable to get back the valid content"+mon_http_display.responseText);
					}
				mon_terminate_ajax_display();
				hide_display_loading();

            } else {
               alert('Oppss...Unable to perform your action\nThere is problem with the network connection.');

            }

        	hide_display_loading();

        }

}


function UpdateMAINContents() {
  	show_loading();
       if (mon_http_main.readyState == 4) {
            if (mon_http_main.status == 200) {
              	var return_value =mon_http_main.responseText.split("<mon_ajax>");
          	 	if((return_value[0]=="YES")&&(return_value[2]=="DONE"))
          	 		{

					document.getElementById("div_tab"+mon_tab_div_id[mon_current_selected_tab]).innerHTML=return_value[1];
						if(mon_next_focus_field!="")
						{
						   try{

						      document.getElementById(mon_next_focus_field).focus();
						      mon_next_focus_field="";
						   }
						   catch(e){
						   }

						}

					}
				else
					{
				  	alert("Oppss...unable to get back the valid content"+mon_http_main.responseText);
				  	//document.getElementById("div_tab"+mon_tab_div_id[mon_current_selected_tab]).innerHTML="ERROR";
					}
				mon_terminate_ajax_main();
				hide_loading();

            } else {
                alert('Oppss...Unable to perform your action\nThere is problem with the network connection.');
                document.getElementById("div_tab"+mon_tab_div_id[mon_current_selected_tab]).innerHTML="ERROR";
            }
            hide_loading();
        }

}


function UpdateTEMPTABContents() {
	show_loading();
       if (mon_http_tab_content.readyState == 4) {
            if (mon_http_tab_content.status == 200) {

              	var return_value =mon_http_tab_content.responseText.split("<mon_ajax>");
          	 	if((return_value[0]=="YES")&&(return_value[2]=="DONE"))
          	 		{

				    	mon_add_div_content("div_tab"+mon_tab_div_id[tab_adding_id],return_value[1]);

					}
				else
					{
				  		alert("Oppss...unable to get back the valid content"+mon_http_tab_content.responseText);
				  		mon_add_div_content("div_tab"+mon_tab_div_id[tab_adding_id],"ERROR");
					}
				mon_terminate_ajax_tab_content();
				hide_loading();

            } else {
                alert('Oppss...Unable to perform your action\nThere is problem with the network connection.');
                mon_add_div_content("div_tab"+mon_tab_div_id[tab_adding_id],"ERROR");
            }
        	hide_loading();
        }

}



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]");
					mon_lookup_v_div=false;

				}
				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 mon_send_get_help(isCheck){
    thisday = new Date();
    thistime = thisday.getTime();

	mon_url="<?php echo $etmfts_domain; ?>help/index.php";
	if(mon_tab_url[mon_current_selected_tab])
		{
			mon_query_string="?page="+mon_tab_url[mon_current_selected_tab]+"&"+thistime;
		}
	else
		{
		  	mon_query_string="?page="+"&"+thistime;
		}

    if(isCheck){
        //DPFrameMinimize('frm_1');   //hide notepad frame
        dhtmlwindow.open('help', 'iframe', mon_url+mon_query_string, 'Online Help', 'width=700px,height=450px,resize=1,scrolling=1,center=1', 'recal');
    }
    else{
        t=document.getElementById('help');  //hide help frame is uncheck
       // dhtmlwindow.close(t);
   	}

	//mon_init_ajax_help();
	//mon_http_help.onreadystatechange = UpdateHELPContents;
	//mon_http_help.open('GET', mon_url+mon_query_string, true);
	//mon_http_help.send(null);
	//document.getElementById("div_help_content").innerHTML="<center><img src=images/loading2.gif></center>";
}



function mon_send_get_field(mon_url,mon_query_string,mon_return_form,mon_return_field){

				mon_current_field_return_form=mon_return_form;
				mon_current_field_return_field=mon_return_field;

			  	mon_init_ajax_field();
			  	mon_http_field.onreadystatechange = UpdateFIELDContents;
			  	mon_http_field.open('GET', mon_url+mon_query_string, true);
				mon_http_field.send(null);

}







var mon_lookup_v_mon_url;
var mon_lookup_v_mon_query_string;
var mon_lookup_v_mon_return_lookup;
var mon_lookup_v_status;

function mon_send_get_lookup(mon_url,mon_query_string,mon_return_lookup)
{


	document.getElementById(mon_return_lookup).innerHTML="<i class='fa fa-spinner fa-pulse fa-3x fa-fw'></i><span class='sr-only'>Loading...</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;
	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 changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);


}


function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}


function mon_animate_menu(mode,div)
{
	if(mode=="IN")
	{
	 	opacity(div, 0, 100, 500);
	}
	if(mode=="OUT")
	{
		opacity(div, 100, 0, 100);

	}
}






function mon_send_get(mon_url,mon_query_string,mon_return_div){
//GET method
		if(mon_return_div=="div_menu")
			{
			 	mon_animate_menu("OUT",mon_return_div);

			  	mon_init_ajax_menu();
			  	mon_http_menu.onreadystatechange = UpdateMENUContents;
			  	mon_http_menu.open('GET', mon_url+mon_query_string, true);
				mon_http_menu.send(null);

			}
		if(mon_return_div=="div_display")
			{

			  	mon_init_ajax_display();
			  	mon_http_display.onreadystatechange = UpdateDISPLAYContents;
			  	mon_http_display.open('GET', mon_url+mon_query_string, true);
				mon_http_display.send(null);

			}

		if(mon_return_div=="div_main")
			{

			  	mon_init_ajax_main();
				show_loading();

			  	mon_http_main.onreadystatechange = UpdateMAINContents;
			  	mon_http_main.open('GET', mon_url+mon_query_string, true);
				mon_http_main.send(null);
			}
}





function mon_send_post(mon_url,mon_query_string,mon_return_div){
//POST Method
		if(mon_return_div=="div_main")
			{
			  	//http.abort;
				//http.open('post',  'back_end.php');
				//http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				//http.send('arg1=val1&arg2=val2&arg3=val3');

			  	mon_init_ajax_main();
			  	mon_http_main.onreadystatechange = UpdateMAINContents;
			  	mon_http_main.open('POST', mon_url, true);
			  	mon_http_main.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				mon_http_main.send(mon_query_string);
			}

		if(mon_return_div=="div_display")
				{
					//http.abort;
					//http.open('post',  'back_end.php');
					//http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
					//http.send('arg1=val1&arg2=val2&arg3=val3');

					mon_init_ajax_display();
					mon_http_display.onreadystatechange = UpdateDISPLAYContents;
					mon_http_display.open('POST', mon_url, true);
					mon_http_display.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
					mon_http_display.send(mon_query_string);
				}

		if(mon_return_div=="div_notepad_status")
			{
			  	mon_init_ajax_main();
			  	mon_return_content_div_id=mon_return_div;
			  	mon_http_main.onreadystatechange = UpdateNotePadContents;
			  	mon_http_main.open('POST', mon_url, true);
			  	mon_http_main.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				mon_http_main.send(mon_query_string);
			}
}

function mon_update_item(mon_url,mon_query_string,mon_return_div){
//GET method

		var update_ok=confirm("Confirm update?");
		if(update_ok)
		{
			if(mon_return_div=="div_main")
				{
				  	mon_init_ajax_main();
				  	mon_http_main.onreadystatechange = UpdateMAINContents;
				  	mon_http_main.open('GET', mon_url+mon_query_string, true);
					mon_http_main.send(null);
				}
		}
		else
		{
			return false;
		}
}


function mon_delete_item(mon_url,mon_query_string,mon_return_div){
//GET method

		delete_ok=confirm("Confirm deletion?");
		if(delete_ok)
		{
			if(mon_return_div=="div_main")
				{
				  	mon_init_ajax_main();
				  	mon_http_main.onreadystatechange = UpdateMAINContents;
				  	mon_http_main.open('GET', mon_url+mon_query_string, true);
					mon_http_main.send(null);
				}
		}
}



function mon_get_tab_content(mon_url,mon_query_string){

  				mon_init_ajax_tab_content();
			  	mon_http_tab_content.onreadystatechange = UpdateTEMPTABContents;
			  	mon_http_tab_content.open('GET', mon_url+mon_query_string, true);
				mon_http_tab_content.send(null);

}




function mon_compute_tab()
{
	var tab_content;
  	tab_content="";

  	var img1="<img border='0' src='images/tabbing/tab_active_l.gif' >";
	var img2="<img border='0' src='images/tabbing/tab_active.gif' >";
	var img3="<img border='0' src='images/tabbing/tab_active_r.gif' >";

	var imgA="<img border='0' src='images/tabbing/tab_inactive_l.gif' >";
	var imgB="<img border='0' src='images/tabbing/tab_inactive.gif' >";
	var imgC="<img border='0' src='images/tabbing/tab_inactive_r.gif' >";





   	if(mon_additional_tab_total>0)
        {
			for(var i=0;i<10;i++)
				{
					if(mon_tab_status[i]=="Y")
						{

							if(mon_current_selected_tab==i)
								{
									tab_frame1="<div class='tab_active' >";
								  	tab_link="<a class='tab_active_text' href=javascript:mon_show_tab("+i+"); >";
								  	tab_close_link="</a>";
									if(0==i)
									{
										tab_close_image="</div>";
									}
									else
									{
										tab_close_image="<a href=javascript:mon_remove_tab("+i+"); class='tab_close_button' ><span class='fa fa-times fa-lg'></span></a></div>";
									}

							  		tab_content=tab_content+tab_frame1+tab_link+mon_tab_name[i]+""+tab_close_link+tab_close_image+"";

								}
							else
								{
									tab_frame1="<div class='tab_inactive' >";
								  	tab_link="<a class='tab_inactive_text'  href=javascript:mon_show_tab("+i+"); >";
								  	tab_close_link="</a>";
									if(0==i)
									{
										tab_close_image="</div>";
									}
									else
									{
										tab_close_image="<a href=javascript:mon_remove_tab("+i+"); class='tab_close_button'  ><span class='fa fa-times fa-lg'></span></a></div>";
									}



							  		tab_content=tab_content+tab_frame1+tab_link+mon_tab_name[i]+""+tab_close_link+tab_close_image+"";
								}


						}
				}
			}

	document.getElementById("div_tab").innerHTML=""+tab_content+"";
}


function mon_compute_tab_v2_1()
{
	var tab_content;
  	tab_content="";

  	var img1="<img border='0' src='images/tabbing/tab_active_l.gif' >";
	var img2="<img border='0' src='images/tabbing/tab_active.gif' >";
	var img3="<img border='0' src='images/tabbing/tab_active_r.gif' >";

	var imgA="<img border='0' src='images/tabbing/tab_inactive_l.gif' >";
	var imgB="<img border='0' src='images/tabbing/tab_inactive.gif' >";
	var imgC="<img border='0' src='images/tabbing/tab_inactive_r.gif' >";


   	if(mon_additional_tab_total>0)
        {
			for(var i=0;i<10;i++)
				{
					if(mon_tab_status[i]=="Y")
						{

							if(mon_current_selected_tab==i)
								{
									tab_frame1="<td style='border:0px solid #888888;border-bottom:1px solid #888888;' width=1% ><br></td>";
								  	//tab_frame1="<td>"+img1+"</td>";
								  	//tab_frame2="<td>"+img3+"</td>";

								  	tab_link="<a href=javascript:mon_show_tab("+i+"); >";
								  	tab_close_link="<a href=javascript:mon_remove_tab("+i+"); >";
								  	tab_close_image="<img src='images/close.png' border=0 ></a>";

							  		tab_content=tab_content+tab_frame1+"<td style='border:1px solid #888888;border-bottom:0px solid #888888;background:#FFFFFF;' align=left  valign=top >"+tab_close_link+tab_close_image+" | "+tab_link+"<b>"+mon_tab_name[i]+"</b></a></td>";

								}
							else
								{
									tab_frame1="<td style='border:0px solid #888888;border-bottom:1px solid #888888;	filter:alpha(opacity=20);-moz-opacity:.20;opacity:.20;' width=1% ><br></td>";
								  	//tab_frame1="<td>"+imgA+"</td>";
								  	//tab_frame2="<td>"+imgC+"</td>";

								  	tab_link="<a href=javascript:mon_show_tab("+i+"); >";
								  	tab_close_link="<a href=javascript:mon_remove_tab("+i+"); >";
								  	tab_close_image="<img src='images/close.png' border=0 ></a>";

							  		tab_content=tab_content+tab_frame1+"<td style='border:1px solid #888888;background:#EEEEEE;filter:alpha(opacity=50);-moz-opacity:.50;opacity:.50;' align=left  valign=top >"+tab_close_link+tab_close_image+" | "+tab_link+mon_tab_name[i]+"</a></td>";
								}


						}
				}
			}
	//mon_current_selected_tab=-1;
	tab_content=tab_content+"<td style='border:0px solid #888888;border-bottom:1px solid #C0C0C0;' ><br></td>";
//	document.getElementById("div_tab").innerHTML="<table cellspacing='0' cellpadding='0' border='0'><tr>"+tab_content+"</tr></table>";
	document.getElementById("div_tab").innerHTML="<table cellspacing='0' cellpadding='5' border='0' ><tr>"+tab_content+"</tr></table>";
}


function mon_compile_tabs()
{
	var j=0;

		for(var i=0;i<tab_limit;i++)
			{
			 		mon_temp_tab_name[i]="";
					mon_temp_tab_url[i]="";
					mon_temp_tab_query_string[i]="";
					mon_temp_tab_content[i]="";
					mon_temp_tab_status[i]="";
				 	mon_temp_tab_div_id[i]="";
			 }


  		for(var i=0;i<tab_limit;i++)
			{

				if(mon_tab_status[i]!="Y")
			 	{

			 	 mon_tab_div_id[i]="";
			 	 /*
					mon_temp_tab_name[j]=mon_tab_name[i];
					mon_temp_tab_url[j]=mon_tab_url[i];
					mon_temp_tab_query_string[j]=mon_tab_query_string[i];
					mon_temp_tab_content[j]=mon_tab_content[i];
					mon_temp_tab_status[j]=mon_tab_status[i];
				 	mon_temp_tab_div_id[j]=i;
				 	j++;
				 	*/
				}
				else
				{

					mon_temp_tab_name[j]=mon_tab_name[i];
					mon_temp_tab_url[j]=mon_tab_url[i];
					mon_temp_tab_query_string[j]=mon_tab_query_string[i];
					mon_temp_tab_content[j]=mon_tab_content[i];
					mon_temp_tab_status[j]=mon_tab_status[i];
				 	mon_temp_tab_div_id[j]=mon_tab_div_id[i];

				 	j++;
				}

			}

  	 	for(var i=0;i<tab_limit;i++)
			{
			 		mon_tab_name[i]=mon_temp_tab_name[i];
					mon_tab_url[i]=mon_temp_tab_url[i];
					mon_tab_query_string[i]=mon_temp_tab_query_string[i];
					mon_tab_content[i]=mon_temp_tab_content[i];
					mon_tab_status[i]=mon_temp_tab_status[i];
				 	mon_tab_div_id[i]=mon_temp_tab_div_id[i];
			 }

}


function mon_add_tab(tab_name,tab_url,tab_query_string)
{
  	var is_added;
  	var is_duplicate;
  	var is_duplicate_with;
  	is_added=false;
  	is_duplicate=false;



  	 for(var i=0;i<tab_limit;i++)
		{
			if((mon_tab_url[i]==tab_url)&&(mon_tab_query_string[i]==tab_query_string))
			{
			 	is_duplicate=true;
				 is_duplicate_with=i;
			}
		}

  	if(!is_duplicate)
  	{



	    for(var i=0;i<tab_limit;i++)
			{



				if((mon_tab_status[i]!="Y")&&(is_added==false))
				{
				  	mon_current_selected_tab=i;
					mon_tab_name[i] = tab_name;
					tab_adding_id=i;


					for(var j=0;j<tab_limit;j++)
					{

						 if(document.getElementById("div_tab"+j).innerHTML=="")
						 {

							mon_tab_div_id[i]=j;
							break;

						 }
					}



					mon_get_tab_content(tab_url,tab_query_string);


					mon_tab_url[i]=tab_url;
					mon_tab_query_string[i]=tab_query_string;

					mon_tab_status[i]="Y";
	  				mon_additional_tab_total=mon_additional_tab_total+1;

					is_added=true;

				}
			}
		if(is_added)
			{
			  //mon_compile_tabs();
			  mon_compute_tab();
			  mon_show_tab(tab_adding_id)
			}
		else
			{
			  alert("Maximun "+tab_limit+" New Window Allowed!");
			}
	}
	else
	{
	  	//alert("Same Tab has been opened!");

	  	mon_show_tab(is_duplicate_with);
	}
}




function mon_show_tab(tab_id)
{
	mon_current_selected_tab=tab_id;
	mon_compute_tab();

	mon_hide_div("div_tab0");
	mon_hide_div("div_tab1");
	mon_hide_div("div_tab2");
	mon_hide_div("div_tab3");
	mon_hide_div("div_tab4");
	mon_hide_div("div_tab5");
	mon_hide_div("div_tab6");
	mon_hide_div("div_tab7");

	mon_show_div("div_tab"+mon_tab_div_id[tab_id]);

}


function mon_refresh_tab()
{
	//mon_current_selected_tab;

	tab_adding_id=mon_current_selected_tab;
	mon_get_tab_content(mon_tab_url[mon_current_selected_tab],mon_tab_query_string[mon_current_selected_tab]);

}


function mon_remove_tab(tab_id)
{
	if((mon_additional_tab_total>0)&&(tab_id!=0))
	{
		mon_remove_div_content("div_tab"+mon_tab_div_id[tab_id]);

	  	mon_tab_name[tab_id] = "";
	  	mon_tab_content[tab_id]="";
	  	mon_tab_status[tab_id]="";
	  	mon_tab_url[tab_id]="";
		mon_tab_query_string[tab_id]="";
		mon_tab_div_id[tab_id]="";


	  	mon_additional_tab_total=mon_additional_tab_total-1;

	  	mon_compile_tabs()

	  	mon_compute_tab();

	  	if(mon_additional_tab_total==0)
	  	{

		    mon_add_tab('Home','mod/welcome/index.php','');

		}
		else
		{
		 	for(var i=0;i<tab_limit;i++)
			{
			 	if((mon_tab_status[i]!="")&&(mon_tab_status[i]))
			 		{

					 	mon_show_tab(i);
					}
			}

		}
	}
	else
	{
		alert("Home cannot be closed");
	}
}


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.top="0px";
	document.getElementById("div_loading").style.height=window_height+"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><span class='fa fa-spin fa-spinner fa-2x'></span><br><br><font color=000000><b>Loading Data...</b></font></center>";
  window.status="Loading";
}

function hide_display_loading(){

  window.status="Loaded";
}
//================FOrm Submission Part=============================================================



function show_optional_field(div_form_name){
 var object_id;
 	var form_elements_total=document.getElementById(div_form_name).tBodies[0].rows.length;


  	for(var i=0;i<form_elements_total;i++)
	{
		if(document.getElementById(div_form_name).tBodies[0].rows[i].id=="field_optional"){

			document.getElementById(div_form_name).tBodies[0].rows[i].style.visibility="visible";
	    	document.getElementById(div_form_name).tBodies[0].rows[i].style.position="static";
	  		document.getElementById(div_form_name).tBodies[0].rows[i].style.display="";
	  		//document.getElementById(div_form_name).tBodies[0].rows[i].style.display="block";
		}



	}
}


function hide_optional_field(div_form_name){
var object_id;
 	var form_elements_total=document.getElementById(div_form_name).tBodies[0].rows.length;


  	for(var i=0;i<form_elements_total;i++)
	{
		if(document.getElementById(div_form_name).tBodies[0].rows[i].id=="field_optional"){
			document.getElementById(div_form_name).tBodies[0].rows[i].style.visibility="hidden";
	    	document.getElementById(div_form_name).tBodies[0].rows[i].style.position="absolute";
	  		document.getElementById(div_form_name).tBodies[0].rows[i].style.display="none";

		}



	}
}

function mon_submit_form(form_name,form_action)
{
  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_post(form_action,submit_string,"div_main");


}




function mon_submit_form_display(form_name,form_action)
{
  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_post(form_action,submit_string,"div_display");


}




var clipboard_field_type=new Array();
var clipboard_field_name=new Array();
var clipboard_field_value=new Array();
var clipboard_field_text=new Array();

function mon_copy_form(form_name)
{
	var field_type;
  	var field_total=0;
  	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;");

			  	if((field_type=="text")||(field_type=="textarea"))
				    {
				      	eval("clipboard_field_type["+i+"]=document."+form_name+".elements["+i+"].type;");
				    	eval("clipboard_field_name["+i+"]=document."+form_name+".elements["+i+"].name;");
						eval("clipboard_field_value["+i+"]=document."+form_name+".elements["+i+"].value;");
						//eval("clipboard_field_text["+i+"]=document."+form_name+".elements["+i+"].text;");
						//alert("Name:"+clipboard_field_name[i]+"\nType:"+clipboard_field_type[i]+"\nValue:"+clipboard_field_value[i]);
						field_total++;
					}
				if(field_type=="select-one")
					{
				     	eval("clipboard_field_type["+i+"]=document."+form_name+".elements["+i+"].type;");
				    	eval("clipboard_field_name["+i+"]=document."+form_name+".elements["+i+"].name;");
						eval("clipboard_field_value["+i+"]=document."+form_name+".elements["+i+"].value;");
						eval("clipboard_field_text["+i+"]=document."+form_name+".elements["+i+"][document."+form_name+".elements["+i+"].selectedIndex].text;");
						 //alert("Name:"+clipboard_field_name[i]+"\nType:"+clipboard_field_type[i]+"\nValue:"+clipboard_field_value[i]+"\nText:"+clipboard_field_text[i]);
						field_total++;
				    }
	    	}
	    	catch(e)
	    	{
			}
		}
	alert("Total of "+field_total+" field copied!");
}


function mon_paste_form(form_name)
{
	var field_type;
  		var field_total=0;
  		var selected_option;
  		eval("var form_elements_total=document."+form_name+".elements.length;");
  	for(var i=0;i<form_elements_total;i++)
	  	{
			try{

				field_type=clipboard_field_type[i];
			  	if((field_type=="text")||(field_type=="textarea"))
				    {
						eval("document."+form_name+"."+clipboard_field_name[i]+".value=clipboard_field_value["+i+"];");
						field_total++;
					}
				if(field_type=="select-one")
				    {
				      	if(clipboard_field_value[i]!="")
				      	{
				      	selected_option=0;
						eval("if(document."+form_name+"."+clipboard_field_name[i]+".length==0){}")
				    	eval("for(var j=0; j < document."+form_name+"."+clipboard_field_name[i]+".length; j++){if(document."+form_name+"."+clipboard_field_name[i]+"[j].text=='"+clipboard_field_text[i]+"'){selected_option=j;} }");

				      	eval("document."+form_name+"."+clipboard_field_name[i]+".selectedIndex="+selected_option);


				  		if(selected_option==0)
					  		{
						      	var option_obj = new Option(clipboard_field_text[i], clipboard_field_value[i]);
								eval("document."+form_name+"."+clipboard_field_name[i]+".options["+0+"]=option_obj");
								eval("document."+form_name+"."+clipboard_field_name[i]+".value=clipboard_field_value["+i+"];");
							}

						field_total++;
						}
					}
	    	}
	    	catch(e)
	    	{

			}
		}

}



function mon_logout()
{
  	var logout_msg="";

	for(var i=0;i<mon_additional_tab_total;i++)
	{
	  	logout_msg=logout_msg+"\t-"+mon_tab_name[i]+"\n";
	}
  	if(logout_msg!="")
  	{
	    logout_msg=mon_additional_tab_total+" tab(s) are open:\n"+logout_msg;
	}
  	var ok=confirm("Are you sure you want to log out from the system?\n\n"+logout_msg+" ");
  	if(ok)
  	{
	    window.location="logout/";
	}
}


function mon_image_preview(img_src,img_text)
{

   document.getElementById("frm_1_content").innerHTML="<img src='"+img_src+"'><br>"+img_text+"";
   DPFrameShow('frm_1');
}




function openNewWindow( mypage, myname, width, height, settings){
    myname = (myname=="") ? "newWindow" : myname;
    width = (width=="") ? screen.width-200 : width;
    height = (height=="") ? screen.height-200 : height;
    LeftPosition = (screen.width) ? (screen.width - width)/2 : 0;
    TopPosition = (screen.height) ? (screen.height - height-25)/2 : 0;
    if (settings==""){
        settings = 'height='+height+',width='+width+',top='+TopPosition+',left='+LeftPosition;
        settings +=',scrollbars=1,resizable=0,status=1,menubar=0';
    }else{
    	settings += ',height='+height+',width='+width+',top='+TopPosition+',left='+LeftPosition;
    }
    win=window.open(unescape(mypage),myname,settings);
    win.focus();
    return win;
}


function print_page(vurl)
{
	openNewWindow(vurl, 'Print', 960, 500, 'scrollbars=1,resizable=1,status=1,menubar=1');
}


function open_page(vurl)
{
	openNewWindow(vurl, '', 960, 500, 'scrollbars=1,resizable=1,status=1,menubar=1');
}




function mon_show_mobile_menu()
{
	document.getElementById('menu_panel').style.top="0";


}
function mon_hide_mobile_menu()
{
	document.getElementById('menu_panel').style.top="-500";

}
