//<SCRIPT>

//window.onerror = null

var ie4 = (document.all!=null)
var ns4 = (document.layers!=null)




//handle Netscape resize bug
function reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.pgW=innerWidth; document.pgH=innerHeight; onresize=reloadPage; }}
  else if (innerWidth!=document.pgW || innerHeight!=document.pgH) location.reload();
}
reloadPage(true);



function popWin(goURL,w,h,features){
	var featureSTR = 'width=' + w + ",height=" + h
	featureSTR += ",resizable=yes"
	if(features){
		if(features.indexOf("scrollbars")>-1 || features.indexOf("scroll")>-1) { featureSTR+=",scrollbars=yes"  }
		if(features.indexOf("location")>-1 || features.indexOf("address")>-1){ featureSTR+=",location=yes"  }
		if(features.indexOf("menubar")>-1 || features.indexOf("menu")>-1)	{ featureSTR+=",menubar=yes"  }
		if(features.indexOf("status")>-1 || features.indexOf("statusbar")>-1)	{ featureSTR+=",status=yes"  }
		if(features.indexOf("toolbar")>-1 || features.indexOf("tool")>-1)	{ featureSTR+=",toolbar=yes"  }
		if(features.indexOf("all")>-1)		{ featureSTR+=",scrollbars=yes,location=yes,menubar=yes,status=yes,toolbar=yes"  }
	}
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	//center window
	featureSTR+=",top="+wint+",left="+winl
	
	openPopupWindow(goURL,'poppy',featureSTR)
}

var gNewWindow=null
function openPopupWindow(theURL,winName,features) {
	//stamp random num to end of URL to assure it's refreshed
	theURL=changeURL(theURL); 

	if (!gNewWindow || gNewWindow.closed) {
		gNewWindow = window.open(theURL,winName,features);
	} else {
	// window already exists, so close it and reload new window
	if(gNewWindow){ gNewWindow.close(); }
		gNewWindow = window.open(theURL,winName,features);
	}
	
	gNewWindow.focus();
}


function openCal(field) {
	theURL=changeURL("../util/calendar/popupCal.asp?field=" + field);
	popWin(theURL,170,160)
}



//append date/time to URL to assure that page is refreshed
function changeURL(goURL){
	if(goURL.indexOf("?") < 0)
		goURL = goURL + "?rand=" + ((new Date()).getTime());
	else
		goURL = goURL + "&rand=" + ((new Date()).getTime());
	return goURL;
}

function gotoURL(goURL){
	window.location=changeURL(goURL);
}

function refreshPage(){
	goURL=String(window.location);
	gotoURL(goURL)	;
}


function nothing(){
	//null
}


function alertWin(msg){
	popWin("../util/alert.asp?msg=" + escape(msg),325,120)
	
}

window.defaultStatus = "";
function winStatus(msg){
	window.status = msg;
}

function goBack(){
	history.go(-1)
}




function getSelectVal(field){
	if(field.selectedIndex==-1) return null;
	else return(field.options[field.selectedIndex].value)
}
function getSelectText(field){
	if(field.selectedIndex==-1) return null;
	return(field.options[field.selectedIndex].text)
}

function setSelectItem(theList,val){
	for(var i=1;i<theList.length;i++){
		if(theList.options[i].value==val){ theList.selectedIndex=i; return }
	}
	theList.selectedIndex=0
}



function hlBG(what){
	what.style.background='#99CCCC'
}
function hlBGOff(what){
	what.style.background='#FFCC66'
}


function mailto(name,email,subject){
	var theURL = "../util/mail.asp"
	theURL += "?toName=" & escape(toName)
	theURL += "&toEmail=" & escape(toEmail)
	theURL += "&subject=" & escape(subject)
	alert(theURL)
	//gotoURL(theURL)

}

function goHome(){
	gotoURL('../customers/overview.asp')
}

function setDateList(list,theDate){

	listDay = eval("document.form1." + list + "Day")
	listMonth = eval("document.form1." + list + "Month")
	listYear = eval("document.form1." + list + "Year")
	
	d = new Date(theDate)

	setSelectItem(listDay,d.getDate())
	setSelectItem(listMonth,d.getMonth()+1)
	setSelectItem(listYear,d.getYear())
}


function Date_dateAdd(interval, number, startDate){
	var buffer = Date.parse( startDate );
	
	switch (interval.charAt(0)){
        case 'd': case 'D': 
            number *= 24 ; // days to hours
            // fall through! 
        case 'h': case 'H':
            number *= 60 ; // hours to minutes
            // fall through! 
        case 'm': case 'M':
            number *= 60 ; // minutes to seconds
            // fall through! 
        case 's': case 'S':
            number *= 1000 ; // seconds to milliseconds
            break ;
        default:	
        alert(intervalMsg) ;
        return null ;
    }
	return new Date( buffer + number ) ;
}

Date.prototype.dateAdd = Date_dateAdd; 

//assembles date from three inputs: month, day, year
function getDate(field){
	var theDay = getSelectVal(eval('document.form1.'+field+'Day'));
	var theMonth = getSelectVal(eval('document.form1.'+field+'Month'));
	var theYear = getSelectVal(eval('document.form1.'+field+'Year'));

	var d = new Date(theYear, theMonth-1, theDay)
	//alert(d)
	return(d);
}

function diffDays(startDate,endDate){
	var diff = endDate-startDate
	//convert to days
	days = parseInt(diff / 86400000) ;
    days += parseInt((diff % 86400000)/43200001) ;
    return(days);
}

function printThisPage(){
	if(window.print) { //browser supports javascript print
		window.print();
	}
}


function round2(val){
	return(Math.round(val*100)/100);

}


function UploadImg(type,target){
	popWin('../util/upload/upload.aspx?type=' + type + '&target=' + target,650,400)
}
function RemoveImg(type,target){
	var targetForm = eval('document.form1.' + target)
	var targetTD = eval('document.all.' + target + 'TD')
	targetForm.value=""
	targetTD.innerHTML="<a href=\"Javascript:UploadImg('"+type+"','" + target + "')\" class=small>Upload Image</a>"
}



function deleteRec(id){
		msg="Are you sure you want to delete this record?"
				+ "\n\nIt cannot be undone."
	var x=confirm(msg)
	if(x){
		document.form1.id.value=id
		document.form1.mode.value="delete"
		document.form1.submit()
	}
}