
    function exist (val,obj) {
        var objLen = obj.length;
				var v;
        for (j=0; j < objLen; j++) {
						v = obj.options[j].value;
            if ( v == val )          return true;
        }
        return false;
    }
function DsplaHidden() {

document.all.navBar.style.visibility = "hidden";

}
// Copia para área de transferência
function HighlightAll() {

var tempval=document.getElementById('noticia');
							document.frm.dados.value=tempval.innerHTML
document.frm.dados.select();
			therange=document.frm.dados.createTextRange()
  			therange.execCommand("Copy")
			alert('Dados copiados !');
}


function Show(item,item2,item3){ 
if (item.style.display=='none'){ 
item.style.display=''; 
item2.src="../css/Treeview/minus.gif" 
item3.src="../img/icons/Folder_o.gif" 
} 
else{ 
item.style.display='none' 
item2.src="../css/Treeview/plusik.gif"
item3.src="../img/icons/Folder.gif" 

}
} 
	
	function MaskCNPJ(Campo, teclapres){

	var tecla = teclapres.keyCode;

	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1 ;

	
	if (tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 6)
			Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
		if (tam >= 6 && tam < 9)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
		if (tam >= 9 && tam < 13)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
		if (tam >= 13 && tam < 15)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
			
		}
}
    
    function addNewOption(objTo,f1,f2) {
    		var frm = f1.form;
    		var ag;
        var str = f1.value  + '#' + f2.value ;
    
        if ( !exist(str,objTo ) ){
    				 
             oNewOption = new Option();
    				 oNewOption.value = str;
    				 if (f1.text!=null) { ag = f1.text; }else{ ag = f1.value } ;
             oNewOption.text = ag + ' » ' + f2.options[f2.selectedIndex].text;				 				 
    	       objTo.add(oNewOption, objTo.length+1);	    
      	     with(frm) {		    
              //f1.selectedIndex = 0;					
    					//f2.selectedIndex = 0;
       	     } 
          }else{
             alert('O elemento escolhido já consta na lista !');
             f1.focus();
          }	  
    }
    function RemoveOption(objFrom) {
    				
    		if (objFrom.selectedIndex>0) {         
            var itemNo = objFrom.selectedIndex;
            var obj = objFrom.options[itemNo];
      
            if (trim(obj.text)!=''){
                var resp = confirm('Confirma remoção do item '+ obj.text + '? ');
                if (resp)       objFrom.options[itemNo]=null;
            }
    		}
    }
    		
    function currency( num ) 
    { 
       var prefix = "R$"; 
       var suffix = ""; 
       if ( num < 0 ) 
       { 
           prefix = "(R$"; 
           suffix = ")"; 
           num = - num; 
       } 
           var temp = Math.round( num * 100.0 ); // convert to pennies! 
           if ( temp < 10 ) return prefix + "0,0" + temp + suffix; 
           if ( temp < 100 ) return prefix + "0," + temp + suffix; 
           temp = prefix + temp; // convert to string! 
           return temp.substring(0,temp.length-2) + "," + temp.substring(temp.length-2) + suffix; 
    }
    		
    function fullwin(targeturl, winname){
       
      var win = window.open(targeturl,winname,"menubar=1,scrollbars=1,history=1,titlebar=no,status=yes,toolbar=yes,hotkeys=yes,alwaysRaised=yes")	 
    	win.moveTo(-5,-26);
    	 
    	win.resizeBy(0,0);	 
    	win.resizeTo(screen.availWidth+25,screen.availHeight+25);
    
    }

    var counter=0;
    function PopUp ( url,w,h,s,scroll,rsz )          {
       var l = (screen.availWidth/2)-(w/2);
    	 var t = (screen.availHeight/2)-(h/2);
    	 var opt = "status="+s+",menubar=no,scrollbars="+scroll+",history=no,top="+t+",left="+l+",width="+w+",height="+h+" ";
    	 if (rsz) opt = opt + ",resize=yes"  
       window.open (url,'',opt); 
    }
    	    
    function makeObj(obj,nest){
    	nest=(!nest) ? '':'document.'+nest+'.'
       	this.css=(is.b=='ns') ? eval(nest+'document.'+obj):eval(obj+'.style')							
    	this.moveIt=b_moveIt;
    }
		
    function b_moveIt(x,y){
    	this.x=x; this.y=y
       	this.css.left=this.x
    	this.css.top=this.y
    }
    /********************************************************************************
    Initilizing the page, getting height and width to moveto and calls the 
    object constructor
    ********************************************************************************/
    var pageWidth,pageHeight
    function geoInit(r,b){
    	alert (r + '\n' + b );
    	oTest=new makeObj('divBottom')
    	pageWidth=(is.b=='ie')?document.body.offsetWidth-4:innerWidth;
    	pageHeight=(is.b=='ie')?document.body.offsetHeight-2:innerHeight;
    	checkIt(r,b)
    	if(is.b=='ie') window.onscroll=checkIt;
    }
    /********************************************************************************
    This function executes onscroll in ie and every 30 millisecond in ns
    and checks if the user have scrolled, and if it has it moves the layer.
    ********************************************************************************/
    function checkIt(gright,gbottom){
    	if(is.b=='ie') oTest.moveIt(document.body.scrollLeft +pageWidth-gright,document.body.scrollTop+pageHeight-gbottom)
    	else if(is.b=='ns'){
    		oTest.moveIt(window.pageXoffset+pageWidth-gright, window.pageYoffset+pageHeight-gbottom)
    		setTimeout('checkIt()',20)
    	}
    }
    
    function RaiseButton ( obj, cls ) {   
		  cls = (cls==undefined ? 'cmdRaiseBtn' : cls );
      obj.className = cls;
    }
    
    function NormalButton ( obj, cls ) {
		  cls = (cls==undefined ? 'cmdBtn' : cls );		
      obj.className = cls;
    }
    
    function PressButton ( obj, cls ) {
		  cls = (cls==undefined ? 'cmdDepressedBtn' : cls );		
      obj.className = cls;
    }
    
    
    function get_mouse(e) 
    {
    	var x = (nav) ? e.pageX : event.x+document.body.scrollLeft; 
    	var y = (nav) ? e.pageY : event.y+document.body.scrollTop;
    	skn.left = x+5;
      skn.top  = y+3;
    }
    
    function kill() 
    {
        skn.visibility = "hidden";
        document.all("topdeck").innerHTML="";
    }
    
    
    function StatusBar( msg, sty ) { 
          var str;
    		  var obj;
    
    		  switch ( sty ){
    		   case 0:
    			   str = "<FONT>" + msg + "</FONT>";
    				 break;
    		   case 1:
    			   str = "<MARQUEE direction=left width=97% scrollamount=10>" + msg + "</MARQUEE>";
    				 break;
    		  } 
    		  obj = document.getElementById("status");
    
      		if (obj!=null){
       		  if (obj.innerHTML != str ) obj.innerHTML = str  		   
      		}else{
      		   window.status=msg;
      		}	
    }
    		
    function DrawIlayer(id,w,h,sSrc){
      document.write('<iframe frameborder="0" src="'+sSrc+'" width="'+w+'" height="'+h+'" name="'+id+'" id="'+id+'" marginWidth="0" marginHeight="0"><ilayer src="'+sSrc+'" name="'+id+'" width="'+w+'" height="'+h+'" visibility="Hide" id="'+id+'"></ilayer></iframe>');
    }
    
    function SendToServer(p,sQueryString){	 
      	 // the URL of the script on the server to run
      
      var sURL = p;
      // if you need to pass any variables to the script, then populate the following string with a
      // valid query string
      // var sQueryString = "";
      var sQSDelim = "?";
    
      // if the query string variable isn't blank, then append it to the URL
      if( sQueryString.length > 0 ){
     	  if (p.indexOf('?')<=0) 
              sURL = sURL + sQSDelim;					  	
          sURL = sURL + sQueryString;
    
      }
    	  var sQSDelim = "&";
      // this will append a random number to the URL string that will ensure the document isn't cached
      sURL = sURL + sQSDelim + Math.random();
      //alert(sURL);
      //return false;
      // if IE then change the location of the IFRAME
    
      if( document.all ){
      	// this loads the URL stored in the sURL variable into the hidden frame
      	document.idServer.location = sURL;
      
      // otherwise, change Netscape v6's IFRAME source file
      } else if( document.getElementById ){
      	// this loads the URL stored in the sURL variable into the hidden frame
      	document.getElementById("idServer").contentDocument.location = sURL;
      
      // otherwise, change Netscape v4's ILAYER source file
      } else if( document.layers ){
      	// this loads the URL stored in the sURL variable into the hidden frame
      	document.idServer.src = sURL;
      }
      
      return true;
    }		

		function SelectOpt1(pg, o, fld, sel)
    {
        var f = o.form;
      	var url = pg+'?sUfSigla='+o.value+'&cfield='+fld+'&frm='+f.name+'&sel='+sel;
			divHidden.location.href = url;				 	
    }
    
    function SelectOpt2(pg,obj1, obj2, fld, frm, sel)
    {
		    var f = obj2.form;
			var url = pg+'?sUfSigla='+obj1.value+'&nMunCod='+obj2.value+'&cfield='+fld+'&frm='+f.name+'&sel='+sel;
        divHidden.location.href = url;
    }
 

		function addOption(obj,val,text){
			 var oNewOption;
       oNewOption = new Option();
			 oNewOption.value = val;
			 oNewOption.text = text;
			 if (exist(val,obj)) {
					 return false; 
       }						    										 
			 obj.add(oNewOption,obj.length+1);
		}
	
		function addCity(obj,val,text){
			 var oNewOption;
       oNewOption = new Option();
			 oNewOption.value = val;
			 oNewOption.text = text;
			 if (exist(val,obj)) {
					 return false; 
       }						    										 
			 obj.add(oNewOption,obj.length+1);
		}	
		

    function OpenWin ( url,win,w,h,s,scroll,rsz )    
		{	

       var l = (w!='100%')?parseInt((screen.availWidth/2)-(w/2)):0;
       var t = (h!='100%')?parseInt((screen.availHeight/2)-(h/2)):0;			 

	     //var w = (w.indexOf('%')>0)?((screen.availWidth*parseInt(w))/100 ):w;
       //var h = (h.indexOf('%')>0)?((screen.availHeight*parseInt(h))/100):h;			 

       scroll = (scroll==true || scroll=='yes' || scroll==1)?'yes':'no';
       var opt = "status="+s+",menubar=yes,scrollbars="+scroll+",resizable="+rsz+",history=no,top="+t+",left="+l+",width="+w+",height="+h+" ";
       window.open (url,win,opt);			  
     }		
		 
    function displayDiv(name){
    	if (document.all[name].style.display==''){
    		  document.all[name].style.display='none';
    	}else{
    		  document.all[name].style.display='';
    	}
    }		 
		
    function colapse(name, expandImg, colapseImg){

		  var oImg = document.getElementById('IMG_'+name);
    	if (document.all[name].style.display==''){
    		  document.all[name].style.display='none';
					oImg.src = expandImg;
    	}else{
    		  document.all[name].style.display='';
					oImg.src = colapseImg;					
    	}
			
    }		 		

		 
		 
    function hideDiv(arr){

				var lyr;
				for (i=0;i<arr.length;i++) {
						lyr = document.getElementById(arr[i]);					 
						lyr.style.display = 'none';
				}		

    }		
		
    function ShowHideDiv(arr, flag){

				var lyr;
				for (i=0;i<arr.length;i++) {
						lyr = document.getElementById(arr[i]);
						if (lyr) lyr.style.display = (flag==0) ? 'none' : 'block';
				}		

    }		
		 
    function showDiv(arr){
						 
				for (i=0;i<arr.length;i++)	 
						document.all[arr[i]].style.display='none';

    }				
		
		function LimitChars(o,max,lyr){
			 var divChar = document.getElementById(lyr);
			 divChar.innerText = eval(o.value.length) + ' caracteres. Restantes ' + eval(max -o.value.length) ;			 
		   if (o.value.length>max){
			    alert('O número máximo de caracteres permitido é '+ max );
					o.value = o.value.substring(o.value,max);
					LimitChars(o,max,lyr) 
			 		return false;
			 }					 
		}

		var imgPath = '/sop/mercado/img';
		function DisplayInfo(p_title,p_msg,p_goto,w,h,p_action,icon) {

			 //var dlgURL = 'info.asp?msg='+p_msg;
			 var html;
			 var t;			 		
			 var sIcon;
			 switch(icon.toUpperCase()){
			 	  case 'MB_INFORMATION':
					  sIcon = 'info.gif'
					  break;
			 	  case 'MB_CRITICAL':
					  sIcon = 'critical.gif'
					  break;
			 	  case 'MB_EXCLAMATION':
					  sIcon = 'alert.gif'
					  break;
			 	  case 'MB_QUESTION':
					  sIcon = 'question.gif'
					  break;																		
			 }
			 html = '<HTML><HEAD><TITLE>'+p_title+'</TITLE></HEAD><BODY STYLE="background:buttonface">';
			 html += '<TABLE width="100%" height="100%" border="0" cellspacing="1">';
 			 html += ' <TR>';
 			 html += '   <TD ALIGN="CENTER" VALIGN="MIDDLE">';			 
			 html += '    &nbsp;<IMG SRC="'+ imgPath +'/'+ sIcon +'">&nbsp;';
			 html += '   </TD>';
    	 	 html += '   <TD width="100%" VALIGN="MIDDLE" style="font:Message-Box;padding-left:8px">'+p_msg+'&nbsp;</TD>';
 			 html += ' <TR>';
 			 html += '   <TD COLSPAN="2" ALIGN="CENTER" VALIGN="top">';
			 html += '     <button Title="Ok" onclick="window.close();window.returnValue=true;" style="font:icon;background:buttonface;width:80px">Ok</button>';
			 html += '   </TD>';
 			 html += ' </TR>';
 			 html += '</TABLE>';
 			 html += '</BODY></HTML>';

			 var o; 
			 var ok = window.showModalDialog("javascript:document.write('"+html+"')",o,'resizable:no;edge:raised;scroll:no;help:no;dialogHeight:'+h+'px;dialogWidth:'+w+'px;center;status:0');

			 if (p_action!='')			 eval(p_action);			 																																																 
    }
		
    // ===================================================================
    // Author: Matt Kruse <matt@mattkruse.com>
    // WWW: http://www.mattkruse.com/
    //
    // NOTICE: You may use this code for any purpose, commercial or
    // private, without any further permission from the author. You may
    // remove this notice from your final code if you wish, however it is
    // appreciated by the author if at least my web site address is kept.
    //
    // You may *NOT* re-distribute this code in any way except through its
    // use. That means, you can include it in your product, or your web
    // site, or any other form where the code is actually being used. You
    // may not put the plain javascript up on your site for download or
    // include it in your javascript libraries for download. 
    // If you wish to share this code with others, please just point them
    // to the URL instead.
    // Please DO NOT link directly to my .js files from your site. Copy
    // the files to your server and use them there. Thank you.
    // ===================================================================
    
    // -------------------------------------------------------------------
    // autoComplete (text_input, select_input, ["text"|"value"], [true|false])
    //   Use this function when you have a SELECT box of values and a text
    //   input box with a fill-in value. Often, onChange of the SELECT box
    //   will fill in the selected value into the text input (working like
    //   a Windows combo box). Using this function, typing into the text
    //   box will auto-select the best match in the SELECT box and do
    //   auto-complete in supported browsers.
    //   Arguments:
    //      field = text input field object
    //      select = select list object containing valid values
    //      property = either "text" or "value". This chooses which of the
    //                 SELECT properties gets filled into the text box -
    //                 the 'value' or 'text' of the selected option
    //      forcematch = true or false. Set to 'true' to not allow any text
    //                 in the text box that does not match an option. Only
    //                 supported in IE (possible future Netscape).
    // -------------------------------------------------------------------
    function autoComplete (field, select, property, forcematch) {
    	var found = false;
    	for (var i = 0; i < select.options.length; i++) {
    	if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) == 0) {
    		found=true; break;
    		}
    	}
    	if (found) { select.selectedIndex = i; }
    	else { select.selectedIndex = -1; }
    	if (field.createTextRange) {
    		if (forcematch && !found) {
    			field.value=field.value.substring(0,field.value.length-1); 
    			return;
    			}
    		var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
    		if (cursorKeys.indexOf(event.keyCode+";") == -1) {
    			var r1 = field.createTextRange();
    			var oldValue = r1.text;
    			var newValue = found ? select.options[i][property] : oldValue;
    			if (newValue != field.value) {
    				field.value = newValue;
    				var rNew = field.createTextRange();
    				rNew.moveStart('character', oldValue.length) ;
    				rNew.select();
    				}
    			}
    		}
    	}
		
 
 	   function getUsers(){

				var f = document.frm_chm;
				var ok = false;
				

                var dlgURL = 'frm_email.asp';
                var listMail; 
                var retValue = window.showModalDialog(dlgURL,listMail, 'resizable:no;edge:raised;scroll:no;help:no;dialogHeight:300px;dialogWidth:400px;center;status:0');
  							if (retValue!=undefined && retValue!=null && retValue!='') {
                        f.EMAIL_ENV_PARA.value = retValue;
                   
											 
    					 }
				
		 }
		 
		 
		 			function returnUsers ( o ) {
    			
					var a = new Array();
					var sUser = '';
					var cont = 0;
					for (i=0; i<o.options.length; i++) { 
								if (o.options[i].selected) {
									  sUser += o.options[i].value + ','; 
										cont++;
								}		
					}
					sUser = sUser.substring(0,sUser.length-1);
    					window.returnValue = sUser;
    					window.close();
										
			}	 		 		


 
