var _ms_XMLHttpRequest_ActiveX = ""; // Holds type of ActiveX to instantiate
var _ajax;                           // Reference to a global XMLHTTPRequest object for some of the samples
var _logger = false;                  // write output to the Activity Log
var _status_area;                    // will point to the area to write status messages to
var toggled = {};

if (typeof Prototype == "undefined")
	$include('/js/prototype.js');

if (typeof Scriptaculous == "undefined")
	$include('/js/scriptaculous/scriptaculous.js');

function isUserLoggedIn() {
	if (getCookie("loggedIn") == null || getCookie("loggedIn") == "false")
		return false;
	else if (getCookie("loggedIn") == "true")
		return true;
}

function $include(path) {
	var e = document.createElement("script");
	e.src = path + '?' + rand() + rand();
	e.type="text/javascript";
	document.getElementsByTagName("head")[0].appendChild(e);
}

function rand() {
	return (Math.floor(Math.random() * (new Date()).getSeconds() + (new Date()).getSeconds() + 1));	
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function wowi(node1id, node2id) {
	var wipeOut;
	node1id = "\"" + node1id + "\"";
	node2id = "\"" + node2id + "\"";

	if (toggled[eval(node1id) + "Displayed"] == undefined) toggled[eval(node1id) + "Displayed"] = true;

	if (toggled[eval(node1id) + "Displayed"]) {
	
		wipeOut = dojo.lfx.wipeOut($(eval(node1id)), null, null, function(n) {
			$(eval(node1id)).style.display='none';
			$(eval(node2id)).style.display='block';
			dojo.lfx.wipeIn($(eval(node2id))).play();			
		});
		toggled[eval(node1id) + "Displayed"] = false;
	}
	else {
	
		wipeOut = dojo.lfx.wipeOut($(eval(node2id)), null, null, function(n) {
			$(eval(node1id)).style.display='block';
			$(eval(node2id)).style.display='none';
			dojo.lfx.wipeIn($(eval(node1id))).play();
		});
		toggled[eval(node1id) + "Displayed"] = true;
	}
	
	wipeOut.play();
}

if (!window.Node || !window.Node.ELEMENT_NODE) {
    var Node = { ELEMENT_NODE: 1, ATTRIBUTE_NODE: 2, TEXT_NODE: 3, CDATA_SECTION_NODE: 4, ENTITY_REFERENCE_NODE: 5,
                  ENTITY_NODE: 6, PROCESSING_INSTRUCTION_NODE: 7, COMMENT_NODE: 8, DOCUMENT_NODE: 9, DOCUMENT_TYPE_NODE: 10, 
    		  DOCUMENT_FRAGMENT_NODE: 11, NOTATION_NODE: 12 };
}

if (typeof Prototype == "undefined") {
	// From prototype.js @ www.conio.net | Returns an object reference to one or more strings
	// ignore the fact that there are no arguments to this method -- javascript doesn't care how many you send (not strongly typed)
	// The method checks the actual # of arguments -- returns a single object or an array
	function $() {
	    var elements = new Array();
	
	    for (var i = 0; i < arguments.length; i++) {
	        var element = arguments[i];
	
	        if (typeof element == 'string')
	            element = document.getElementById(element);
	
	        if (arguments.length == 1)
	            return element;
	
	        elements.push(element);
	    }
	
	    return elements;
	}
}

// Method to get text from an XML DOM object
function getTextFromXML( oNode, deep ) {
    var s = "";
    var nodes = oNode.childNodes;

    for (var i = 0; i < nodes.length; i++) {
        var node = nodes[i];

        if (node.nodeType == Node.TEXT_NODE) {
            s += node.data;
        } else if (deep == true && (node.nodeType == Node.ELEMENT_NODE || node.nodeType == Node.DOCUMENT_NODE
                                       || node.nodeType == Node.DOCUMENT_FRAGMENT_NODE)) {
            s += getTextFromXML(node, true);
        };
    }

    ;
    return s;
}

;
	function getText(rootElement, pathExpression) {
		var pathElements = pathExpression.split('/');
		var root = rootElement;
		for (var i=0;i < pathElements.length;i++) {
			if (pathElements[i].indexOf('@') == 0) {
				return root.getAttribute(pathElements[i].substring(1));
			}
			var match = false;
			for (var j=0;j<root.childNodes.length;j++) {
				if (root.childNodes[j].nodeName == pathElements[i]) {
					root = root.childNodes[j];
					match = true;
					break;
				}
			}
			if (match == false) {
				return null;
			}
		}		

		return root.firstChild.nodeValue;
	};

	function goodKeystroke(event) {
		if (event) {
			if (event.keyCode == 16 || event.keyCode == 17|| event.keyCode == 18) return false;
			if (event.keyCode == 8) return true;
			if (event.keyCode == 13) return false;
			if (event.keyCode >= 65 && event.keyCode <= 90) return true;
			if (event.keyCode >= 48 && event.keyCode <= 58) return true;
		} else {
			return true;
		}
		return false;
	};
// If you plan on doing anything outside of North America, then you'd better encode the things you pass back and forth
// the escape() method in Javascript is deprecated -- should use encodeURIComponent if available
function encode( uri ) {
    if (encodeURIComponent) {
        return encodeURIComponent(uri);
    }

    if (escape) {
        return escape(uri);
    }
}

function decode( uri ) {
    uri = uri.replace(/\+/g, ' ');

    if (decodeURIComponent) {
        return decodeURIComponent(uri);
    }

    if (unescape) {
        return unescape(uri);
    }

    return uri;
}

// log information to the status area textfield
function logger( text, clear ) {
    if (_logger) {
        if (!_status_area) {
            _status_area = document.getElementById("status_area");
        }

        if (_status_area) {
            if (clear) {
                _status_area.value = "";
            }

            var old = _status_area.value;
            _status_area.value = text + ((old) ? "\r\n" : "") + old;
        }
    }
}


/*
 * AJAXRequest: An encapsulated AJAX request. To run, call
 * new AJAXRequest( method, url, async, process, data )
 *
 */

function executeReturn( AJAX ) {
    if (AJAX.readyState == 4) {
        if (AJAX.status == 200) {
            logger('AJAXRequest is complete: ' + AJAX.readyState + "/" + AJAX.status + "/" + AJAX.statusText);
	    if ( AJAX.responseText ) {
		    logger(AJAX.responseText);
		    logger("-----------------------------------------------------------");
		    eval(AJAX.responseText);
	    }
	}
    }
}

function AJAXRequest( method, url, data, process, async, dosend) {
    // self = this; creates a pointer to the current function
    // the pointer will be used to create a "closure". A closure
    // allows a subordinate function to contain an object reference to the
    // calling function. We can't just use "this" because in our anonymous
    // function later, "this" will refer to the object that calls the function 
    // during runtime, not the AJAXRequest function that is declaring the function
    // clear as mud, right?
    // Java this ain't
    
    var self = this;

    // check the dom to see if this is IE or not
    if (window.XMLHttpRequest) {
	// Not IE
        self.AJAX = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
	// Hello IE!
        // Instantiate the latest MS ActiveX Objects
        if (_ms_XMLHttpRequest_ActiveX) {
            self.AJAX = new ActiveXObject(_ms_XMLHttpRequest_ActiveX);
        } else {
	    // loops through the various versions of XMLHTTP to ensure we're using the latest
	    var versions = ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
                        "Microsoft.XMLHTTP"];

            for (var i = 0; i < versions.length ; i++) {
                try {
		    // try to create the object
		    // if it doesn't work, we'll try again
		    // if it does work, we'll save a reference to the proper one to speed up future instantiations
                    self.AJAX = new ActiveXObject(versions[i]);

                    if (self.AJAX) {
                        _ms_XMLHttpRequest_ActiveX = versions[i];
                        break;
                    }
                }
                catch (objException) {
                // trap; try next one
                } ;
            }

            ;
        }
    }
    
    // if no callback process is specified, then assing a default which executes the code returned by the server
    if (typeof process == 'undefined' || process == null) {
        process = executeReturn;
    }

    self.process = process;

    // create an anonymous function to log state changes
    self.AJAX.onreadystatechange = function( ) {
        //logger("AJAXRequest Handler: State =  " + self.AJAX.readyState);
        self.process(self.AJAX);
    }

    // if no method specified, then default to POST
    if (!method) {
        method = "POST";
    }

    method = method.toUpperCase();

    if (typeof async == 'undefined' || async == null) {
        async = true;
    }

    logger("----------------------------------------------------------------------");
    logger("AJAX Request: " + ((async) ? "Async" : "Sync") + " " + method + ": URL: " + url + ", Data: " + data);

    self.AJAX.open(method, url, async);

    if (method == "POST") {
        self.AJAX.setRequestHeader("Connection", "close");
        self.AJAX.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        self.AJAX.setRequestHeader("Method", "POST " + url + "HTTP/1.1");
    }

    // if dosend is true or undefined, send the request
    // only fails is dosend is false
    // you'd do this to set special request headers
    if ( dosend || typeof dosend == 'undefined' ) {
	    if ( !data ) data=""; 
	    self.AJAX.send(data);
    }
    return self.AJAX;
}

