/*
JavaScript
*/

/*
*********************************************************************
* Pop-up Windows                                                    *
*********************************************************************
*/

/* This Function Created by:	Jamie Peloquin v */
/* Generic - Centered -------------------------------------------- */
function PopGeneric(URL,WINNAME,WD,HT,SCROLL){
	if(!WD){WD = "760"}
	if(!HT){HT = "420"}
	var halfW = (WD/2)
 	var halfH = (HT/2)
   	var screenW = screen.availWidth
    var screenH = screen.availHeight
    
    var screenX = ((screenW / 2) - halfW) // is half the width of the window
    var screenY = ((screenH / 2) - halfH) // is half the height of the window

    var genWin = window.open(URL, WINNAME, 'width='+WD+', height='+HT+', top='+screenY+', left='+screenX+', toolbar=no, location=no, menubar=yes, scrollbars='+SCROLL+', status=yes, resizable=yes');
    genWin.focus();
}
/* END Generic - Centered ---------------------------------------- */

function switchVis(obj) {
    if (document.getElementById) { // DOM3 = IE5, NS6
        if(document.getElementById(obj).style.visibility == 'visible') {
            document.getElementById(obj).style.visibility = 'hidden';
            document.getElementById(obj).style.display = 'none';                       
        } else if(document.getElementById(obj).style.visibility == 'hidden') {
            document.getElementById(obj).style.visibility = 'visible';
            document.getElementById(obj).style.display = 'block';            
        } else {
            document.getElementById(obj).style.visibility = 'hidden';
            document.getElementById(obj).style.display = 'none';            
        }
    } else {
        if (document.layers) { // Netscape 4
            if(document.obj.visibility == 'visible') {
                document.obj.visibility = 'hidden';
                document.obj.display = 'none';                
            } else if(document.obj.visibility == 'hidden') {
                document.obj.visibility = 'visible';
                document.obj.display = 'block';                
            } else {
                document.obj.visibility = 'hidden';
                document.obj.display = 'none';           
            }
        } else { // IE 4
            if(document.all.obj.style.visibility == 'visible') {
                document.all.obj.style.visibility = 'hidden';
                document.all.obj.style.display = 'none';                
            } else if(document.all.obj.style.visibility == 'hidden') {
                document.all.obj.style.visibility = 'visible';
                document.all.obj.style.display = 'block';                

            } else {
                document.all.obj.style.visibility = 'hidden';
                document.all.obj.style.display = 'none';                

            }
        }
    }
}

function openWin(url, name, w, h) {

  l = (screen.availWidth-10 - w) / 2;
  t = (screen.availHeight-20 - h) / 2;

  features = "width="+w+",height="+h+",left="+l+",top="+t;
  features += ",screenX="+l+",screenY="+t;
  features += ",scrollbars=1,resizable=1,location=0";
  features += ",menubar=0,toolbar=0,status=0";

  window.open(url, name, features);
}

function confirmSubmit(string)
{
    var agree=confirm(string);
    if (agree)
    	return true ;
    else
    	return false ;
}

function sbFocus(obj) {
    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById(obj).focus()
    } else {
        if (document.layers) { // Netscape 4
            document.obj.focus()
        } else { // IE 4
            document.document.all.obj.focus()
        }
    }
}

function format_safeurl(usource,udest) {
    var oSource = document.getElementById(usource);
    var oDest = document.getElementById(udest);
    var s = oSource.value;
    var word_list = new Array();
    var word_list = s.split(/[^a-zA-Z0-9]/);
    var t = '';
    var re = new RegExp ('"', 'gi') ;
        
    for (i=0;i<word_list.length;i++)
    {
        var newstr = word_list[i];
        newstr = newstr.replace(re, '');
        if(t) {
            t = t + '-' + newstr;
        } else {
            t = newstr;        
        }
    }
    oDest.value = t;
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function show(obj) {
    document.getElementById(obj).innerHTML=opener.document.pageform.f_content.value;
}


/*
bool switchSubCheckbox(string parent, string child)
 - Disables and checks the child checkbox if the parent is unchecked.
 - Extend this to handle generic parameters
*/
function switchSubCheckbox(parent, child) {
    if (document.getElementById(parent).checked == false) {
        document.getElementById(child).checked = true;
        document.getElementById(child).disabled = true;        
    } else if (document.getElementById(parent).checked == true) {
        document.getElementById(child).checked = false;
        document.getElementById(child).disabled = false;    
    } else {
        return false;
    }
    return true;
}

function openWindow(url, name) {
popupWin = window.open(url,name,'_blank,resizable=1,location=0,scrollbars=1,toolbar=0,personalbar=0,status=1,width=800,height=640,left=15,top=5');
window.name = 'popupWin';
popupWin.focus();
}