function selectAssetImage(formobject, valuefield, sURL, sAssetID)
	{
//	formobject.inpImgURL.value = sURL;
	valuefield.value = sAssetID;
	
	divImg.style.visibility = "hidden"
	divImg.innerHTML = "<img id='idImg' src='" + sURL + "'>";
	

	var width = formobject.idImg.width
	var height = formobject.idImg.height 
	var resizedWidth = 150;
	var resizedHeight = 200;

	var Ratio1 = resizedWidth/resizedHeight;
	var Ratio2 = width/height;

	if(Ratio2 > Ratio1)
		{
		if(width*1>resizedWidth*1)
			formobject.idImg.width=resizedWidth;
		else
			formobject.idImg.width=width;
		}
	else
		{
		if(height*1>resizedHeight*1)
			formobject.idImg.height=resizedHeight;
		else
			formobject.idImg.height=height;
		}
	
	divImg.style.visibility = "visible"
	}

function mask (InString, Mask, objref)  {
	LenStr = InString.length;
	LenMsk = Mask.length;
	if ((LenStr==0) || (LenMsk==0))
		return(0);
	if (LenStr!=LenMsk)
		return(0);
	TempString=""
	for (Count=0; Count<=InString.length; Count++)  {
		StrChar = InString.substring(Count, Count+1);
		MskChar = Mask.substring(Count, Count+1);
		if (MskChar=='#') {
			if(!isNumberChar(StrChar))
				return(0);
		}
		else if (MskChar=='?') {
			if(!isAlphabeticChar(StrChar))
				return(0);
		}
		else if (MskChar=='!') {
			if(!isNumOrChar(StrChar))
				return(0);
		}
		else if (MskChar=='*') {
		}
		else {
			if (MskChar!=StrChar) 
				return(0);
		}
	}
	return (1);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function emailCheck (emailStr) {
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
	alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]
if (user.match(userPat)==null) {
    alert("The username doesn't seem to be valid.")
    return false
}
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
    return false
}

var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}

return true;
}


function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}
function showDiv( strDiv ) {
	if (document.getElementById( strDiv ).style.display == 'block') {
		document.getElementById( strDiv ).style.display = 'none';
	} else {
		document.getElementById( strDiv ).style.display = 'block';
	}
}

function incTime( obj ) {
	var fltParsed = parseFloat( obj.value );
	
	if (event.button == 2) event.cancelBubble = true;
	if (isNaN(fltParsed)) {
		obj.value = 0;
	} else {
		if (fltParsed > 50) {
			// Do nothing!
		} else {
			obj.value = event.shiftKey ? fltParsed + 1 : fltParsed + .25;
		}
	}
}
function decTime( obj ) {
	var fltParsed = parseFloat( obj.value );
	
	if (isNaN(fltParsed)) {
		obj.value = 0;
	} else {
		if (fltParsed < .25) {
			// Do nothing!
		} else {
			obj.value = event.shiftKey ? fltParsed - 1 : fltParsed - .25;
		}
	}
}
function incPercent( obj, strDefault ) {
	var intParsed = parseInt( obj.value );
	
	if (isNaN(intParsed)) {
		obj.value = strDefault;
	} else {
		if (intParsed > 95) {
			// Do nothing!
		} else {
			obj.value = event.shiftKey ? intParsed + 10 : intParsed + 5;
		}
	}
}
function decPercent( obj, strDefault ) {
	var intParsed = parseInt( obj.value );
	
	if (isNaN(intParsed)) {
		obj.value = strDefault;
	} else {
		if (intParsed < 5) {
			// Do nothing!
		} else {
			obj.value = event.shiftKey ? intParsed - 10 : intParsed - 5;
		}
	}
}

