﻿//<!--

var RowSelectColor = '#ffcc66';
var RowUnSelectColor = 'White';

 function findElementById(id) {												
	if (document.getElementById != null) {	// try ie and such
		return document.getElementById(id);	
	} else {					
		if (document.layers != null) {		// try nn and such
			return document.layers[id]; 		
		} else {							// last resort									
			return document.all(id);
		}
	}
}

function HoverOn(ctrl) {
	ctrl.style.cursor = 'pointer';		
}

function HoverOff(ctrl) {
	ctrl.style.cursor = 'default';
}
	
function SyncDropDownByIndex(ddlMasterName, ddlSlaveName, evt) {

	var ctlMaster = findElementById(ddlMasterName);
	var ctlSlave = findElementById(ddlSlaveName);
	ctlSlave.selectedIndex = ctlMaster.selectedIndex;
}

function SelectRow(ctl) {

	var grid;
	if (ctl.parentElement) {
		grid = ctl.parentElement.parentElement;	
	} else {
		grid = ctl.parentNode.parentNode;
	}

	// Start at row 1 in order to skip header in row zero.
	var i=0;
	for (i=1; i<grid.rows.length; i++) {
		if (i == ctl.rowIndex) {
			grid.rows[i].style.backgroundColor = RowSelectColor;
		} else {
			grid.rows[i].style.backgroundColor = RowUnSelectColor;
		}
	}
	return true;
}	

function ClearList(lst) {
	var i=0;
	for (i=lst.options.length-1;i>=0;i--) {
		lst.remove(i);
	}
}

function BubbleOff(evt) {

	var e = GetEvent(evt);

	if (e.stopPropagation) {
		e.stopPropagation();
		e.preventDefault();		
	} else {	
		e.returnValue = false;
		e.cancelBubble = true;	
	}
}	

function Flip(src, className) {
	if (src) { src.className = className; }
	return true;
}

function GetEventSource(evt) {

	var src;
	var e = GetEvent(evt);

	if (e.target) { src = e.target; }
	else if (e.srcElement) { src = e.srcElement; }
	if (src && src.nodeType == 3) // defeat Safari bug
		src = src.parentNode;
	
	return src;
}

function GetEvent(evt) {
	
	var e;
	if (!evt)
		e = window.event;
	else
		e = evt;
		
	return e;
}

function IsMatchEmail(email) {
	
	var re = new RegExp(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/);

	var isValid = false;
	if (email.match(re)) {
		isValid = true;
	} else {
		isValid = false;
	}    	
	return isValid;				 	
}
	
function IsMatchFax(fax) {

	var isValid = false;		
	var re = new RegExp(/((\(\d{3}\) )|(\d{3}-))\d{3}-\d{4}/);

	if (fax.match(re)) {
		isValid = true;
	} else {
		isValid = false;
	}     	
	return isValid;				 	
}	

function ShowWarning(ctl, warnMsg) {
	ctl.className = "WarningOn";
	ctl.innerHTML = warnMsg;
}

function HideWarning(ctl) {
	ctl.className = "WarningOff";
}
	
function DoSubmit() {var frm = findElementById("Form1");frm.submit();}

function ShowBrowserDialog(controlPath, actCtlName, action, mstCtlName, msg, evt) {

	var popWidth = 400;
	var popHeight = 180;
	var popupPath = controlPath + "/FolderBrowser.aspx";
	
	GetText(popupPath, popHeight, popWidth, actCtlName, action, mstCtlName, msg, evt); 
}

function ShowDatePicker(controlPath, mstCtlName, msg, evt) {

	var popWidth = 250;
	var popHeight = 270;
	var popupPath = controlPath + "/DatePicker.aspx";

	GetText(popupPath, popHeight, popWidth, "", "", mstCtlName, msg, evt); 
}

