	var thePreviousColor = '';
	
	//opens a new lead window, used on the main page.
	function openWindow(theLeadID) {
		var theWidth=0;
		var theHeight=0;

		if (screen.width==800) {
			theWidth="780";
			theHeight="580";
		}
		else {
			theWidth="1000";
			theHeight="720";
		}

		theNewWindow = window.open("./NewLead.php?LeadID=" + theLeadID + 
						"","theWin","height=" + theHeight + ",width=" + theWidth + ",resizable=yes,scrollbars=yes,status=no,toolbar=no, " +
						"menubar=no,location=no");

		theNewWindow.focus();

		if (theWidth=="1000")
			theNewWindow.moveTo(10,10);
	}

	//opens a new lead window, used on the main page.
	function openNotesHistory(theLeadID) {
		theNewWindow = window.open("./NotesHistory.php?LeadID=" + theLeadID + 
						"","_blank","height=500,width=500,status=no,toolbar=no, " +
						"menubar=no,location=no");

		theNewWindow.moveTo(100,100);
	}
	//pass in the selectbox/dropdown and a value to compare, it will search through 
	//all the elements in the dropdown until it finds a match, and will select it
	function checkSelected(theSelectbox, compareTo) {
		for (x=0;x<theSelectbox.options.length;x++) {
			if (theSelectbox.options[x].value==compareTo) {
				theSelectbox.selectedIndex = x;
			}
		}
	}

	function openNewDealer(theDealerID, theAction) {
		theNewWindow = window.open("./NewDealer.php?Action=" + theAction + "&DealerID=" +  theDealerID,"_blank","height=685,width=480,status=no,toolbar=no, " +
						"menubar=no,location=no");

		theNewWindow.moveTo(100,100);
	}

	function stripDollars(theValue) {
		theValue = theValue.replace("$", "");
		theValue = theValue.replace(",", "");

		return theValue;
	}

	//used on main page (new leads, appointments, followups) to do mouse over events
	function onOver(theTR) {
		theTR.bgColor = '#B8CEDC';

		if (theTR.cells[0])
			theTR.cells[0].style.fontWeight = 'bold';
		if (theTR.cells[1])
			theTR.cells[1].style.fontWeight = 'bold';
		if (theTR.cells[2])
			theTR.cells[2].style.fontWeight = 'bold';
		if (theTR.cells[3])	//check if the last column is there, only 3 columns in new leads and 4 in appts
			theTR.cells[3].style.fontWeight = 'bold';
	}

	function onOut(theTR) {
		theTR.bgColor = '#EBEDF3';

		if (theTR.cells[0])
			theTR.cells[0].style.fontWeight = 'normal';
		if (theTR.cells[1])
			theTR.cells[1].style.fontWeight = 'normal';
		if (theTR.cells[2])
			theTR.cells[2].style.fontWeight = 'normal';
		if (theTR.cells[3])
			theTR.cells[3].style.fontWeight = 'normal';
	}

	function onNewLeadOver(theTR) {
		thePreviousColor = theTR.bgColor;
		theTR.bgColor = '#B8CEDC';

		if (theTR.cells[0])
			theTR.cells[0].style.fontWeight = 'bold';
		if (theTR.cells[1])
			theTR.cells[1].style.fontWeight = 'bold';
		if (theTR.cells[2])
			theTR.cells[2].style.fontWeight = 'bold';
		if (theTR.cells[3])	//check if the last column is there, only 3 columns in new leads and 4 in appts
			theTR.cells[3].style.fontWeight = 'bold';
	}

	function onNewLeadOut(theTR) {
//		theTR.bgColor = '#EBEDF3';
		theTR.bgColor = thePreviousColor;

		if (theTR.cells[0])
			theTR.cells[0].style.fontWeight = 'normal';
		if (theTR.cells[1])
			theTR.cells[1].style.fontWeight = 'normal';
		if (theTR.cells[2])
			theTR.cells[2].style.fontWeight = 'normal';
		if (theTR.cells[3])
			theTR.cells[3].style.fontWeight = 'normal';
	}

	function onReportOver(theTR) {
		thePreviousColor = theTR.bgColor;
		theTR.bgColor = 'yellow';
	}

	function onReportOut(theTR) {
		theTR.bgColor = thePreviousColor;			
	}


	function isSIN(num) {
		snum = '';
		template = '121212121';
		d = '';
		sd = 0;

		for(x=0;x<num.length;x++) {
			if((num.charAt(x) >= '0') && (num.charAt(x) <= '9')) {
				snum = snum + num.charAt(x);
			}
		}
	  
		if(snum.length != 9) {
			return false;
		}

		for(x=0;x<snum.length;x++) {
			d = snum.charAt(x) * template.charAt(x);

			if(d > 9) {
				d = d + '';
				d = (d.charAt(0)*1) + (d.charAt(1)*1);
			}
			
			sd = sd + (d * 1);
		}

		if(sd % 10 == 0) {
			return snum.substring(0,3) + ' ' + snum.substring(3,6) + ' ' + snum.substring(6,9);
		}
		else {
			return false;
		}
	}

	function isPostalCode(pc) {
		pc = pc.toUpperCase();
		tpc = '';

		for(n=0;n<pc.length;n++) {
			if((pc.charAt(n) >= '0' && pc.charAt(n) <=9) || (pc.charAt(n) >= 'A' && pc.charAt(n) <='Z')) {
				tpc = tpc + pc.charAt(n);
			}
		}

		if(tpc.length == 6) {
			for(l=0;l<6;l+=2) {
				
				if(tpc.charAt(l) < 'A' || tpc.charAt(l) > 'Z') {
					return false;
				}

				if(tpc.charAt(l+1) < '0' || tpc.charAt(l+1) > '9') {
					return false;
				}
			}
			
			return tpc.substring(0,3) + ' ' + tpc.substring(3,6);
		}
		else {
			return false;
		}  
	}

	function isPhone(pn) {
		tpn = '';
		for(n=0;n<pn.length;n++) {
			if(pn.charAt(n) >= '0' && pn.charAt(n) <= '9') {
				tpn = tpn + pn.charAt(n);
			}
		}

		if(tpn.length == 10) {
			return tpn;
		}
		else {
			return false;
		}
	}

	function validateProvincePostal(ProvinceID, PostalCode) {
		ppc = new Array(13);

		ppc[00] = '-';
		ppc[01] = 'T';     // AB
		ppc[02] = 'V';     // BC
		ppc[03] = 'C';     // PE
		ppc[04] = 'R';     // MB
		ppc[05] = 'A';     // NF
		ppc[06] = 'E';     // NB
		ppc[07] = 'B';     // NS
		ppc[08] = 'X';     // NVT
		ppc[09] = 'KLMNP'; // ON
		ppc[10] = 'GHJ';   // QC
		ppc[11] = 'S';     // SK
		ppc[12] = 'X';     // NWT
		ppc[13] = 'Y';     // YT

		tc = PostalCode.charAt(0);

		if(ppc[ProvinceID].indexOf(tc) >= 0) {
			return true;
		}
		else {
			return false;
		}
	}