function Refresh(pageMain){

	window.opener.location.href=pageMain;
	
	
}

function printElementID(id,pg){
	
	var oPrint,oJan;
	oPrint=window.document.getElementById(id).innerHTML;
		oJan=window.open(pg);
			oJan.document.write(oPrint);
	oJan.history.go();
		oJan.window.print();
	
	
}
/*function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
*/    // -------------------------------------------------------------------
    // TabNext()
    // Function to auto-tab phone field
    // Arguments:
    //   obj :  The input object (this)
    //   event: Either 'up' or 'down' depending on the keypress event
    //   len  : Max length of field - tab when input reaches this length
    //   next_field: input object to get focus after this one
    // -------------------------------------------------------------------
    var phone_field_length=0;
    function TabNext(obj,event,len,next_field) {
    	if (event == "down") {
    		phone_field_length=obj.value.length;
    		}
    	else if (event == "up") {
    		if (obj.value.length != phone_field_length) {
    			phone_field_length=obj.value.length;
    			if (phone_field_length == len) {
    				next_field.focus();
    				}
    			}
    		}
    	}

	function PageNavigator() {
     var i;
		 var args=PageNavigator.arguments;

     var s = '';
  	 s += (args[1]==1)?'<span style="color:silver" ALT="Primeiro" class=move>&#57</span>':'<a href="javascript:nav('+args[0]+')"" ALT="Primeiro" class=move>&#57</a>';		 
  	 s += '  |  ';	 
  	 s += (args[1]==1)?'<span style="color:silver" ALT="Anterior" class=move>&#55</span>':'<a href="javascript:nav('+eval(args[1]-1)+')"" ALT="Anterior" class=move>&#55</a>';
  	 s += '  |  ';	 	 
  	 s += (args[1]==args[2])?'<span style="color:silver" ALT="Próximo" class=move>&#56</span>':'<a href="javascript:nav('+eval(args[1]+1)+')"" ALT="Próximo" class=move>&#56</a>';
  	 s += '  |  ';
  	 s += (args[1]==args[2])?'<span style="color:silver" ALT="Último" class=move>&#58</span>':'<a href="javascript:nav('+args[2]+')"" ALT="Último" class=move>&#58</a>';		 	 	 		 			 			 	 
		 s += '<BR>';
		 if (args[2]>args[1]){
    	 s += '<B>Página</B>  ';
    	 s += '<SELECT name="pagenum" onChange="nav(this.value)">';
    	 s += '   <OPTION VALUE="">--</OPTION>';
    	 for (i=1;i<=args[2];i++)
       	 	  s += '   <OPTION VALUE="'+i+'">'+i+'</OPTION>';
    	 s += '</SELECT>';	 	
		 } 	 	 	 		 	
		 document.write(s);		 			 	 	 														
  }
	
	function nav(pgnum){
      url = '?page='+pgnum;
      location.href=url;
	}
		
	/*=================================================================================*/
	
				function over(objet){ objet.style.background = '#FFFFFF'; objet.style.color = '#000000';}
				function notover(objet) {objet.style.background = 'buttonface';objet.style.color = '#000000';}
				
				//Action executer lors du passage sur un tr
				function overtr(objet) {objet.style.background = 'navy';	objet.style.color = '#FFFFFF';}
				
				function notovertr(objet, ovrColor, ovrFontColor){
				     objet.style.background = (ovrColor!=undefined) ? ovrColor : '#FFFFFF';
						 objet.style.color = (ovrFontColor!=undefined) ? ovrFontColor : '#000000';	
				}

				//function goto(url){document.location = url;}
				
				function selected(objet){
					if (objet.style.background == 'navy')	{
						  objet.style.background = 'navy';	
							objet.style.color = '#FFFFFF';
					}else{ 
							objet.style.background = '#FFFFFF';
							objet.style.color = '#000000';
					}									
				}
				
				function SwapMode()
				{
					if (document.all['advancedfields'])
					{
						if (document.all['advancedfields'].style.display == 'none') 
						{
						    document.all['advancedfields'].style.display = 'block';
							document.all['swaper'].innerHTML = '<img  src="media/collapse.gif" hspace="4" align="middle"/><xsl:value-of select="$string[440]"/>';						    
						}
						else  
						{
							document.all['advancedfields'].style.display = 'none';
							document.all['swaper'].innerHTML = '<img  src="media/expand.gif" hspace="4" align="middle"/><xsl:value-of select="$string[439]"/>';
						}
					}
				}
	
				function ShowHideDiv2(div,div2)
				{
					if (div2!='') document.all[div2].style.display = 'none';
					var o = document.getElementById(div);
					//if (o)
					//{
					o.style.display = 'block';
								alert(o.style.display);
					//}	
				}				

	var imgPath = 'sop/mercado/img';
		function DisplayInfo(p_title,p_msg,p_goto,w,h,p_action,icon) {

			 var html;
			 var t;			 		
			 var sIcon;								 
			 switch(icon){
			 	  case 'info':
					  sIcon = 'info.gif' 
					  break;
			 	  case 'critical':		 
					  sIcon = 'critical.gif'					
					  break;
			 	  case 'alert':						 
					  sIcon = 'alert.gif'					
					  break;
			 	  case 'question':			
					  sIcon = 'question.gif'					
					  break;																		
			 }
			 html = '<HTML><HEAD><TITLE>'+p_title+'</TITLE></HEAD><BODY STYLE="background:buttonface">';
			 html += '<TABLE width="100%" height="100%" border="0" cellspacing="1">';
 			 html += ' <TR>';
 			 html += '   <TD ALIGN="CENTER" VALIGN="MIDDLE">';			 
			 html += '    &nbsp;<IMG SRC="/'+ imgPath +'/'+ sIcon +'"/>&nbsp;';
			 html += '   </TD>';
    	 html += '   <TD width="100%" VALIGN="MIDDLE" style="font:icon;padding-left:8px">'+p_msg+'&nbsp;</TD>';
 			 html += ' <TR>';
 			 html += '   <TD COLSPAN="2" ALIGN="CENTER" VALIGN="top">';
			 html += '     <button Title="Ok" onclick="window.close();window.returnValue=true;" style="font:icon;background:buttonface;width:80px">Ok</button>';
			 html += '   </TD>';			 			 
 			 html += ' </TR>';
 			 html += '</TABLE>';
 			 html += '</BODY></HTML>';			 			 			 			 						  			 
			 var o; 
			 var ok = window.showModalDialog("javascript:document.write('"+html+"')",o,'resizable:no;edge:raised;scroll:no;help:no;dialogHeight:'+h+'px;dialogWidth:'+w+'px;center;status:0');

			 if (p_action!='')			 eval(p_action);			 																																																 
    }
	/*=================================================================================*/
	/* Sub Form*/
