﻿// +---------------------------------------------------------+
// | NAME           : jsCommo.js
// |
// | DESCRIPTION    : Common Javascript code snippets
// |                : 
// |
// | VERSION        : 1.2
// | CREATED BY     : Blaine Jenkins
// | MODIFIED BY    : 
// |
// |               (c) 2007 Cissec Corporation
// +---------------------------------------------------------+



function closeWindow() {

  pause(200); //ALLOWS THE DOM TO LOAD on SLOW MACHINES
  
  //CHECK BROWSER
  var x = navigator;
      try{
        if (x.appName == 'Microsoft Internet Explorer'){
            //IS INTERNET EXPLORER
            window.close();
        }else{
            //IS SOME OTHER BROWSER
            var myparent = window.parent.opener;
            var returnobj = window.open('','_parent','');
            myparent.location.href = myparent.location.href;
            returnobj.close();
        }
    
    }
	catch(err)
        {
         txt="The security settings on your browser prevented the\n";
	 	 txt+="application from providing the requested content.\n\n";
	 	 txt+="Please ensure all pop-up blockers are turned off,\n";
	 	 txt+="and you have added this websites URL to your trusted sites.\n\n";
	
	     txt+="Error number: " + (err.number & 0xffff) + "\n\n";
	     txt+="Error description: " + err.description + "\n\n";
 	     txt+="Click OK to continue.\n\n";
	     alert(txt);
   }//END CATCH
  
}//------------------------------------------


function ShowDialog(formIdx,Destination,Height,Width){

    var retval=""; 
    var txt = "";
	var dlgLeft = Math.round(window.screen.availWidth /2-Width/2);
	var dlgTop = Math.round(window.screen.availHeight/2-Height/2);

   //CHECK BROWSER
   // FOR IE SHOW MODAL WINDOW
   // FOR ALL OTHERS SHOW REGULAR WINDOW

   try
    {
           var x = navigator;
           
           if (x.appName == 'Microsoft Internet Explorer'){
            //IS INTERNET EXPLORER
            
                retval = window.showModalDialog(Destination,'window_'+ formIdx,'dialogHeight=' + Height + 'px;dialogWidth=' + Width + 'px;dialogLeft=' + dlgLeft+'px;dialogTop=' + dlgTop + 'px;status=yes;help=no;'); 
          
                //CODE WAITS FOR RETURN
                
                switch (retval)
	                {
	                    case '1': // force parent refresh
        	               
			                document.forms[formIdx].submit();
        			        
			                break;
			            case '0':
        		            //Do nothing			       
			                break;
		                default:
			                if ((retval!="" && retval!=null))
			                {
				                //Unknow so Repost anyway
			   	                document.forms[formIdx].submit();
			                }		
	                }//switch
           }
           else{
                //IS SOME OTHER BROWSER
                window.open(Destination,'window_'+ formIdx,'scrollbars=no,menubar=no,height=' + Height + ',width=' + Width + ',resizable=yes,toolbar=no,location=no,status=no');
           }
    }catch(err){
         txt="The security settings on your browser prevented the\n";
	 	 txt+="application from providing the requested content.\n\n";
	 	 txt+="Please ensure all pop-up blockers are turned off,\n";
	 	 txt+="and you have added this websites URL to your trusted sites.\n\n";
	
	     txt+="Error number: " + (err.number & 0xffff) + "\n\n";
	     txt+="Error description: " + err.description + "\n\n";
 	     txt+="Click OK to continue.\n\n";
	     alert(txt);
         
    }//END CATCH


}//+---------------------------------------- ShowDialog

function ShowMaxDialog(formIdx,Destination,offsetx, offsety){

    var retval=""; 
    var txt = "";
	if((offsetx == 'undefinded')||(offsetx == '')){offsetx = 20;}
	if((offsety == 'undefinded') ||(offsety == '') ){offsety = 40;}
	
	//FORCE SIZE
	Height = window.screen.availHeight - offsety;
	Width = window.screen.availWidth - offsetx;
	var dlgLeft = window.screen.availWidth /2-Width/2;
	var dlgTop = window.screen.availHeight/2-Height/2;

   //CHECK BROWSER
   // FOR IE SHOW MODAL WINDOW
   // FOR ALL OTHERS SHOW REGULAR WINDOW

   try
    {
           var x = navigator;
           
           if (x.appName == 'Microsoft Internet Explorer'){
            //IS INTERNET EXPLORER
            
                retval = window.showModalDialog(Destination,'window_'+ formIdx,'dialogHeight=' + Height + 'px;dialogWidth=' + Width + 'px;dialogLeft=' + dlgLeft+'px;dialogTop=' + dlgTop + 'px;status=yes;help=no;'); 
          
                //CODE WAITS FOR RETURN
                
                switch (retval)
	                {
	                    case '1': // force parent refresh
        	               
			                document.forms[formIdx].submit();
        			        
			                break;
			            case '0':
        		            //Do nothing			       
			                break;
		                default:
			                if ((retval!="" && retval!=null))
			                {
				                //Unknow so Repost anyway
			   	                document.forms[formIdx].submit();
			                }		
	                }//switch
           }
           else{
                //IS SOME OTHER BROWSER
                window.open(Destination,'window_'+ formIdx,'scrollbars=no,menubar=no,height=' + Height + ',width=' + Width + ',resizable=yes,toolbar=no,location=no,status=no');
           }
    }catch(err){
         txt="The security settings on your browser prevented the\n";
	 	 txt+="application from providing the requested content.\n\n";
	 	 txt+="Please ensure all pop-up blockers are turned off,\n";
	 	 txt+="and you have added this websites URL to your trusted sites.\n\n";
	
	     txt+="Error number: " + (err.number & 0xffff) + "\n\n";
	     txt+="Error description: " + err.description + "\n\n";
 	     txt+="Click OK to continue.\n\n";
	     alert(txt);
         
    }//END CATCH


}//+---------------------------------------- ShowDialog