function incDate( obj ) {
	// Construct a date object to utilize Date methods.
	var dat = new Date( obj.value );
	
	// If shift is down, modify by a week, else only 1 day.
	event.shiftKey ? dat.setDate( dat.getDate() + 7) : dat.setDate( dat.getDate() + 1);
	if (obj.name == "txtBegin") {
		datBegin = (dat.getMonth()+1) + "/" + dat.getDate() + "/" + dat.getYear();
	}
	else {
		datExpected = (dat.getMonth()+1) + "/" + dat.getDate() + "/" + dat.getYear();
	}
		
	// Trim the time off of the string by not taking the last 12 characters.
	// Hopefully this will be the length of the time + am/pm indicator on 
	// every system.
	obj.value = dat.toLocaleString().substr( 0, dat.toLocaleString().length - 12);
}
function decDate( obj ) {
	// Construct a date object to utilize Date methods.
	var dat = new Date( obj.value );
	
	// If shift is down, modify by a week, else only 1 day.
	event.shiftKey ? dat.setDate( dat.getDate() - 7) : dat.setDate( dat.getDate() - 1);
	if (obj.name == "txtBegin") {
		datBegin = (dat.getMonth()+1) + "/" + dat.getDate() + "/" + dat.getYear();
	}
	else {
		datExpected = (dat.getMonth()+1) + "/" + dat.getDate() + "/" + dat.getYear();
	}
	
	// Trim the time off of the string by not taking the last 12 characters.
	// Hopefully this will be the length of the time + am/pm indicator on 
	// every system.
	obj.value = dat.toLocaleString().substr( 0, dat.toLocaleString().length - 12);
}
function convertDates() {
	document.frmNew.txtBegin.value = datBegin;
	document.frmNew.txtExpected.value = datExpected;				
}
function keyCheck() {
	// TAB = 9
	// + = 187 
	// - = 189
	// Shift = 17  
	// CRLF = 13
	if (event.keyCode == 187) {
		incDate( event.srcElement );
	} else if (event.keyCode == 189) {
		decDate( event.srcElement );
	} else if (event.keyCode == 9) {
		return;
	} else if (event.keyCode == 13) {
		return;
	}
	event.returnValue = false;
}

function confirmCheck( strAction ) {
	var strConfirm = "Are you sure you would like to " + strAction + " this item?\n\n";
	
	if (strAction == "complete") 
		strConfirm += 
			"(Note: Currently you can not undo this operation.\n" +
			"If you wish to get an item back that has been completed, you must\n" +
			"go into the database and null out the 'COMPLETE' fields in either the\n" +
			"task or project.)";
	else
		strConfirm +=
			"(Note: Currently you can not undo this operation.\n" +
			"If you delete an item, all time that you have logged on it\n" +
			"will be lost.  If you would like to keep the time for reporting\n" +
			"purposes, you must 'complete' the item instead.  Deleting can not\n" +
			"be undone.)";
			
	if (confirm( strConfirm ) == 1)
		event.returnValue = true;
	else
		event.returnValue = false;
}

function voteRemind() {
	if (confirm( "This is just a friendly reminder to vote for this program on Planet\n" +
		"Source Code.  If you click 'OK' below you will be brought to this code's screen\n" +
		"on PSC. Scroll down to the 'Your Vote' section and cast your vote.  You may click\n" +
		"cancel at this time to stay on this screen.  This option will only be available\n" +
		"until the end of Novemember." ) == 1)
		event.returnValue = true;
	else
		event.returnValue = false;
}
function checkFileUpload(form,extensions,requireUpload,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight) { //v2.09
  document.MMFU_returnValue = true;
  for (var i = 0; i<form.elements.length; i++) {
    field = form.elements[i];
    if (field.type.toUpperCase() != 'FILE') continue;
    checkOneFileUpload(field,extensions,requireUpload,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight);
} }

function checkOneFileUpload(field,extensions,requireUpload,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight) { //v2.09
  document.MMFU_returnValue = true;
  if (extensions != '') var re = new RegExp("\.(" + extensions.replace(/,/gi,"|").replace(/\s/gi,"") + ")$","i");
    if (field.value == '') {
      if (requireUpload) {alert('File is required!');document.MMFU_returnValue = false;field.focus();return;}
    } else {
      if(extensions != '' && !re.test(field.value)) {
        alert('This file type is not allowed for uploading.\nOnly the following file extensions are allowed: ' + extensions + '.\nPlease select another file and try again.');
        document.MMFU_returnValue = false;field.focus();return;
      }
    document.PU_uploadForm = field.form;
    re = new RegExp(".(gif|jpg|png|bmp|jpeg)$","i");
    if(re.test(field.value) && (sizeLimit != '' || minWidth != '' || minHeight != '' || maxWidth != '' || maxHeight != '' || saveWidth != '' || saveHeight != '')) {
      checkImageDimensions(field,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight);
    } }
}

function showImageDimensions(fieldImg) { //v2.09
  var isNS6 = (!document.all && document.getElementById ? true : false);
  var img = (fieldImg && !isNS6 ? fieldImg : this);
  if (img.width > 0 && img.height > 0) {
  if ((img.minWidth != '' && img.minWidth > img.width) || (img.minHeight != '' && img.minHeight > img.height)) {
    alert('Uploaded Image is too small!\nShould be at least ' + img.minWidth + ' x ' + img.minHeight); return;}
  if ((img.maxWidth != '' && img.width > img.maxWidth) || (img.maxHeight != '' && img.height > img.maxHeight)) {
    alert('Uploaded Image is too big!\nShould be max ' + img.maxWidth + ' x ' + img.maxHeight); return;}
  if (img.sizeLimit != '' && img.fileSize > img.sizeLimit) {
    alert('Uploaded Image File Size is too big!\nShould be max ' + (img.sizeLimit/1024) + ' KBytes'); return;}
  if (img.saveWidth != '') document.PU_uploadForm[img.saveWidth].value = img.width;
  if (img.saveHeight != '') document.PU_uploadForm[img.saveHeight].value = img.height;
  document.MMFU_returnValue = true;
} }