/****************************************************************/
/* Declare variables */
var lastno = 0; // last table row number
var onno = 0; // 
var lastobj ; // last row object

function prepareClone(oname,n)
{
	if (n.value !="") {
		xno = n.id;
		re = /_([^_]*)$/;
		r = xno.search(re);
		xno = xno.substr(r+1);
		// Find the row number and prepare the last row element to be copied
		lastno = 0;
		findlastTR(eval("document.all."+oname + xno+".parentNode"),oname);
		if (lastno < 501) clone(eval("document.all."+oname + xno),oname); // do not clone if total number of rows is greater than 500,you can change this limit
	}
}

function clone(hobj,oname)
{
	//Copy the table row element and paste it 
	//Clean all the content of pasted row.
	idx = hobj.id;
	re = /_([^_]*)$/;
	r = idx.search(re);
	idx = idx.substr(r+1);  
	idx= parseInt(idx)+1;
	// Be sure the row which is intented to be copied ,is the last row
	if ( typeof(document.all[oname+idx]) == "undefined" )
	{
		// If the row is the last row
		var oCloneNode =hobj.cloneNode(true);
		// Copy the row
		var pnode = hobj.parentNode;
		// And paste it into table
		pnode.appendChild(oCloneNode);
		
		// Number each rows again
		lastno=0;
		addSections(hobj.parentNode,oname);

		// Find pasted row
		lastno=0;
		findlastTR(hobj.parentNode,oname);
		// Delete all the content of elements inside the row
		clearAll(lastobj);
			document.frm.count.value=lastno-1;
	}
}