function simpleAjax(url, onSuccess) {
    return new AJAXRequest("POST",  url, null, 
				function(AJAX) {
					if (AJAX.readyState == 4) {
						if (AJAX.status == 200) {
							
							onSuccess(AJAX.responseXML.documentElement);
						}
					}
				}
				,true);
}
function simpleAjaxCall(url, onSuccess) {
    return new AJAXRequest("POST",  url, null, 
				function(AJAX) {
					if (AJAX.readyState == 4) {
						if (AJAX.status == 200) {
							eval(onSuccess);
						}
					}
				}
				,true);
}


var bSaf = (navigator.userAgent.indexOf('Safari') != -1);
var bOpera = (navigator.userAgent.indexOf('Opera') != -1);
var bMoz = (navigator.appName == 'Netscape');
function execJS(node) {
  var st = node.getElementsByTagName('SCRIPT');
  var strExec;
  for(var i=0;i<st.length; i++) {     
    if (bSaf) {
      strExec = st[i].innerHTML;
    }
    else if (bOpera) {
      strExec = st[i].text;
    }
    else if (bMoz) {
      strExec = st[i].textContent;
    }
    else {
      strExec = st[i].text;
    }
    try {
      eval(strExec.split("<!--").join("").split("-->").join(""));
    } catch(e) {
      alert(e);
    }
  }
}

