// JavaScript Document
//MM functions
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];}}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  //window.open('', winName).close();
  window.open(theURL,winName,features);
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_popupMsg(msg) { //v1.0
  alert(msg);
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_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 MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_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_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_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//Box functions

function UpdateAcctSz(sz) {
	if (confirm(sz)) {
		top.location='/mybox.php';
		//document.updateacct.submit();
	}
}

function JPEGopenNewWindow(URLtoOpen, windowName, windowFeatures) {
	newWindow=window.open(URLtoOpen, windowName, windowFeatures);
}

function toggle(target,sw){
	obj=(document.all) ? document.all[target] : document.getElementById(target);
	switch (sw){
		case "display":
		obj.style.display='';
		break;
		case "none":
		obj.style.display='none';
		break;
		default:
		obj.style.display=(obj.style.display=='none') ? '' : 'none';
	}
}

//  setCheckboxColumn(\'id' . $row_no . ''\');
function setCheckboxColumn(theCheckbox){
    if (document.getElementById(theCheckbox)) {
        document.getElementById(theCheckbox).checked = (document.getElementById(theCheckbox).checked ? false : true);
        if (document.getElementById(theCheckbox + 'r')) {
            document.getElementById(theCheckbox + 'r').checked = document.getElementById(theCheckbox).checked;
        }
    } else {
        if (document.getElementById(theCheckbox + 'r')) {
            document.getElementById(theCheckbox + 'r').checked = (document.getElementById(theCheckbox +'r').checked ? false : true);
            if (document.getElementById(theCheckbox)) {
                document.getElementById(theCheckbox).checked = document.getElementById(theCheckbox + 'r').checked;
            }
        }
    }
}

function expand(ulid){
	li=document.getElementById(ulid);
	var ul=li.getElementsByTagName('ul')[0];
	if(ul.style.display!="block"){
		ul.style.display="block";
		ul.style.visibility="visible";
	}else{
		ul.style.display="none";
		ul.style.visibility="hidden";
	}
}

function expand_any(id){
	targetid=document.getElementById(id);
	//var ul=li.getElementsByTagName('ul')[0];
	if(targetid.style.display!="block"){
		targetid.style.display="block";
		targetid.style.visibility="visible";
	}else{
		targetid.style.display="none";
		targetid.style.visibility="hidden";
	}
}


function box_valForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=box_valForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.id; 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') { num = parseFloat(val);
          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 (num<min || max<num) 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.MM_returnValue = (errors == '');
} }

function valSend() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=valSend.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.id; 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') { num = parseFloat(val);
          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 (num<min || max<num) 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('Please choose a recipient from your contact list or add a new contact.');
    document.MM_returnValue = (errors == '');
} }

function toggleFlashViewer(linkid){
	vb=document.getElementById("flashcontent"+linkid);
	//alert(vb.style.display);
	if(vb.style.display=="none"){
		revealFlashViewer(linkid);
		//alert("reveal");	
	}else{
		hideFlashViewer(linkid);
		//alert("hide");	
	}
}

function newFlashViewer(linkid, dsc, typeValue) {
	// hide content
	hdr=document.getElementById('header');
	hdr.style.display="none";
	hdr.style.visibility="hidden";

	bdy=document.getElementById('mainBkgd');
	bdy.style.display="none";
	bdy.style.visibility="hidden";

	ftr=document.getElementById('footer');
	ftr.style.display="none";
	ftr.style.visibility="hidden";
	
	// display flash container
	vb=document.getElementById('flashViewerContainer');
	vb.style.display="block";
	vb.style.visibility="visible";
	
	//Detect IE6-
	version=0
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		temp=navigator.appVersion.split("MSIE")
		version=parseFloat(temp[1])

		if (version<7){
			vb.style.width=document.body.clientWidth-32;
		} else {
			vb.style.width="auto";
		}

	} else {
		vb.style.width="auto";
	}
	

	var newViewer='<div id="flashViewer'+linkid+'" class="flashViewer"><div id="flashcontent'+linkid+'" class="flashcontent"></div><div id="controller'+linkid+'" class="controller"><a href="javascript:void(0);" onclick="toggleFlashViewer(\''+linkid+'\')"><img class="min_maxBtn" src="media/transparent.gif" alt="Show/Hide Viewer" /></a><div id="label'+linkid+'" class="fv_label"></div><a href="javascript:void(0);" onclick="closeFlashViewer(\''+linkid+'\');"><img class="closeBtn" src="media/transparent.gif" alt="Close Viewer" /></a></div></div>';
	var flashViewerContainer = document.getElementById('flashViewerContainer');
	flashViewerContainer.innerHTML = newViewer;
	
	var so = new SWFObject("center/modules/viewer/boxview2.swf", "movie", "100%", "100%", "8", "#FFFFFF");
	so.addVariable("linkid", linkid);
	so.addVariable("typeValue", typeValue);
	so.addParam("wmode", "transparent");
	so.write("flashcontent"+linkid);

	var label_so = new SWFObject("center/modules/viewer/label.swf", "movie", "31", "161", "8", "#FFFFFF");
	label_so.addVariable("dsc", dsc);
	label_so.addParam("wmode", "transparent");
	label_so.write("label"+linkid);

}

