//start tooltip code
var ns4, ie4, dom;

ns4 = (document.layers)? true:false;
ie4 = (document.all)? true:false;
dom = (document.getElementById) ? true:false;

function checkCard(cc) {
		return cardval(cc.value);
		//alert(cardval(cc.value));
	}
	
function cardval(s) {
	var v = "0123456789";
	var w = "";
	for (i=0; i < s.length; i++) {
		x = s.charAt(i);
		if (v.indexOf(x,0) != -1)
			w += x;
	}
	
	// validate number
	j = w.length / 2;
	if (j < 6.5 || j > 8 || j == 7) return false;
	
	k = Math.floor(j);
	m = Math.ceil(j) - k;
	c = 0;
	for (i=0; i<k; i++) {
		a = w.charAt(i*2+m) * 2;
		c += a > 9 ? Math.floor(a/10 + a%10) : a;
	}
	for (i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
		return (c%10 == 0);
}
	
function showDiv(id, callID) 
{
	if (ns4) 
	{		
		document.layers[id].visibility = "show";
		document.layers[id].display = "block";
	}
	else if (ie4) 
	{		
		//document.all[id].style.left = document.all[callID].style.pixelLeft + 20;
		
		//document.all[id].style.top = document.all[callID].style.pixelTop + 20;

		document.all[id].style.visibility = "visible";
		document.all[id].style.display = "block";
	}
	else if (dom) 
	{
		document.getElementById(id).style.visibility = "visible";		
		document.getElementById(id).style.display = "block";
	}
	
}

function HideTooltip(id)
{
    
	if (ns4)
	{
	    if ((document.layers != null) && (document.layers[id] != null))
        {
            document.layers[id].visibility = "hide";
		    document.layers[id].display = "none";
        }		
	}
	else if (ie4) 
	{
	    if (document.all[id] != null)
	    {
		    document.all[id].style.visibility = "hidden";
		    document.all[id].style.display = "none";
		}
	}
	else if (dom)
	{
	    if (document.getElementById(id) != null)
	    {
		    document.getElementById(id).style.visibility = "hidden";
		    document.getElementById(id).style.display = "none";
		}
	}
}
function ShowTooltip(id)
{
	if (ns4)
	{
		document.layers[id].visibility = "visible";
		document.layers[id].display = "block";
	}
	else if (ie4) 
	{
		document.all[id].style.visibility = "visible";
		document.all[id].style.display = "block";
	}
	else if (dom)
	{
		document.getElementById(id).style.visibility = "visible";
		document.getElementById(id).style.display = "block";
	}
}
function checkDiv(id)
{	
	if (ns4)
	{
		if (document.layers[id].visibility == "hide")
		{
			showDiv(id);
		}
		else
		{
			hideDiv(id);
		}
	}
	else if (ie4)
	{
		if (document.all[id].style.visibility == "hidden")
		{
			showDiv(id);
		}
		else
		{
			hideDiv(id);
		}
	}
	else if (dom) 
	{
		if (document.getElementById(id).style.visibility == "hidden")
		{
			showDiv(id);
		}
		else
		{
			hideDiv(id);
		}
	}
}

//end tooltip code


function moneyFormat(obj){
	var result = "";
	var input;
	var multiplier;
	var decimalPart;
	var numPart;
	var reg = new RegExp("[^0-9.]","gi");
	
	input = obj.value;
	input = input.replace(reg,"");

	if (input.indexOf(".") == -1)
		decimalPart = ".00";
	else
	{
		decimalPart = input.substr(input.indexOf("."), input.length);
		decimalPart = decimalPart.substr(0,3);
		if (decimalPart.length < 3){
			if (decimalPart.length == 1)
				decimalPart = ".00";
			else if (decimalPart.length == 2)
				decimalPart = decimalPart + "0";
		}
			
	}

	if (input.indexOf(".") == -1)
		numPart = input;
	else
		numPart = input.substr(0,input.indexOf("."));
		
		
	for (i = (numPart.length - 3); i > 0; i=i-3){
		result =  "," + numPart.substr(i,3) + result;
	}
	result = "$" + numPart.substr(0,i+3) + result + decimalPart;

	obj.value = result;

}
function openWindow( pageToLoad, winName, width, height, center) {
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;
    }
    args = "width=" + width + "," 
    + "height=" + height + "," 
    + "location=0," 
    + "menubar=0,"
    + "resizable=0,"
    + "scrollbars=0,"
    + "status=1," 
    + "titlebar=0,"
    + "toolbar=0,"
    + "hotkeys=0,"
    + "left=" + xposition + ","
    + "top=" + yposition;

    newWindow = window.open( pageToLoad,winName,args );
}
function openWindowWithScrollingResizeable( pageToLoad, winName, width, height, center) {
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;
    }
    args = "width=" + width + "," 
    + "height=" + height + "," 
    + "location=0," 
    + "menubar=0,"
    + "resizable=1,"
    + "scrollbars=1,"
    + "status=1," 
    + "titlebar=0,"
    + "toolbar=0,"
    + "hotkeys=0,"
    + "left=" + xposition + ","
    + "top=" + yposition;

    newWindow = window.open( pageToLoad,winName,args );
}
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	
	if(cents<10)
		cents = "0" + cents;
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
	
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function openScrollingWindow( pageToLoad, winName, width, height, center) {
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;
    }
    args = "width=" + width + "," 
    + "height=" + height + "," 
    + "location=0," 
    + "menubar=0,"
    + "resizable=1,"
    + "scrollbars=1,"
    + "status=1," 
    + "titlebar=0,"
    + "toolbar=0,"
    + "hotkeys=0,"
    + "left=" + xposition + ","
    + "top=" + yposition;

    newWindow = window.open( pageToLoad,winName,args );
}