function showBusy(x, y) {
	if (isNaN(x) && isNaN(y))
		x = y = 0;
	
	if (!$("loadingDiv")) {
		var div = document.createElement("div");
		div.setAttribute("id","loadingDiv");
		div.style.top = y + "px";
		div.style.left = x + "px";
		
		div.appendChild(document.createTextNode("Loading"));
		
		document.body.appendChild(div);
	}
	else {
		div.style.top = y + "px";
		div.style.left = x + "px";
	}
}

function hideBusy() {
	document.body.removeChild($('loadingDiv'));
}

function ajaxDivPopulate( url, divId) {
	document.getElementById(divId).innerHTML = '<img id="ajaxLoadingImg" style="margin:5px;" src="/images/html/common/images/icon_animated_busy.gif" width="16" height="16" align="absmiddle"/><span style="font-size:8pt;font-family:Verdana,Sans Serif;"> Loading...</span>';
    return new AJAXRequest("POST",  url, null, 
				function(AJAX) {
					if (AJAX.readyState == 4) {
						if (AJAX.status == 200) {
							var output = '';
							//output += '<textarea rows=10 cols=80>';
							output += AJAX.responseText;
							//output += '</textarea>'
							//output += AJAX.responseText;
							document.getElementById(divId).innerHTML = output;
							execJS(document.getElementById(divId));
						} else {
							document.getElementById(divId).innerHTML = 'ERROR - ' + AJAX.responseText;
						}
					} 
				}
				,true);
}