function addSections(n,oname) {
	// Number each rows id and name again
	if (n.tagName == "TR" && (n.id).search(oname) >= 0) {lastno = lastno +1;}
		if (typeof(n.id) != "undefined" && n.id != "" && typeof(n.name) != "undefined" && n.name != "") { 
			xno = n.id;
			// Take the number after underscore
			re = /_([^_]*)$/; 
			r = xno.search(re);
			xno = xno.substr(0,r); 
			xno = xno+"_"+lastno;
			// Count the rows and then write the last number to rows id and name
			n.id = xno;
			xname = n.name;
			r = xname.search(re);
			xname = xname.substr(0,r);  
			xname = xname+"_"+lastno;
			n["name"] = xname;
			// If the changed property is set to 'auto', automatic number is written to each row
			if (n.tagName == "INPUT" && n.changed == "auto") {
				if (lastno != onno)	{n.value = lastno;}
			}
			if (n.tagName == "DIV" && n.changed == "auto") {
				if (lastno != onno)	{ n.innerHTML = lastno;}
			}
		}
        for(var m = n.firstChild; m != null; m = m.nextSibling) {
			xlastno = lastno;
			// Continue until last element found in the table
			addSections(m,oname);
		}
		
    }

function findlastTR (n,oname)
{
		// Find the last table row number.It counts table rows only whose id is same as the string passed by 'oname'.
	if (n.tagName == "TR" && (n.id).search(oname) >= 0) {
		lastobj = n;
		lastno = lastno +1;
	}
	for(var m = n.firstChild; m != null; m = m.nextSibling) {
		// Continue until last element found in the table
		findlastTR(m,oname);
	}
}