function openPrintWindow( pageToLoad, winName, width, height, center) {
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;
    }
    args = "width=" + width + "," 
    + "height=" + height + "," 
    + "location=0," 
    + "menubar=0,"
    + "resizable=1,"
    + "scrollbars=0,"
    + "status=1," 
    + "titlebar=0,"
    + "toolbar=0,"
    + "hotkeys=0,"
    + "left=" + xposition + ","
    + "top=" + yposition;

    newWindow = window.open( pageToLoad,winName,args );
}

function openExcelWindow( pageToLoad, winName, width, height, center) {
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;
    }
    args = "width=" + width + "," 
    + "height=" + height + "," 
    + "location=0," 
    + "menubar=1,"
    + "resizable=1,"
    + "scrollbars=0,"
    + "status=1," 
    + "titlebar=0,"
    + "toolbar=0,"
    + "hotkeys=0,"
    + "left=" + xposition + ","
    + "top=" + yposition;

    newWindow = window.open( pageToLoad,winName,args );
}

function crPrint( pageToLoad) {
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (1)){
        xposition = (screen.width - 200) / 2;
        yposition = (screen.height - 300) / 2;
    }
    args = "width= 200," 
    + "height=300," 
    + "location=0," 
    + "menubar=0,"
    + "resizable=1,"
    + "scrollbars=0,"
    + "status=1," 
    + "titlebar=0,"
    + "toolbar=0,"
    + "hotkeys=0,"
    + "left=" + xposition + ","
    + "top=" + yposition;
	winName="t"
	qString="crystal/CRYSTAL_PRINT.aspx?rptURL=" + pageToLoad
    newWindow = window.open(qString,winName,args );
	
}
function pdfPrint( pageToLoad) {
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (1)){
        xposition = (screen.width - 200) / 2;
        yposition = (screen.height - 300) / 2;
    }
    args = "width= 400," 
    + "height=600," 
    + "location=0," 
    + "menubar=0,"
    + "resizable=1,"
    + "scrollbars=0,"
    + "status=1," 
    + "titlebar=0,"
    + "toolbar=0,"
    + "hotkeys=0,"
    + "left=" + xposition + ","
    + "top=" + yposition;
	winName="t"
	qString=pageToLoad
    newWindow = window.open(qString,winName,args );
	//alert("DFDF")
    //newWindow.print()
	//newWindow.close()
	
}

function clearTopFrame() {
	parent.document.location.href="MDE_DEfault.aspx?new=1";
}

function openModalDialog( pageToLoad, winObject, width, height, center) {
    args = "dialogWidth:" + width + "px;" 
    + "dialogHeight:" + height + "px;" 
    + "status:0;" 
	+ "help:0;"
	+ "center:1;"
	+ "scroll:0;"

    window.showModalDialog( pageToLoad,winObject,args );
}

function newConfirm(title,mess,icon,defbut,mods) {	
//Requires VBYesNo.vbs to be included as well
	icon = (icon==0) ? 0 : 2;
	defbut = (defbut==0) ? 0 : 1;
	retVal = makeMsgBox(title,mess,icon,4,defbut,mods);
	retVal = (retVal==6);
	return retVal;
}