function PageNavigation(strPage){
//FUNCTION SIMPLY DOES A  PAGE SHIFT
		//alert(strPage);
	if (strPage == ''){
		//ERROR HANDLE
		return false;
	}
	else
	{
	    //SHIFT TO THE SPECIFIED PAGE
		window.location.href = strPage;
	}
}//------------------------------------------------PageNavigation

function ConfirmRemove(msg){
//FUNCTION shows confirm message
	if (confirm(msg)){
		return true;
	}
	else{
		return false;	
	}
}//------------------------------------------------ConfirmRemove


function Pause(millis) {
// JAVASCRIPT PAUSE USED MAIN FOR 
// ASYNC CALL BACKS

        var date = new Date();
        var curDate = null;
        do { curDate = new Date(); } 
        while(curDate-date < millis)
} //--------------------------------Pause


function ToggleDivLayer(ItemName){
//  +----------------------------------------------------------------+
//  |DESCRIPTION : TOGGLES ANY LAYER  
//  |PARAMETERS	: Name of TAG TO CONTROL	
//  |                    	
//  |AUTHOR	: Blaine Jenkins    April  29, 2005
//  +----------------------------------------------------------------+
try{
//GET REFERENCE TO THE CONTROL
	var ref_ctrl = Q_findObj(ItemName);	
	if (ref_ctrl != null ){
		// reference to control found
	//	alert(ref_ctrl.style.visibility);
		if (ref_ctrl.style.visibility == 'hidden'){
			Q_showHideLayers(ItemName,'','show')
			ref_ctrl.style.display = 'block';
		}else{
			Q_showHideLayers(ItemName,'','hide')
			ref_ctrl.style.display = 'none';
		}//if
	}//if
	
  }catch(e){
         txt="OOOPs... an error occured that is preventing the \n";
	 	 txt+="application from providing the requested content.\n\n";
	 	 txt+="Please contact support@cissec.com or your local administrator\n";
	 	 txt+="to resolve the issue.";
	 	 	 	 
	     txt+="Error number: " + (err.number & 0xffff) + "\n\n"
	     txt+="Error description: " + err.description + "\n\n"
 	     txt+="Click OK to continue.\n\n"
	     alert(txt);
         
  }//END TRY	
}//-------------------------------------------------- ToggleDivLayer

function ShowHideDivLayer(ItemName, Show){
//  +----------------------------------------------------------------+
//  |DESCRIPTION : TOGGLES ANY LAYER  
//  |PARAMETERS	: Name of TAG TO CONTROL	
//  |                    	
//  |AUTHOR	: Blaine Jenkins    April  29, 2005
//  +----------------------------------------------------------------+
try{
//GET REFERENCE TO THE CONTROL
	var ref_ctrl = Q_findObj(ItemName);	
	if (ref_ctrl != null ){
		// reference to control found
	//	alert(ref_ctrl.style.visibility);
		if (Show){
			Q_showHideLayers(ItemName,'','show')
			ref_ctrl.style.display = 'block';
		}else{
			Q_showHideLayers(ItemName,'','hide')
			ref_ctrl.style.display = 'none';
		}//if
	}//if
	
  }catch(e){
         txt="OOOPs... an error occured that is preventing the \n";
	 	 txt+="application from providing the requested content.\n\n";
	 	 txt+="Please contact support@cissec.com or your local administrator\n";
	 	 txt+="to resolve the issue.";
	 	 	 	 
	     txt+="Error number: " + (err.number & 0xffff) + "\n\n"
	     txt+="Error description: " + err.description + "\n\n"
 	     txt+="Click OK to continue.\n\n"
	     alert(txt);
         
  }//END TRY	
}//-------------------------------------------------- ShowHideDivLayer


function CopyToClipboard(objName){
// EXAMPLE OBJECT: <TEXTAREA ID="holdtext" STYLE="display:none;"></TEXTAREA> 
//
	var objtxt = document.all[objName];
	var tmptxt = '';

	if (objtxt != null){
		tmptxt = objtxt.innerText;
		window.clipboardData.clearData('Text');
		window.clipboardData.clearData('HTML');
		window.clipboardData.setData('Text',tmptxt);
		
	}/*if*/
}/**/



function Q_swapImgRestore() { //v3.0
  var i,x,a=document.Q_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function Q_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.Q_p) d.Q_p=new Array();
    var i,j=d.Q_p.length,a=Q_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.Q_p[j]=new Image; d.Q_p[j++].src=a[i];}}
}
function Q_findObj(n, d) { //v4.0
  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=Q_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function Q_swapImage() { //v3.0
  var i,j=0,x,a=Q_swapImage.arguments; document.Q_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=Q_findObj(a[i]))!=null){document.Q_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function Q_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.Q_pgW=innerWidth; document.Q_pgH=innerHeight; onresize=Q_reloadPage; }}
  else if (innerWidth!=document.Q_pgW || innerHeight!=document.Q_pgH) location.reload();
}
//Q_reloadPage(true);

function Q_showHideLayers() { //v3.0
  var i,p,v,obj,args=Q_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=Q_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function Q_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function Q_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=Q_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=Q_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.Q_returnValue = (errors == '');
}
