﻿
function popup(mylink, windowname)
        {
        if (! window.focus)return true;
        var href;
        var size;
        var popup_width;
        if (typeof(mylink) == 'string')
            href=mylink;
        else
            href=mylink.href;
            window.open(href, windowname, 'width=600,height=800,scrollbars=No');          
           
        return false;
        }
        

function MM_openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}

 function DoClick(buttonName,e) {
        
        var key;
        
        if(window.event)
             key = window.event.keyCode;     //IE
        else
             key = e.which;     //firefox
    
        if (key == 13) {
        
            var btn = document.getElementById(buttonName);
            
            if (btn != null) { 
            
                btn.click();
                event.keyCode = 0
                
            }
        }

   }
   
   // Trim the String Space
   
   function Trim(stringToTrim) {
   
        return stringToTrim.replace(/^\s+|\s+$/g,"");
   
   }
   
// Change the Text Field to CAPS

 function ChangeToCaps(FormItem){
 
  if(FormItem.value!=FormItem.value.toUpperCase()){
  
   FormItem.value=FormItem.value.toUpperCase();
   
  }
  
 }
 
  
// Toggle visibility between none and inline 
  
 function Toggle_Visibility(itemID) { 
     
      if ((document.getElementById(itemID).style.display == 'none')) 
      { 
        document.getElementById(itemID).style.display = 'inline'; 
      } 
      else 
      { 
        document.getElementById(itemID).style.display = 'none'; 
      } 
      
  }
 
 //Show the Popup Window For Image 
 var my_window = null;
 
 function ShowPopUpImage(mImgPk,searchType)  {
    
    if (searchType == 1)
       my_window = window.open('getImage.aspx?PV=PI_ID&IMG=PI_Image&Type=1&ID='+mImgPk,'popupImage','width=800,height=600,scrollbars,resizable, return false;'); 
    
    else if (searchType == 2)
       my_window = window.open('getImage.aspx?PV=TMI_ID&IMG=TMI_Image&Type=2&ID='+mImgPk,'popupImage','width=800,height=600,scrollbars,resizable, return false;'); 

    else if (searchType == 3)
       my_window = window.open('getImage.aspx?PV=DI_ID&IMG=DI_Image&Type=3&ID='+mImgPk,'popupImage','width=800,height=600,scrollbars,resizable, return false;'); 
       
       
    my_window.focus();   
    
}

// Close the Popup Window

function ClosePopup() {

    if (my_window != null) {

         if(false == my_window.closed) 
            my_window.close (); 
    }
     
    return true;
     
}

// Clear the File Upload 

function Clear(imageValue) {
 
   imageValue.outerHTML = "<INPUT TYPE='file' NAME='<%= fupImage.ClientID %>' id='<%= fupImage.ClientID %>'>";
    
 }
 
 
// Ajax Call Back


function CreateRequest() {

   var request;
   var browser=navigator.appName;
   
   if(browser=="Microsoft Internet Explorer")
       request= new ActiveXObject("Microsoft.XMLHttp");
   else
       request=new XMLHttpRequest();

   return request;
 
 } 

//Show Save and Complete Dialog Box

function ShowSaveComplete() {

    if (document.all) {

        var OLECMDID_SAVEAS = 4;
        var OLECMDEXECOPT_DONTPROMPTUSER = 2;
        var OLECMDEXECOPT_PROMPTUSER = 1;
        var WebBrowser = "<OBJECT ID=\"WebBrowser1\" WIDTH=0 HEIGHT=0 CLASSID=\"CLSID:8856F961-340A-11D0-A96B-00C04FD705A2\"></OBJECT>";

        document.body.insertAdjacentHTML("beforeEnd", WebBrowser);

        WebBrowser1.ExecWB(OLECMDID_SAVEAS, OLECMDEXECOPT_PROMPTUSER);

        WebBrowser1.outerHTML = "";

    } 
    else {

    alert("This is only applicable to Internet Explorer");

    }

}


// Print Document 
 
function PrintDoc() {
    if (window.print) {
    
        window.print() ;  
        
    } 
    else {
        
        var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
        
        document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
        WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
        
    }
}


// Word Wrap

function WordWrap() {

    var larg_total,larg_carac,quant_quebra,pos_quebra;
    var elementos,quem, caracs, texto, display_orig;

    elementos = document.getElementsByTagName("label")

    for(var i=0; i<elementos.length;i++){
        if(elementos[i].className=="word-wrap"){
            quem = elementos[i];

            quem.innerHTML = String(quem.innerHTML).replace(/ /g,"Ø")
            texto = String(quem.innerHTML)

            quem.innerHTML = " "

            display_orig = quem.style.display;
            quem.style.display="block";
            larg_oficial = quem.offsetWidth;
            if(!document.all) quem.style.display="table";
            quem.innerHTML = texto;
            larg_total = quem.offsetWidth;

            pos_quebra = 0;
            caracs = texto.length;
            texto = texto.replace(/Ø/g," ")
            larg_carac = larg_total / caracs
            if(larg_total>larg_oficial){
                quant_quebra = parseInt(larg_oficial/larg_carac)
                quant_quebra = quant_quebra - (parseInt(quant_quebra/6)) //quanto menor o num, maior a garantia;
                quem.innerHTML = ""
                while(pos_quebra<=caracs){
                    quem.innerHTML = quem.innerHTML + texto.substring(pos_quebra,pos_quebra + quant_quebra) + " "
                    pos_quebra = pos_quebra + quant_quebra;
                }
            }else{
                quem.innerHTML = texto;
            }
            quem.style.display = display_orig;
        }
    }
}


    function GoBackPage() {
           history.go(-1);
           return false;
       }
function GoViewBackPage() {
           history.go(-2);
           return false;
       }