function formatRegNumber(theTextField) {
	theTextField.value = theTextField.value.toUpperCase();
}

function addDateSlashes(theTextField,evt){
		//alert(window.event.keyCode);
		// quit theTextField or the event was not passed
		if (arguments.length != 2)
			return;

		// if keystroke was a backstroke or tab exit the function
		if ((window.event.keyCode == 8) || (window.event.keyCode == 9))
			return;

		// if keystroke was an arrow key exit the function
	  var keyCode = 
	    document.layers ? evt.which :
	    document.all ? event.keyCode :
	    document.getElementById ? evt.keyCode : 0;
	  if (keyCode == 39){
			return;
		}else if (keyCode == 40){
			return;
		}else if (keyCode == 38){
			return;
		}else if (keyCode == 37){
			return;
		}
			
		// formatting
		theTextField.value=theTextField.value.replace('/','');
		if(theTextField.value.length == 2){
			theTextField.value=theTextField.value + '/';
		}else if(theTextField.value.length > 2){
			if(theTextField.value.slice(2,3) != '/')
				theTextField.value=theTextField.value.slice(0,2) + '/' + theTextField.value.slice(2,theTextField.value.length);
		}
		if(theTextField.value.length == 5){
			theTextField.value=theTextField.value + '/';
		}else if(theTextField.value.length > 5){
			if(theTextField.value.slice(5,6) != '/')
				theTextField.value=theTextField.value.slice(0,5) + '/' + theTextField.value.slice(5,theTextField.value.length);
		}
		theTextField.value=theTextField.value.replace('//','/');
		theTextField.value=theTextField.value.replace('//','/');
	}
	
