function popImage(imageURL,imageTitle){
PositionX = 170;
PositionY = 170;

defaultWidth  = 600;
defaultHeight = 600;

var AutoClose = false;

if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
	if (isNN){imagesWin=window.open('about:blank','',optNN);}
	if (isIE){imagesWin=window.open('about:blank','',optIE);}
	with (imagesWin.document){
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');
		writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');
		writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');
		writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');
		writeln('if (isIE){');
		writeln('window.resizeTo(100,100);');
		writeln('width=100-(document.body.clientWidth-document.images[0].width);');
		writeln('height=100-(document.body.clientHeight-document.images[0].height);');
		writeln('window.resizeTo(width,height);}');
		writeln('if (isNN){');       
		writeln('window.innerWidth=document.images["MetroPCS"].width;');
		writeln('window.innerHeight=document.images["MetroPCS"].height;}}');
		writeln('function doTitle(){document.title="'+imageTitle+'";}');
		writeln('</sc'+'ript>');
		if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
		else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
		writeln('<img name="MetroPCS" src=\"'+imageURL+'\" style="display:block"></body></html>');
		close();		
	}
}

function checkRadios() {
	var el = document.forms[0].elements;
	for(var i = 0 ; i < el.length ; ++i) {
		if(el[i].type == "radio") {
			var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
			var itemchecked = false;
		for(var j = 0 ; j < radiogroup.length ; ++j) {
			if(radiogroup[j].checked) {
			itemchecked = true;
			break;
			}
		}
		if(!itemchecked) { 
			alert("Please select a return method.\n");
			if(el[i].focus)
				el[i].focus();
				return false;
			}
		}
	}
	return true;
} 

function checkForm(formName){
	error=0
	wrong=0
	reqError=""
	dateError=""
	emailError = ""
	bolType = false;
	thisForm=eval("document."+formName)
	for(i=0;i<thisForm.elements.length;i++){
		elementtype=thisForm.elements[i].type
		elementname=thisForm.elements[i].name
		elementclass=thisForm.elements[i].className
		elementid=thisForm.elements[i].id
		elementvalue=thisForm.elements[i].value
		elementvaluelength=thisForm.elements[i].value.length
		elementname=elementname.toLowerCase()
		if(elementclass.indexOf("req")!=-1){
				if(elementvalue==""){
					error=1
					reqError="\t One or more of the required fields (blue) are not entered, please enter in the required fields \n"
					thisForm.elements[i].className="req_error_text"
				}else{
					thisForm.elements[i].className="req_input"
					CheckNonReq(true);
				}
				
				if(elementname.indexOf("email")!=-1 && elementvalue !=""){
					if(IsEmail(elementvalue)!=true){
						error=1
						wrong = 1
						emailError="\t The e-mail you have entered is not valid\n"
						thisForm.elements[i].className="req_error_input"
						if(bolType==true){
							thisForm.elements[i].className="req_input"
						}else{
							thisForm.elements[i].className="req_error_input"
						}
					}else{
						thisForm.elements[i].className=returnType
					}
				}
		}else{
			CheckNonReq(false);
			if(elementname.indexOf("email")!=-1 && elementvalue !=""){
					if(IsEmail(elementvalue)!=true){
						error=1
						wrong = 1
						emailError="\t The e-mail you have entered is not valid\n"
						thisForm.elements[i].className="error_input"
						if(bolType==true){
							thisForm.elements[i].className="req_input"
						}else{
							thisForm.elements[i].className="error_input"
						}
					}else{
						thisForm.elements[i].className=returnType
					}
				}
		}
	}
	if(error==1){
		if (wrong == 1)
		{
		strError="The following problems (highlighted in red) are wrong with the information you entered:\n" + reqError + dateError
		}
		else
		{
			strError = reqError + dateError
		}
		alert(strError + emailError);
		return false;
	}else{
		return true;  
	}
}
function IsEmail(emailAddress) {
     var emailReg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
     var regex = new RegExp(emailReg);
     return regex.test(emailAddress);
}
function CheckNonReq(bolType){
	if(bolType==true){
		returnType="req_input"
	}else{
		returnType="input"
	}
	if(elementname.indexOf("date")!=-1){
		if ( (elementtype != "hidden") && (elementvalue != "") ) {
			if(checkValidDate(elementvalue)!=true){
				error=1;
				wrong=1;
				dateError="\t The Date you have entered is not formatted properly (mm/dd/yyyy)\n\t\t or is not valid\n";
				thisForm.elements[i].className="error_input";
				if(bolType==true){
					thisForm.elements[i].className="req_error_input";
				}else{
					thisForm.elements[i].className="error_input";
				}
			}else{
				thisForm.elements[i].className=returnType;
			}
		}
	}
}
function checkValidDate(dateStr) {
    var slash1 = dateStr.indexOf("/");
    if (slash1 == -1) { slash1 = dateStr.indexOf("-"); }
    if (slash1 == -1) { return false; }
    var dateMonth = dateStr.substring(0, slash1)
    var dateMonthAndYear = dateStr.substring(slash1+1, dateStr.length);
    var slash2 = dateMonthAndYear.indexOf("/");
    if (slash2 == -1) { slash2 = dateMonthAndYear.indexOf("-"); }
    if (slash2 == -1) { return false; }
    var dateDay = dateMonthAndYear.substring(0, slash2);
    var dateYear = dateMonthAndYear.substring(slash2+1, dateMonthAndYear.length);
    if ( (dateMonth == "") || (dateDay == "") || (dateYear == "") ) { return false; }
    for (var x=0; x < dateMonth.length; x++) {
        var digit = dateMonth.substring(x, x+1);
        if ((digit < "0") || (digit > "9")) { return false; }
    }
    var numMonth = 0;
    for (var x=0; x < dateMonth.length; x++) {
        digit = dateMonth.substring(x, x+1);
        numMonth *= 10;
        numMonth += parseInt(digit);
    }
    if ((numMonth <= 0) || (numMonth > 12)) { return false; }
    for (var x=0; x < dateDay.length; x++) {
        digit = dateDay.substring(x, x+1);
        if ((digit < "0") || (digit > "9")) { return false; }
    }
    var numDay = 0;
    for (var x=0; x < dateDay.length; x++) {
        digit = dateDay.substring(x, x+1);
        numDay *= 10;
        numDay += parseInt(digit);
    }
    if ((numDay <= 0) || (numDay > 31)) { return false; }
    if ((numMonth == 2) && (numDay > 29)) { return false; }
    if ((numMonth == 4) || (numMonth == 6) || (numMonth == 9) || (numMonth == 11)) { 
        if (numDay > 30) { return false; } 
    }
	for (var x=0; x < dateYear.length; x++) {
        digit = dateYear.substring(x, x+1);
        if ((digit < "0") || (digit > "9")) { return false; }
    }
    var numYear = 0;
    for (var x=0; x < dateYear.length; x++) {
        digit = dateYear.substring(x, x+1);
        numYear *= 10;
        numYear += parseInt(digit);
    }
	if (dateYear.length != 4) { return false; }
    if ( (numYear < 50) && (dateYear.length == 2) ) { numYear += 2000; }
    if ( (numYear < 100) && (dateYear.length == 2) ) { numYear += 1900; }
    if ((numYear <= 1753) || (numYear > 9999)) { return false; }
    if ((numMonth == 2) && (numDay == 29)) {
        var div4 = numYear % 4;
        var div100 = numYear % 100;
        var div400 = numYear % 400;
        if (div4 != 0) { return false; }
        if ((div100 == 0) && (div400 != 0)) { return false; }
    }
    return true;
}