/*
Submit a form using dojo
*/
function submitForm(loadCallback, errorCallback, timeoutCallback, timeoutSeconds, formNode, synchronous) {
	var _synchronous = false;

	if (arguments[5] != undefined)
		_synchronous = synchronous;
		
	var kw = {
		url: formNode.action,
		load: loadCallback,
		error: errorCallback,
		timeoutSeconds: timeoutSeconds,
		timeout: timeoutCallback,
		formNode: formNode,
		sync: _synchronous
	};

	dojo.io.bind(kw);
}

function submitAdminLoginForm() {
	submitForm(adminLoginLoad, adminLoginError, adminLoginTimeout, 30, $('adminLoginForm'));
}

function adminLoginLoad(data,data2,data3,data4) {
	if (data2!=null) {

		if (data2.lastIndexOf("np")>=0) {
			document.location.href='/cust.newAccount.pml';
			return false;
		}
	
		if (data2.lastIndexOf("ua")>=0) {
			document.location.href='/cust.newAccount.pml';
			return false;
		}
	
		if (data2.lastIndexOf("ok")>=0) {
			siteLoginLoad();
			return false;
		}
	
	} else {
		document.location.reload();
	}
}
 
function submitSiteLoginForm() {
	submitForm(siteLoginLoad, adminLoginError, adminLoginTimeout, 30, $('adminLoginForm'));
}

function siteLoginLoad(data,data2,data3,data4) {
	try {
		var requestHost = $('requestHost').innerHTML;
		if (requestHost!=null && requestHost.indexOf('admin')>=0) {
			document.location.href = '/';
			return;
		}
		document.location.href = '/cust.SiteAdmin.pml?tab=1';
	} catch (e) {
		document.location.href = '/cust.SiteAdmin.pml?tab=1';
	}
}

function adminLoginError(arg1, data, arg3) {
	if (data.message.indexOf('Internal Server Error') >= 0) 
		alert("Your Username or Password was Incorrect.\nPlease try entering your information again.");
	else
		alert("An error occurred while attempting to login.\n\nError: " + data.message.replace(/XMLHttpTransport Error: [0-9]{3} /ig,"").replace(/\+/ig, " "));
}

function adminLoginTimeout(data) {
	alert("No response received from server. Please try again.");
}

function changeImages(id, img) {
	document.getElementById(id).src = img;
}

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

// Pass nothing or seperate lists of all inputs.
function validateRequiredFields() {
	var inputs;
	if (arguments.length == 0)
		inputs = combineGets(getByTag("input"), getByTag("select"));
	else
		inputs = combineGets(arguments[0],arguments[1]);
		
	var errorMessages = "";
	var div = document.createElement("div");
	var i = 0;
	
	try {
		var foundError = false;
		for (i=0;i<inputs.length;i++) {
			if (hasClassValue(inputs[i], "required") && inputs[i].value == '' && inputs[i].value != 'on') {
				foundError=true;
				
				if (inputs[i].parentNode.lastChild.nodeType == 3 || getClassValue(inputs[i].parentNode.lastChild) != "info alert") {
					var p = document.createElement("p");
					p.appendChild(
						document.createTextNode(getLabel(inputs[i].id).replace(/\:/,"") + " is a required field.")
					);

					appendClass(p, "info alert");

					p.style.position="relative";
					p.style.marginLeft = "105px";

					inputs[i].parentNode.appendChild(p);
				}
			}
		}

		if (foundError)
			return false;

/*		if (div.childNodes.length > 0) {
			var d;
			if (!dojo.widget.byId('pmlMessageDialog'))
				d = dojo.widget.createWidget("Dialog", {id:"pmlMessageDialog"}, $('pmlMessageDialog'));	
			else
				d = dojo.widget.byId('pmlMessageDialog');
	
			removeAllChildren($('pmlMessageDialogContent'));
			$('pmlMessageDialogContent').appendChild(div);	
			d.show();

			toggleContinueButton();			
			return false;
		}
*/
		return true;
	}
	catch(e) {
		alert("An unexpected error has occurred: " + e);
		return false;
	}
}

function insertAfter(node, referenceNode) {
	referenceNode.parentNode.insertBefore(node, referenceNode.nextSibling);
}

// Combine Node Lists
function combineGets() {
  var o=[], a=arguments;
  for(var i=0,l1=a.length;i<l1;i++) {
    for(var k=0,l2=a[i].length;k<l2;k++)
      o.push(a[i][k]);
  }
  return o;
}