function limitPD(theTextArea)
	{
		var arealen 
		arealen=theTextArea.value.length-1
		if (theTextArea.scrollHeight>119)
			{
				alert("Your Property Description may be a maximum of 9 lines")
				theTextArea.value=theTextArea.value.substring(0,arealen)		
			}
	}
	
	
	function formatPostalCode(theTextField,evt,calltype){
	// theTextField = the field from which the function was called (just pass 'this')
	// evt = event (just pass 'event')

		// quit theTextField or the event was not passed
		if (arguments.length != 3)
			return;

		//if the function was called on a keystroke make sure it ignores arrows and such
		if (calltype == 'keystroke'){
			// if keystroke was a backstroke exit the function
			if (window.event.keyCode == 8)
				return;
	
			// if keystroke was an arrow key exit the function
		  var keyCode = 
		    document.layers ? evt.which :
		    document.all ? event.keyCode :
		    document.getElementById ? evt.keyCode : 0;
		  if (keyCode == 39){
				return;
			}else if (keyCode == 40){
				return;
			}else if (keyCode == 38){
				return;
			}else if (keyCode == 37){
				return;
			}
		}
			
		// formatting
		theTextField.value=theTextField.value.replace(/ /g,'');
		
		// only format postal codes 
	//	if (document.f1.ddlProvinces.value < 14){
			theTextField.value=theTextField.value.toUpperCase();
			if(theTextField.value.length == 3){
				theTextField.value=theTextField.value + ' ';
			}else if(theTextField.value.length > 2){
				if(theTextField.value.slice(3,4) != ' ')
					theTextField.value=theTextField.value.slice(0,3) + ' ' + theTextField.value.slice(3,theTextField.value.length);
			}
	//	}
	}

	function formatMtgNumber(theTextField,evt,calltype) {
		// theTextField = the field from which the function was called (just pass 'this')
		// evt = event (just pass 'event')

		// quit theTextField or the event was not passed
		if ( !(theTextField.value.length == 3 || theTextField.value.length == 7 || theTextField.value.length == 10))
			return;
		
		//if the function was called on a keystroke make sure it ignores arrows and such
		if (calltype == 'keystroke'){
			// if keystroke was a backstroke exit the function
			if (window.event.keyCode == 8)
				return;
	
			// if keystroke was an arrow key exit the function
			var keyCode = 
				document.layers ? evt.which :
				document.all ? event.keyCode :
				document.getElementById ? evt.keyCode : 0;
			
			if (keyCode == 39)
				return;
			else if (keyCode == 40)
				return;
			else if (keyCode == 38)
				return;
			else if (keyCode == 37)
				return;
		}
		// first, get rid of any spaces in the field
		theTextField.value=theTextField.value.replace(/ /g,'');		

		// add new spaces where they need to be to make the format == '### ### ###'
		var temp = '';

		for (var j = 0; j < theTextField.value.length; j++) {
			temp += theTextField.value.charAt(j);
			
			if (j == 2 || j == 5)
				temp += ' ';
		}

		theTextField.value = temp;
	}

	function formatPhoneNumber(theTextField,evt,calltype){
	// theTextField = the field from which the function was called (just pass 'this')
	// evt = event (just pass 'event')

		if (window.event.keyCode != 9){
		//alert(window.event.keyCode);
		// quit theTextField or the event was not passed
		if (arguments.length != 3)
			return;
			
		//if the function was called on a keystroke make sure it ignores arrows and such
		if (calltype == 'keystroke'){
		// if keystroke was a backstroke exit the function
			if (window.event.keyCode == 8)
				return;
	
		// if keystroke was an arrow key exit the function
		  var keyCode = 
		    document.layers ? evt.which :
		    document.all ? event.keyCode :
		    document.getElementById ? evt.keyCode : 0;
		  if (keyCode == 39){
				return;
			}else if (keyCode == 40){
				return;
			}else if (keyCode == 38){
				return;
			}else if (keyCode == 37){
				return;
			}
		}
		
		// formatting	
		theTextField.value=theTextField.value.replace(/ /g,'');
		theTextField.value=theTextField.value.replace('-','');
		theTextField.value=theTextField.value.replace('(','');
		theTextField.value=theTextField.value.replace(')','');
		if(theTextField.value.length >= 1){
			if(theTextField.value.slice(0,1) == '1'){
				if(theTextField.value.length >= 2){
					if(theTextField.value.slice(1,2) != ' ')
						theTextField.value=theTextField.value.slice(0,1) + ' ' + theTextField.value.slice(1,theTextField.value.length);
					if(theTextField.value.length >= 3){
						if(theTextField.value.slice(2,3) != '(')
							theTextField.value=theTextField.value.slice(0,2) + '(' + theTextField.value.slice(2,theTextField.value.length);
						if(theTextField.value.length >= 7){
							if(theTextField.value.slice(6,7) != ')')
								theTextField.value=theTextField.value.slice(0,6) + ')' + theTextField.value.slice(6,theTextField.value.length);
							if(theTextField.value.length >= 8){
								if(theTextField.value.slice(7,8) != ' ')
									theTextField.value=theTextField.value.slice(0,7) + ' ' + theTextField.value.slice(7,theTextField.value.length);
								if(theTextField.value.length >= 11)
									if(theTextField.value.slice(11,12) != '-')
										theTextField.value=theTextField.value.slice(0,11) + '-' + theTextField.value.slice(11,theTextField.value.length);
							}
						}
					}
				}
			}else{
				if(theTextField.value.slice(0,1) != '(')
					theTextField.value='(' + theTextField.value;
				if(theTextField.value.length >= 4){
					if(theTextField.value.slice(4,5) != ')')
						theTextField.value=theTextField.value.slice(0,4) + ')' + theTextField.value.slice(4,theTextField.value.length);
					if(theTextField.value.length >= 5){
						if(theTextField.value.slice(5,6) != ' ')
							theTextField.value=theTextField.value.slice(0,5) + ' ' + theTextField.value.slice(5,theTextField.value.length);
						if(theTextField.value.length >= 9)
							if(theTextField.value.slice(8,9) != '-')
								theTextField.value=theTextField.value.slice(0,9) + '-' + theTextField.value.slice(9,theTextField.value.length);
					}
				}
			}
		}
		}
	}


	
	function setelementfocus(theelement) {
		//alert('Hey sucker!  setelementfocus was called!');
		if (theelement != -1 && theelement.enabled == true)
			document.f1.elements[theelement].focus();
	}

	function showelementnum(theelement) {
		var currelement=-1;
		for (i=0; i<document.f1.length; i++)
			if (document.f1.elements[i].name == theelement.name){
				currelement=i;
				break;
			}
		//alert("SHOW:"+currelement);
	}

	function compareValue(charcount, currfield, nextfield, formname, evt){

		// if formname was not passed set it to 'f1'
		if (arguments.length == 4)
			formname='f1';

		// find out what the number of 'formname' is ...
		var formNum=-1;
		for (i = 0; document.forms[i]; i ++) {
			if (document.forms[i].name == formname) {
				formNum = i;
				break;
			}
		}
		
		// quit if 'formname' isn't a real form.
		if (formNum < 0) {
			return;
		}

		// find out what the number of 'currfield' is ...
		var currelement=-1;
		for (i=0; i<document.forms[formNum].length; i++)
			if (document.forms[formNum].elements[i].name == currfield){
				currelement=i;
				break;
			}

		// quit if 'currfield' isn't a real form element.
		if (currelement < 0) {
			return;
		}

		// find out what the number of 'nextfield' is ...
		var nextelement=-1;
		for (i=0; i<document.forms[formNum].length; i++)
			if (document.forms[formNum].elements[i].name == nextfield){
				nextelement=i;
				break;
			}

		// quit if 'nextfield' isn't a real form element.
		if (nextelement < 0) {
			return;
		}

	// if keystroke was a backstroke or tab exit the function
		if ((window.event.keyCode == 8) || (window.event.keyCode == 9))
			return;

	// if keystroke was an arrow key exit the function
	  var keyCode = 
	    document.layers ? evt.which :
	    document.all ? event.keyCode :
	    document.getElementById ? evt.keyCode : 0;
	  if (keyCode == 39){
			return;
		}else if (keyCode == 40){
			return;
		}else if (keyCode == 38){
			return;
		}else if (keyCode == 37){
			return;
		}

		// check if the length of the current field data is equal to charcount
		if (document.forms[formNum].elements[currelement].value.length == charcount){
			// go to the next field
			document.forms[formNum].elements[nextelement].select();
			//alert('setting focus to ' + nextelement);
			document.forms[formNum].elements[nextelement].focus();
		
		}
	}
	