function GetDate(targetCtrlName) {

	var ctlName = "";
	var ctl = null;
	for(ctl in window.document.all) {
		if (ctl.indexOf(targetCtrlName) != -1) {
			ctlName = ctl;
			break;
		}
	}
	
	var popWidth = 250;
	var popHeight = 220;
	var url = "../UControls/DatePicker.aspx?MasterControlName=" + ctlName;
	
	var top = (screen.height-popHeight)/2;
	var left = (screen.width-popWidth)/2;
	
	if ( top <= 0 ) {
		top = 25;
	}
	if (left <= 0) {
		left = 25;
	}				

	var win = window.open(url, "_blank", 
		"status=0,toolbar=0,top=" + top + ",left=" + left + ",location=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=" + popWidth + ",height=" + popHeight);
}

function SetDate(dateControl, selectedDate) {
	var dtCtl = findElementById(dateControl);
	dtCtl.value = selectedDate;
}

function GetText(popupPath, popHeight, popWidth, actCtlName, action, mstCtlName, msg, evt) {
	
	var url = popupPath + "?MasterControlName=" + mstCtlName + 
		"&ActionControlName=" + actCtlName + 
		"&Action=" + action + 
		"&Label=" + msg;

	var top = (screen.height-popHeight)/2;
	var left = (screen.width-popWidth)/2;
	
	if ( top <= 0 ) {
		top = 25;
	}
	if (left <= 0) {
		left = 25;
	}				

	var win = window.open(url, "_blank", 
		"status=0,toolbar=0,top=" + top + ",left=" + left + ",location=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=" + popWidth + ",height=" + popHeight);

	var e = GetEvent(evt);		
	BubbleOff(e);		
}

function GetTextEntry(actCtlName, action, mstCtlName, msg, clickControlName, evt) {
		
	var popWidth = 250;
	var popHeight = 180;	
	var url = "../UControls/TextEntry.aspx?MasterControlName=" + mstCtlName + 
		"&ActionControlName=" + actCtlName + 
		"&Action=" + action + 
		"&Label=" + msg +
		"&clickCtrlName=" + clickControlName;
	
	var top = (screen.height-popHeight)/2;
	var left = (screen.width-popWidth)/2;
	
	if ( top <= 0 ) {
		top = 25;
	}
	if (left <= 0) {
		left = 25;
	}				

	var win = window.open(url, "_blank", 
		"status=0,toolbar=0,top=" + top + ",left=" + left + ",location=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=" + popWidth + ",height=" + popHeight);

	var e = GetEvent(evt);		
	BubbleOff(e);		
}

function SetText(actCtlName, actionValue, mstCtlName, entryValue) {

	var mstCtl = findElementById(mstCtlName);
	if (mstCtl != null && entryValue != null && entryValue.length > 0) {
		mstCtl.value = entryValue;		
	}
	
	var actCtl = findElementById(actCtlName);	
	if (actCtl != null && actionValue != null && actionValue.length > 0) {
		actCtl.value = actionValue;		
	}  
	
	theForm.submit();
}


function PopAlert(url, evt) {

	if (url != null && url.length > 0) {

		var popWidth = screen.width-150;
		var popHeight = screen.height-150;

		var win = window.open(url, "_blank", 
			"status=0,toolbar=1,location=0,top=100,left=100,menubar=1,directories=0,resizable=1,scrollbars=1,width=" + popWidth + ",height=" + popHeight);									
	}	
	
	BubbleOff(evt);
	return false;
			
}

// Currently supports: Input, Select
function findControlByTypeID( typeName, idGiven) {
    
    var matchTypeName = "";    
    if (typeName == 'textbox') {
        matchTypeName = 'input'; 
    } else {
        matchTypeName = typeName;    
    }

    var ctl = null;    
    var lists = document.getElementsByTagName(matchTypeName);
    for (var i = 0; i < lists.length; i++) {
        if(lists[i].id.endsWith = idGiven) {
            ctl = lists[i];
            break;
        }
    }      
    
    return ctl;
}

//-->