function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   for (v = 0; v < sText.length && IsNumber == true; v++) 
      { 
      Char = sText.charAt(v); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}
function checkNumeric(){
    var sMask = "01234567890";
    var KeyTyped = String.fromCharCode(window.event.keyCode);
    var srcObject = window.event.srcElement;
    if (IsNumeric(KeyTyped)){
	}
	else {
		window.event.keyCode = 0;
	}
}
function setFormFunction(strFunction,strForm){
		thisForm=eval("document."+strForm)
		thisForm.W.value=strFunction
		thisForm.submit()
}
function fieldMask(maskType) {
    var sMask = "01234567890()";
    var KeyTyped = String.fromCharCode(window.event.keyCode);
    var srcObject = window.event.srcElement;
    if (sMask.indexOf(KeyTyped.toString()) == -1){
        	window.event.keyCode = 0;
            _ret = false;
    }
	frigger = document.getElementById(window.event.srcElement.id);
	keyCount = frigger.value.length;
	var tmpStr = "";
		if(maskType == "date"){
			switch (keyCount)
				{
				case 1: 
					tmpStr += srcObject.value;
					srcObject.value = tmpStr;
					break;
				case 2:
					srcObject.value += "/";
					break;
				case 5:
					srcObject.value += "/";
					break;
				}
		}
		if(maskType == "time"){
			switch (keyCount)
			{
			case 2:
				srcObject.value += ":";
				break;
			}
		}
		if(maskType == "phone"){
			switch (keyCount)
			{
			case 0:
				newVal = '(' + srcObject.value;
				srcObject.value = newVal;
				break;
			case 4:
				srcObject.value += ") ";
				break;
			case 9:
				srcObject.value += "-";
				break;
			case 14:
				srcObject.value += " Ext ";
				break;
}
		}
}
function ToggleNav(){
}
function clearUserID(){
	document.getElementById('UserID').value=""
}
function inCell(cell,theclass) {
	if (!cell.contains(event.fromElement)) {
		cell.id = theclass;
	}
}