function currencyFormat(fld, milSep, decSep) {
		var sep = 0;
		var key = '';
		var i = j = 0;
		var len = len2 = 0;
		var strCheck = '0123456789';
		var aux = aux2 = '';
		alert(fld.value)
		alert(fld)
		aux = '';
		for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
		aux += key;
		len = aux.length;
		if (len == 0) fld.value = '';
		if (len == 1) fld.value = '0'+ decSep + '0' + aux;
		if (len == 2) fld.value = '0'+ decSep + aux;
		if (len > 2) {
		aux2 = '';
		for (j = 0, i = len - 3; i >= 0; i--) {
		if (j == 3) {
		aux2 += milSep;
		j = 0;
		}
		aux2 += aux.charAt(i);
		j++;
		}
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
		fld.value += aux2.charAt(i);
		fld.value += decSep + aux.substr(len - 2, len);
		}
return false;
}	
	
	/*
function openWindow( pageToLoad, winObject, width, height, center) {
    args = "dialogWidth:" + width + "px;" 
    + "dialogHeight:" + height + "px;" 
    + "status:1;" 
	+ "help:0;"
	+ "center:1;"
	+ "scroll:0;"

    win = window.open( pageToLoad,winObject,args );
    win.focus();
}*/

function checkLength( textbox, nextTexBox, maxLength ) {
/*
	var content = textbox.value;
	var tb;
	
	if( content.length  >= maxLength ) {
		tb = document.getElementById(nextTexBox);
		tb.focus();
	}
	*/
}

function showDynDiv(divName) {
    var objDiv = document.getElementById(divName);
    if (objDiv == null)
    {
        return;
    }
	var objDivStyle = document.getElementById(divName).style;
	objDivStyle.visibility = 'visible';
	objDivStyle.position = 'static';
	objDivStyle.display='block';
}

function hideDynDiv(divName) {
    var objDiv = document.getElementById(divName);
    if (objDiv == null)
    {
        return;
    }
	var objDivStyle = document.getElementById(divName).style;
	objDivStyle.visibility = 'hidden';
	objDivStyle.position = 'absolute';
	objDivStyle.display='none';
}

function replaceAll(text, strA, strB)
{
	return text.replace( new RegExp(strA,"g"), strB );    
}

function toggleDiv(rb, divName)
{
	var rbField = document.getElementById(rb);
	if (rbField == null)
	{
		rbField = document.getElementById(replaceAll(rb,":","_" ));
	}
	if (rbField == null)
	{
	    return;
	}
	if (rbField.checked)
		showDynDiv(divName);
	else
		hideDynDiv(divName);			
}

function getField(fieldName)
{
	var tempField = document.getElementById(fieldName);
	if (tempField == null)
	{
		tempField = document.getElementById(replaceAll(fieldName,":","_" ));
	}
	return tempField;
}


function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0)
		{
			return c.substring(nameEQ.length,c.length);
		}
	}
	return null;
}


<!--
function checkProvCookie()
{
	//if (readCookie('prov_pref') == null)
		//location.replace('http://localhost/cti/choose_lang.htm');
}
//-->