// Get Elements By Tag Name
function getByTag() {
	return document.getElementsByTagName(arguments[0]);
}

function getLabel(forValue) {
	var labels = document.getElementsByTagName("label");
	for (var i=0;i<labels.length;i++) {
		if (labels[i].attributes["for"].value == forValue) {
			if (labels[i].childNodes[0]) {
				return labels[i].childNodes[0].nodeValue;
			}
			else {
				return labels[i].nodeValue;
			}
		}
	}
}

function _genericLoad(data,data2,data3) {
	var errorMsg = "";
	
	if (data2.match(/<div id=\"pmlmessages\">.+?<\/div>/ig)) {

		var d;
		if (!dojo.widget.byId('pmlMessageDialog')) {
			d = dojo.widget.createWidget("Dialog", {id:"pmlMessageDialog"}, $('pmlMessageDialog'));
			document.body.appendChild(d.domNode);
		}	
		else {
			d = dojo.widget.byId('pmlMessageDialog');
		}

		removeAllChildren($('pmlMessageDialogContent'));

		errorMsg = data2.match(/<div id=\"pmlmessages\">.+?<\/div>/ig)[0];

		if ($('pmlMessageDialogContent')) {
			$('pmlMessageDialogContent').innerHTML = errorMsg;
			$('pmlMessageDialogContent').innerHTML += "<br/><br/><input type='button' class='buttonStyle' value='OK' onclick='dojo.widget.byId(\"pmlMessageDialog\").hide();'/>";
		}
		else {
			var div = document.createElement('div');
			div.id = 'pmlMessageDialogContent';
			
			div.innerHTML = errorMsg;
			div.innerHTML += "<br/><br/><input type='button' class='buttonStyle' value='OK' onclick='dojo.widget.byId(\"pmlMessageDialog\").hide();'/>";
			d.domNode.appendChild(div);
		}

		

		d.show();
		return false;
	}
	return true;
}

function toggleRequired() {
	var obj;
	if (arguments[0].target)
		obj = arguments[0].target;
	else
		obj = arguments[0];
		
	if (obj.value != '') {
		if (getClassValue(obj))
	 		removeClass(obj,"reqAlert");
	 }
	else {
	 	appendClass(obj, "reqAlert");
	}
}

function updateRequiredStatus() {
	var elements = combineGets(getByTag("input"), getByTag("select"));

	for (var i=0;i<elements.length;i++) {
		if (hasClassValue(elements[i], "required")) {
			if (elements[i].value == "") {
				if (!hasClassValue(elements[i], "reqAlert"))
					appendClass(elements[i], "reqAlert");
			}
			else {
				if (hasClassValue(elements[i], "reqAlert"))
					removeClass(elements[i], "reqAlert");
			}
		}
	}
}

/* IE 6 safe class manipulation....... */
function getClassValue(obj) {
	return (obj.getAttribute("class")) ? obj.getAttribute("class"): obj.getAttribute("classname");
}

function hasClassValue(obj, classValue) {
	var classIdentifier = (obj.getAttribute("class")) ? "class" : "classname";
	if (obj.getAttribute(classIdentifier)) {
		var r = new RegExp("" + classValue + "\\b", "i");
		return (getClassValue(obj).search(r) > -1) ? true : false;
	}
	return false;
}

function appendClass(obj, classValue) {
	var classIdentifier = (obj.getAttribute("class")) ? "class" : "class";
	if (obj.getAttribute(classIdentifier))
	 	obj.setAttribute(classIdentifier, obj.getAttribute(classIdentifier) + " " + classValue);
	else
	 	obj.setAttribute(classIdentifier, classValue);
}

function removeClass(obj, classToRemove) {
	var classIdentifier = (obj.getAttribute("class")) ? "class" : "classname";
	if (obj.getAttribute(classIdentifier)) {
		var r = new RegExp("" + classToRemove + "", "i");
		var newValue = getClassValue(obj).replace(r,"");
		if (obj.className)	
	 		obj.className = newValue;
	 	else
	 		obj.setAttribute("class",newValue);
	}
}

function removeAllChildren(parent) {
	if (parent) {
		while (parent.childNodes.length > 0)
			parent.removeChild(parent.childNodes[0]);
	}
}

function cookieUpForm(formNode) {
	var cookieValue = "\{";
	
	for (var i=0;i<formNode.length;i++) {
		if (formNode[i].type=="button" || formNode[i].type=="submit")
			continue;
		
		if (formNode[i].name == "" || formNode[i].name == undefined)
			continue;
		
		if (formNode[i].type=="radio" && !formNode[i].checked)
			continue;

		cookieValue += formNode[i].name + ":\"" + formNode[i].value + "\",";

		// If the form has an input name with 'name' in it, put the value of that field
		// in a dropdown.
		if (formNode[i].name.indexOf('name') >= 0 && $(formNode[i].name + "Temporary")) {
			$(formNode[i].name + "Temporary").options[$(formNode[i].name + "Temporary").options.length] = new Option(formNode[i].value, formNode[i].value, true);
		}
	}
	
	cookieValue = cookieValue.substring(0,cookieValue.length-1) + "\}";

	if (getCookie(formNode.id) != null)
		setCookie(formNode.id, getCookie(formNode.id) + ',' + cookieValue, null, null, null, null);
	else
		setCookie(formNode.id, cookieValue, null, null, null, null);
}

function toggleHidden(imgNode, id) {
	if ($(id).style.display != "none") {
		$(id).style.display = "none";
		
		if (imgNode)
			imgNode.src = imageDir + "expand.gif";
	}
	else {
		$(id).style.display = "block";
		$(id).scrollTo();
		if (imgNode)
			imgNode.src = imageDir + "collapse.gif";
	}
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function clearPetFields() {
	$('petName').value = '';
	$('petType').value = '';
	$('petBreed').value = '';
	$('petFixed').checked=false;
	$('petWeight').value = '';
	dojo.widget.byId('petBirthdate').setValue('');
	
	var elements = getElementsByClass('info alert');
	for (var i=0;i<elements.length;i++) {
		elements[i].parentNode.removeChild(elements[i]);
	}
}

function createUpdatePetInit() {
	var o = $('petBday');
	if (o) {
		appendClass(o, 'required');
		appendClass(o, 'reqAlert');
	}

	dojo.event.kwConnect({
		type: "after", 
		srcObj: dojo.widget.byId('petInsertDialog'), 
		srcFunc: "show",
		targetFunc: "updateRequiredStatus"
	});

/*
	dojo.event.kwConnect({
		type: "after", 
		srcObj: dojo.widget.byId('petInsertDialog'), 
		srcFunc: "hide",
		targetFunc: "clearPetFields"
	});
*/

	dojo.event.kwConnect({
		type: "after", 
		srcObj: dojo.widget.byId('petBirthdate'), 
		srcFunc: "onValueChanged",
		targetFunc: "updateRequiredStatus"
	});
}

function buttonOnMouseUp(data) {
	Element.removeClassName(data.target, 'clicked');
}

function buttonOnMouseDown(data) {
	Element.addClassName(data.target, 'clicked');
}

function globalInit() {
	var inputs = document.getElementsByTagName('input');

	for (var i=0;i<inputs.length;i++) {
		if (inputs[i].type == 'button' || inputs[i].type == 'submit') {
			
			dojo.event.kwConnect({
				type: "after", 
				srcObj: inputs[i], 
				srcFunc: "onmousedown",
				targetFunc: "buttonOnMouseDown"
			});

			dojo.event.kwConnect({
				type: "after", 
				srcObj: inputs[i], 
				srcFunc: "onmouseup",
				targetFunc: "buttonOnMouseUp"
			});

			dojo.event.kwConnect({
				type: "after", 
				srcObj: inputs[i], 
				srcFunc: "onmouseout",
				targetFunc: "buttonOnMouseUp"
			});

		}
	}
	if (dojo && dojo.widget && dojo.widget.byId('petInsertDialog'))
		createUpdatePetInit();
}

dojo.addOnLoad(globalInit);	