function outCell(cell,theclass) {
	if (!cell.contains(event.toElement)) {
		cell.id = theclass;
	}
}
function confirm_TimeRemove(TimeID){
	input_box=confirm("Warning! Proceeding will delete time entry from the system");
	if (input_box==true){ 
			location.href('./default.asp?W=TimeRemove&TimeID='+TimeID+'');
			history.go();
	}

}
function confirm_DocumentRemove(DocumentID,ProjectID){
	input_box=confirm("Warning! Proceeding will delete document from the system");
	if (input_box==true){ 
			location.href('./default.asp?W=RemoveDocument&DocumentID='+DocumentID+'&ProjectID='+ProjectID);
			history.go();
	}

}
function confirm_RequestRemove(RequestID){
	input_box=confirm("Warning! Proceeding will delete request from the system");
	if (input_box==true){ 
			location.href('./default.asp?W=RemoveRequest&RequestID='+RequestID);
			history.go();
	}

}

function swapClockImage(strClockID){
	myButton=eval(strClockID+"button")
	if(myButton){
		ClockButtonDown(strClockID)
	}else{
		ClockButtonUp(strClockID)
	}
}
function ClockButtonUp(strClockID){
	eval(strClockID+"button"+"="+1)
	eval("document." + strClockID + ".src='./images/ClockPlus.jpg'")
}
function ClockButtonDown(strClockID){
	eval(strClockID+"button"+"="+0)
	 eval("document." + strClockID + ".src='./images/ClockMinus.jpg'")
}
function ShowSelectTS(value){
	if(value=='employee'){
		document.getElementById('xSearchUserID').style.visibility='visible';
		document.getElementById('xSearchUserID').style.position='relative';
	}
	else{
		document.getElementById('xSearchUserID').style.visibility='hidden';
		document.getElementById('xSearchUserID').style.position='absolute';
	}
	if(value=='customer'){
		document.getElementById('xSearchCustomerID').style.visibility='visible';
		document.getElementById('xSearchCustomerID').style.position='relative';
	}
	else{
		document.getElementById('xSearchCustomerID').style.visibility='hidden';
		document.getElementById('xSearchCustomerID').style.position='absolute';
	}
	if(value=='project'){
		document.getElementById('xSearchProjectID').style.visibility='visible';
		document.getElementById('xSearchProjectID').style.position='relative';
	}
	else{
		document.getElementById('xSearchProjectID').style.visibility='hidden';
		document.getElementById('xSearchProjectID').style.position='absolute';
	}
	if(value==''){
		document.getElementById('xSearchProjectID').style.visibility='visible';
		document.getElementById('xSearchProjectID').style.position='relative';
	}
}
function DropAllSubNav(theID,mainNav){
	techString = eval("document.TimeEditor."+theID+".value")
	//alert(techString)
	if(!techString==""){
		if (eval(mainNav)==1){
			var techArray = new Array();
			techString=techString.slice(0,techString.lastIndexOf(","))
			techArray=techString.split(",")
			for (x in techArray){
				if(techArray[x] != ""){
				HideNav2(techArray[x]+'_drop')
				eval(techArray[x]+'_drop' + "=" + 1)
				ClockButtonUp(techArray[x])
				}
			}
			HideNav2(mainNav);
			eval(mainNav + "=" + 1)
			//window.open ('navsessionstate.asp?'+mainNav+'=1','submitbox')
		}
	}
}
function OpenAllSubNav(mainNav){
	theElements = document.getElementsByTagName("table");
	for(i=0;i<theElements.length;i++){
		if(theElements[i].className=='SubTable'){
			theElementName = theElements[i].id
			theElementName = theElementName.slice(0,theElementName.lastIndexOf("_"))
			//alert(theElementName)
			if(eval(mainNav)==1){
				ClockButtonDown(theElementName)
				ShowNav2(theElementName+'_drop')
				eval(theElementName+'_drop' + "=" + 0)
			}
			else{
				ClockButtonUp(theElementName)
				HideNav2(theElementName+'_drop')
				eval(theElementName+'_drop' + "=" + 1)
			}
		}
	}
	if(eval(mainNav)==1){
		eval(mainNav + "=" + 0)
	}
	else{
		eval(mainNav + "=" + 1)
	}
}
function HideNav2(strNavName){
	document.getElementById(strNavName).style.display='none';
}
function ShowNav2(strNavName){
	document.getElementById(strNavName).style.display='inline';
}
function SwapNav2(strNavName){
	if (eval(strNavName)==1){
		ShowNav2(strNavName);
		eval(strNavName + "=" + 0)
		//window.open ('navsessionstate.asp?'+strNavName+'=0','submitbox')
	}else{
		HideNav2(strNavName);
		eval(strNavName + "=" + 1)
		//window.open ('navsessionstate.asp?'+strNavName+'=1','submitbox')
	}
}