function clearAll (n)
{
	if (n.changed != "keep") // Elements content will be deleted unless changed property is set to 'keep'.
	{
		if (n.tagName == "INPUT" && n.type !="button" || n.tagName== "TEXTAREA") {
			n.value="";
			if(n.type == "checkbox") n.checked = false;
		}
		if (n.tagName == "SELECT") {
			n.selectedIndex = 0;
		}
		if (n.tagName == "DIV") {
			n.innerHTML = "";
		}
	}
	for(var m = n.firstChild; m != null; m = m.nextSibling) {
		// Continue until last element found in the table
		clearAll(m);
	}
}

function removeClone(receivedID,nobj,oname,tname)
{
	// Remove the row by proper id that came from delete button
	idx = nobj.id;
	re = /_([^_]*)$/;
	r = idx.search(re);
	idx = idx.substr(r+1);  
	idx= parseInt(idx)+1; // Found to determine if the row is last row
	// If the selected row is not last row,it will be deleted
	if ( typeof(document.all[oname+idx]) != "undefined" )
	{
		eval(tname+".deleteRow(receivedID)");
		onno = lastno - 1;
		lastno = 0;	
		addSections(eval("document.all."+tname),oname); // Put rows ids in order.

		lastno = 0;
		findlastTR(eval("document.all."+tname),oname); // Find last tablerow

		clearAll(lastobj); // Delete contents of last row's input, select, textarea and div elements 
		onno = 0;
	}
}

function clearsubmit(oname,tname)
{
	// Delete last empty row to prevent the last row's content recorded into database
	lastno = 0;
	findlastTR(eval("document.all."+tname),oname); // Find last row number
	eval(tname+".deleteRow(document.all[oname+lastno].rowIndex)"); // Delete last empty row
}
function validate() {
	clearsubmit('trow_','tblGrid'); // Delete last empty row
	return true;
}

/****************************************************************/