function hideFlashViewer(linkid){
	hdr=document.getElementById('header');
	hdr.style.display="block";
	hdr.style.visibility="visible";

	bdy=document.getElementById('mainBkgd');
	bdy.style.display="block";
	bdy.style.visibility="visible";

	ftr=document.getElementById('footer');
	ftr.style.display="block";
	ftr.style.visibility="visible";
	
	// display flash container
	vb=document.getElementById('flashcontent'+linkid);
	vb.style.display="none";
	vb.style.visibility="hidden";
	vb.style.width="30px";

	vb2=document.getElementById('flashViewerContainer');
	vb2.style.width="30px";
	vb2.style.left="0";
	
	vb3=document.getElementById('controller'+linkid);
	vb3.style.left="0";
}

function revealFlashViewer(linkid){
	
	// display flash container
	hdr=document.getElementById('header');
	hdr.style.display="none";
	hdr.style.visibility="hidden";

	bdy=document.getElementById('mainBkgd');
	bdy.style.display="none";
	bdy.style.visibility="hidden";

	ftr=document.getElementById('footer');
	ftr.style.display="none";
	ftr.style.visibility="hidden";
	
	// display flash container
	vb=document.getElementById('flashcontent'+linkid);
	vb.style.display="block";
	vb.style.visibility="visible";

	//Detect IE6-
	version=0
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		temp=navigator.appVersion.split("MSIE")
		version=parseFloat(temp[1])

		if (version<7){
			vb.style.width=document.body.clientWidth-32;
		} else {
			vb.style.width="auto";
		}

	} else {
		vb.style.width="auto";
	}
	

	vb2=document.getElementById('flashViewerContainer');
	vb2.style.left="16px";
	//Detect IE6-
	version=0
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		temp=navigator.appVersion.split("MSIE")
		version=parseFloat(temp[1])

		if (version<7){
			vb2.style.width=document.body.clientWidth-32;
		} else {
			vb2.style.width="auto";
		}

	} else {
		vb2.style.width="auto";
	}
	
	
	vb3=document.getElementById('controller'+linkid);
	vb3.style.left="auto";
}


function closeFlashViewer(linkid){
	hdr=document.getElementById('header');
	hdr.style.display="block";
	hdr.style.visibility="visible";

	bdy=document.getElementById('mainBkgd');
	bdy.style.display="block";
	bdy.style.visibility="visible";

	ftr=document.getElementById('footer');
	ftr.style.display="block";
	ftr.style.visibility="visible";
	
	// display flash container
	vb=document.getElementById('flashViewerContainer');
	vb.style.display="none";
	vb.style.visibility="hidden";
	vb.style.width="30px";
}

function confirmMakeRequest(msg, url, vars){
	var answer = confirm(msg);
	if (answer){
		MM_goToURL('parent','ondabox.php#'+url+'&'+vars);
	} 
}

function selectCheckbox(form, chkGroup, chkbox) {
	f = document.getElementById(form);
	for (i = 0 ; i < f.elements.length; i++) {
		if ((f.elements[i].type == "checkbox") && (f.elements[i].name == chkGroup)) {
			if (!(f.elements[i].value == "DISABLED" || f.elements[i].disabled)) {
				f.elements[i].checked = chkbox.checked;
			}
		}
	}
	return true;
}

function newProjectRefer(selObj){
	prj=document.getElementById('prj');
	num=document.getElementById('num');
	if (selObj.options[selObj.selectedIndex].value=="*"){
		prj.style.display="block";
		prj.style.visibility="visible";
		num.style.display="block";
		num.style.visibility="visible";
	} else {
		prj.style.display="none";
		prj.style.visibility="hidden";
		num.style.display="none";
		num.style.visibility="hidden";
	}
}

function contactlist(selObj){
	addcontact=document.getElementById('addcontact');
	if (selObj.options[selObj.selectedIndex].value=="*"){
		// open new contact form
		noHistoryLoadPage("div=addcontact&page=center/modules/send/addcontactsrc");
		//makeRequest('center/modules/send/addcontactsrc', '', 'addcontact');
	} else {
		// add selected contact to send list
		noHistoryLoadPage("div=contactlist&page=center/modules/send/contacts&type=add&member_id="+selObj.options[selObj.selectedIndex].value);
		//makeRequest('center/modules/send/contacts', 'type=add&member_id='+selObj.options[selObj.selectedIndex].value, 'contactlist');
	}
}

function srcnewcontact(){
	var z=document.getElementById('email');
	makeRequest('center/modules/send/addcontactform','email='+z.value,'addcontact');
}