function changeSBox(){
	custID = TimeUpdateForm.CustomerID.value;
	projectID = TimeUpdateForm.ProjectID.value;
	techID = TimeUpdateForm.UserID.value;
	phaseID = TimeUpdateForm.PhaseID.value;
	location.href('./default.asp?W=TimeAddForm&Z=1&CustomerID='+custID+'&ProjectID='+projectID+'&UserID='+techID+'&PhaseID='+phaseID+'')
}
function setTBoxVal(strForm,strVal,strValID){
		thisForm=eval("document."+strForm)
		if (strVal == 'Add New'){
			thisForm.AddButton.value='Add New'
			thisForm.PhaseName.value=''
			thisForm.PhaseID.value='0'
		}
		else {
			thisForm.PhaseName.value=strVal
			thisForm.PhaseID.value=strValID
			thisForm.AddButton.value='Update'
		}
}
function checkTBoxPop(strForm,toGo){
		thisForm=eval("document."+strForm)
		if(thisForm.PhaseName.value==""){
			alert('Please Fill In Phase Name')
		}
		else{
			if(toGo == 'SetActive'){
				if (PhaseEditor.PhaseID.value == 0){
					alert('Phase Must Be Added First')
				}
				else{
					location.href('./default.asp?W=SetPhaseActive&PhaseID='+PhaseEditor.PhaseID.value)
				}
			}
			else{
				thisForm.submit();
			}
		}
		
}
function ShowSelectRG(value){
	if(value=='customer'){
		document.getElementById('ReportCustomerIDdiv').style.visibility='visible'
		document.getElementById('ReportCustomerIDdiv').style.position = 'relative'
	}
	else{
		document.getElementById('ReportCustomerIDdiv').style.visibility='hidden'
		document.getElementById('ReportCustomerIDdiv').style.position = 'absolute'
	}
	if(value=='employee'){
		document.getElementById('ReportUserIDdiv').style.visibility='visible'
		document.getElementById('ReportUserIDdiv').style.position = 'relative'
	}
	else{
		document.getElementById('ReportUserIDdiv').style.visibility='hidden'
		document.getElementById('ReportUserIDdiv').style.position = 'absolute'
	}
	if(value=='project'){
		document.getElementById('ReportProjectIDdiv').style.visibility='visible'
		document.getElementById('ReportProjectIDdiv').style.position = 'relative'
	}
	else{
		document.getElementById('ReportProjectIDdiv').style.visibility='hidden'
		document.getElementById('ReportProjectIDdiv').style.position = 'absolute'
	}
	if(value==''){
		document.getElementById('ReportProjectIDdiv').style.visibility='visible'
		document.getElementById('ReportProjectIDdiv').style.position = 'relative'
	}
}
function SetReportVisible(colType){
srcIndex = event.srcElement.selectedIndex
srcName = event.srcElement.name
theElements = document.getElementsByTagName("td");
for(i=0;i<theElements.length;i++){
	if(theElements[i].id == colType){
		if (theElements[i].style.visibility == 'hidden'){
			theElements[i].style.visibility = 'visible';
			theElements[i].style.position = 'relative';
			if(colType == 'note'){
				moveIdx = 0
			}
			else{
				moveIdx = 1
			}
			HighLightIndex(srcIndex,srcName,'False')
		}
		else{
			theElements[i].style.visibility = 'hidden';
			theElements[i].style.position = 'absolute';
				if(colType == 'note'){
					moveIdx = 0
				}
				else{
					moveIdx = -1
				}
			HighLightIndex(srcIndex,srcName,'True')
		}
	}
}
		AdjustTotalCols(moveIdx)
}
function AdjustTotalCols(moveIdx){
	theElements = document.getElementsByTagName("td");
	for(i=0;i<theElements.length;i++){
		if (theElements[i].className == 'ReportCellTTl'){
			curSpan = theElements.item(i).colSpan
			curSpan = curSpan + moveIdx
			theElements[i].colSpan = curSpan
		}
	}
}
function HighLightIndex(idx,name,setType){
	if(setType == 'True'){
		color = "#EA450E"
	}
	else{
		color = "#333333"
	}
	sBox = eval(name);
	sBox.options[idx].style.color = color
}
function compareDates(strDate1,strDate2){
	var firstDate=new Date(strDate1);
	var secondDate=new Date(strDate2);
	if(firstDate<secondDate){
		return true;
	}else{
		return false;
	}
}