function checkImageDimensions(field,sizeL,minW,minH,maxW,maxH,saveW,saveH) { //v2.09
  if (!document.layers) {
    var isNS6 = (!document.all && document.getElementById ? true : false);
    document.MMFU_returnValue = false; var imgURL = 'file:///' + field.value.replace(/\\/gi,'/').replace(/:/gi,'|').replace(/"/gi,'').replace(/^\//,'');
    if (!field.gp_img || (field.gp_img && field.gp_img.src != imgURL) || isNS6) {field.gp_img = new Image();
		   with (field) {gp_img.sizeLimit = sizeL*1024; gp_img.minWidth = minW; gp_img.minHeight = minH; gp_img.maxWidth = maxW; gp_img.maxHeight = maxH;
  	   gp_img.saveWidth = saveW; gp_img.saveHeight = saveH; gp_img.onload = showImageDimensions; gp_img.src = imgURL; }
	 } else showImageDimensions(field.gp_img);}
}
function modsitevalidate () {
  document.MS_returnValue = true;
  if (document.MMFU_returnValue == true && document.MMFV_returnValue == true) {
  document.MS_returnValue = true;
  } else {
  document.MS_returnValue = false;

} }

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 YY_checkform() { //v4.65
//copyright (c)1998,2002 Yaromat.com
  var args = YY_checkform.arguments; var myDot=true; var myV=''; var myErr='';var addErr=false;var myReq;
  for (var i=1; i<args.length;i=i+4){
    if (args[i+1].charAt(0)=='#'){myReq=true; args[i+1]=args[i+1].substring(1);}else{myReq=false}
    var myObj = MM_findObj(args[i].replace(/\[\d+\]/ig,""));
    myV=myObj.value;
    if (myObj.type=='text'||myObj.type=='password'||myObj.type=='hidden'){
      if (myReq&&myObj.value.length==0){addErr=true}
      if ((myV.length>0)&&(args[i+2]==1)){ //fromto
        var myMa=args[i+1].split('_');if(isNaN(parseInt(myV))||myV<myMa[0]/1||myV > myMa[1]/1){addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==2)){
          var rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-z]{2,4}$");if(!rx.test(myV))addErr=true;
      } else if ((myV.length>0)&&(args[i+2]==3)){ // date
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);
        if(myAt){
          var myD=(myAt[myMa[1]])?myAt[myMa[1]]:1; var myM=myAt[myMa[2]]-1; var myY=myAt[myMa[3]];
          var myDate=new Date(myY,myM,myD);
          if(myDate.getFullYear()!=myY||myDate.getDate()!=myD||myDate.getMonth()!=myM){addErr=true};
        }else{addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==4)){ // time
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);if(!myAt){addErr=true}
      } else if (myV.length>0&&args[i+2]==5){ // check this 2
            var myObj1 = MM_findObj(args[i+1].replace(/\[\d+\]/ig,""));
            if(myObj1.length)myObj1=myObj1[args[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!myObj1.checked){addErr=true}
      } else if (myV.length>0&&args[i+2]==6){ // the same
            var myObj1 = MM_findObj(args[i+1]);
            if(myV!=myObj1.value){addErr=true}
      }
    } else
    if (!myObj.type&&myObj.length>0&&myObj[0].type=='radio'){
          var myTest = args[i].match(/(.*)\[(\d+)\].*/i);
          var myObj1=(myObj.length>1)?myObj[myTest[2]]:myObj;
      if (args[i+2]==1&&myObj1&&myObj1.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
      if (args[i+2]==2){
        var myDot=false;
        for(var j=0;j<myObj.length;j++){myDot=myDot||myObj[j].checked}
        if(!myDot){myErr+='* ' +args[i+3]+'\n'}
      }
    } else if (myObj.type=='checkbox'){
      if(args[i+2]==1&&myObj.checked==false){addErr=true}
      if(args[i+2]==2&&myObj.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
    } else if (myObj.type=='select-one'||myObj.type=='select-multiple'){
      if(args[i+2]==1&&myObj.selectedIndex/1==0){addErr=true}
    }else if (myObj.type=='textarea'){
      if(myV.length<args[i+1]){addErr=true}
    }
    if (addErr){myErr+='* '+args[i+3]+'\n'; addErr=false}
  }
  if (myErr!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+myErr)}
  document.MMFV_returnValue = (myErr=='');
}