﻿// JScript File

	    function changeDivision(strDivisionIDX, strIsHorseEntry){
		    if (navigator.appName == "Microsoft Internet Explorer")
                {				
		        window.event.returnValue = false;
		        window.location.href="entry.aspx?SIM=" + strDivisionIDX + "&ISHRS=" + strIsHorseEntry ;
		        }
		    else
		        {
		        //e.preventDefault();
		        document.location.href = "entry.aspx?SIM=" + strDivisionIDX + "&ISHRS=" + strIsHorseEntry;
		        }
		    }
	    function changePerson(myobject, strPersonType) {
		    var strPersonAttributes = myobject.options[myobject.selectedIndex].value;
		    if (strPersonAttributes == "")
			    {
			    document.frmMain["txt" + strPersonType + "Name"].value = "";
			    document.frmMain["txt" + strPersonType + "Address"].value = "";
			    document.frmMain["txt" + strPersonType + "City"].value = "";
			    document.frmMain["txt" + strPersonType + "State"].value = "";
			    document.frmMain["txt" + strPersonType + "ZipCode"].value = "";
			    document.frmMain["txt" + strPersonType + "Relationship"].value = "";
			    document.frmMain["ddl" + strPersonType + "Association1"].value = "";
			    document.frmMain["txt" + strPersonType + "AssociationNumber1"].value = "";
			    document.frmMain["ddl" + strPersonType + "Association2"].value = "";
			    document.frmMain["txt" + strPersonType + "AssociationNumber2"].value = "";
			    document.frmMain["ddl" + strPersonType + "Association3"].value = "";
			    document.frmMain["txt" + strPersonType + "AssociationNumber3"].value = "";
			    }
		    else {
			    var aPersonAttributes = strPersonAttributes.split("||");
			    document.frmMain["txt" + strPersonType + "Name"].value = myobject.options[myobject.selectedIndex].text;
			    document.frmMain["txt" + strPersonType + "Address"].value = aPersonAttributes[0];
			    document.frmMain["txt" + strPersonType + "City"].value = aPersonAttributes[1];
			    document.frmMain["txt" + strPersonType + "State"].value = aPersonAttributes[2];
			    document.frmMain["txt" + strPersonType + "ZipCode"].value = aPersonAttributes[3];
			    document.frmMain["txt" + strPersonType + "Relationship"].value = aPersonAttributes[4];
			    document.frmMain["ddl" + strPersonType + "Association1"].value = aPersonAttributes[5];
			    document.frmMain["txt" + strPersonType + "AssociationNumber1"].value = aPersonAttributes[6];
			    document.frmMain["ddl" + strPersonType + "Association2"].value = aPersonAttributes[7];
			    document.frmMain["txt" + strPersonType + "AssociationNumber2"].value = aPersonAttributes[8];
			    document.frmMain["ddl" + strPersonType + "Association3"].value = aPersonAttributes[9];
			    document.frmMain["txt" + strPersonType + "AssociationNumber3"].value = aPersonAttributes[10];
			    return false;
			    }
		    }

	    function populateDefaults(){
	        var strDefaultString = document.frmMain["txtDefaultString"].value;
	        var aDefaultSet = strDefaultString.split("|FLDNAME|");
	        var aDefaultPair;
	        var fld;
	        var val;
	        var i = 2;
	        while (i <= aDefaultSet.length - 1){
		        aDefaultPair = aDefaultSet[i].split("|FLDVALUE|");
		        fld = aDefaultPair[0];
		        val = aDefaultPair[1];
		        if (fld == "ddlClass"){
			        val = val + "||";
			        document.frmMain[fld].value = val;
			        }
		        else if(fld == "rblSex") {
			        switch(val){
				        case "1":
					        fld = "0"
					        break;
				        case "2":
					        fld = "1"
					        break;
				        case "3":
					        fld = "2"
					        break;
				        case "4":
					        fld = "3"
					        break;
				        case "5":
					        fld = "0"
					        break;
				        case "6":
					        fld = "1"
					        break;
				        case "7":
					        fld = "2"
					        break;
			        }
			        document.frmMain["rblSex_" + fld].checked = true;
			        }
		        else if (String(fld).substring(0,3) == "chk") {
			        document.frmMain[fld].checked = true;
			        }
		        else {
			        document.frmMain[fld].value = val;
		        }
		        ++i;
		        }
        		
		        if ( document.getElementById('lblDuplicateBubble') && document.getElementById('lblDuplicateBubble').focus)
		        {
		        //lblDuplicateBubble.style.display = "none";
				        hideBubble(document.getElementById('tblDuplicate'));
		        }		
    	
	        }

	    var mytimer;
	    var count = 0;

	    function hideBubble(objBubbleToHide){
	        if (navigator.appName == "Microsoft Internet Explorer")
	            {
                document.getElementById(objBubbleToHide.id).filters[0].apply();
                document.getElementById(objBubbleToHide.id).style.visibility="hidden";	
                document.getElementById(objBubbleToHide.id).filters[0].play();
	            }
	        else
	            {
	            document.getElementById(objBubbleToHide.id).style.visibility="hidden";	
	            }
	        }
    	
	    function showBubbles(){
	            mytimer = window.setInterval( "runBubbles()", 400 );
	        }

	    function runBubbles() {
		    if ( document.getElementById('tblDuplicate') && document.getElementById('tblDuplicate').focus)
		    {
		    document.getElementById('tblDuplicate').filters[0].apply();
		    document.getElementById('tblDuplicate').style.visibility="visible";			
		    document.getElementById('tblDuplicate').filters[0].play();
		    }
		    count = count + 1	
		    if (count > 1){
			    if ( document.getElementById('tblDivisionNotes') && document.getElementById('tblDivisionNotes').focus){
			        document.getElementById('tblDivisionNotes').filters[0].apply();
			        document.getElementById('tblDivisionNotes').style.visibility="visible";			
			        document.getElementById('tblDivisionNotes').filters[0].play();
			        }	
			        window.clearTimeout(mytimer);
		        }		
	        }	

		    if ( document.getElementById('ddlClass_dropList') && document.getElementById('ddlClass_dropList').focus){
		        document.getElementById('ddlClass_dropList').style.left = "200px";			
		        }

        //Ajax for dynamic department/divisions
        var xmlHttp
               
        function changeDepartment(str){
        
            if ( document.getElementById('divFeedbackAlert') && document.getElementById('divFeedbackAlert').focus){
              document.getElementById('divFeedbackAlert').style.display = "none";              
            }
            if (str.length==0)
              { 
              //this is only used if they don't select something
              //document.getElementById("txtHint").innerHTML="";
              return;
              }
            xmlHttp=GetXmlHttpObject()
            if (xmlHttp==null)
              {
              alert ("Your browser does not support AJAX!");
              return;
              } 
            if(str=="-- Choose a Department --"){
                document.frmMain.ddlDivisions.options.length = 0;
                document.frmMain.ddlDivisions.options[0] = new Option("-- Choose a Division --","0");
                hideshowRowDivisions("hide");
                setDivision("-- Choose a Division --");
                }
            else{ //they selected a department so bind the division list
                //first check to see if the form is already layed out, if so then we need to reload the page
                hideshowRowDivisions("show");
                //document.getElementById('lblFeedback').innerHTML = "Now choose a Division for this entry";

                var url="getDivisions.aspx";
                //url=url+"?DEP="+str;
                str = str.replace('+', '%2B');
                url=url+"?DEP="+Url.encode(str);
                url=url+"&sid="+Math.random();
                xmlHttp.onreadystatechange=stateChanged;
                xmlHttp.open("GET",url,true);
                xmlHttp.send(null);

                if ( document.getElementById('btnAddToCart') || document.getElementById('btnUpdateEntry')){
                    //alert('the form is layed out');
                    setDivision("-- Choose a Division --");
                    }
                }
            } 

        function stateChanged(){ 
            if (xmlHttp.readyState==4){ 
                var aLine = xmlHttp.responseText.split("^");
                var i = 0;
                var strLine;
                var aItems;
                var strItem;
                document.frmMain.ddlDivisions.options.length = 0;
                if (aLine.length > 0){
                    document.frmMain.ddlDivisions.options[0] = new Option("-- Choose a Division --","0");
                    while (i <= aLine.length -2){
                      strLine = aLine[i];
                      aItems = strLine.split("|");
                      strItem = aItems[aItems.length-1];
                      document.frmMain.ddlDivisions.options[i+1] = new Option(strItem,strLine);
                      i+=1;
                      }
                    }
            }
         }

        function GetXmlHttpObject(){
            var xmlHttp=null;
            try
              {
              // Firefox, Opera 8.0+, Safari
              xmlHttp=new XMLHttpRequest();
              }
            catch (e)
              {
              // Internet Explorer
              try
                {
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                }
              catch (e)
                {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
              }
            return xmlHttp;
        }

        function setDivision(str){
            document.getElementById("txtDivisionString").value=str;
            document.frmMain.submit();
        }
        
        function initializeDropdowns(){
            //document.frmMain.ddlDivisions.disabled = false;
            hideshowRowDivisions("show");
            if ((document.getElementById('ddlDivisions').selectedIndex == 0) && (document.getElementById('ddlDepartments').selectedIndex == 0)){
                document.frmMain.ddlDivisions.options.length = 0;
                document.frmMain.ddlDivisions.options[0] = new Option("-- Choose a Division --","0");
                hideshowRowDivisions("hide");
                }
            else if((document.getElementById('ddlDivisions').selectedIndex == 0) && (document.getElementById('ddlDepartments').selectedIndex == 1)){
                changeDepartment("All Departments");
                }
        }
        
        function hideshowRowDivisions(strDoWhat){
            if (navigator.appName == "Microsoft Internet Explorer"){
                if(strDoWhat=="hide"){ //hide it
                    document.getElementById('rowDivisions').style.display="none";
                }
                else { //show it
                    document.getElementById('rowDivisions').style.display="block";
                }
            }    
            else {
                if(strDoWhat=="hide"){ //hide it
                    document.getElementById('rowDivisions').style.display="none";
                }
                else { //show it
                    document.getElementById('rowDivisions').style.display="table-row";
                }            
            }
        }
        

        var Url = {

            // public method for url encoding
            encode : function (string) {
                return escape(this._utf8_encode(string));
            },

            // public method for url decoding
            decode : function (string) {
                return this._utf8_decode(unescape(string));
            },

            // private method for UTF-8 encoding
            _utf8_encode : function (string) {
                string = string.replace(/\r\n/g,"\n");
                var utftext = "";

                for (var n = 0; n < string.length; n++) {

                    var c = string.charCodeAt(n);

                    if (c < 128) {
                        utftext += String.fromCharCode(c);
                    }
                    else if((c > 127) && (c < 2048)) {
                        utftext += String.fromCharCode((c >> 6) | 192);
                        utftext += String.fromCharCode((c & 63) | 128);
                    }
                    else {
                        utftext += String.fromCharCode((c >> 12) | 224);
                        utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                        utftext += String.fromCharCode((c & 63) | 128);
                    }

                }

                return utftext;
            },

            // private method for UTF-8 decoding
            _utf8_decode : function (utftext) {
                var string = "";
                var i = 0;
                var c = c1 = c2 = 0;

                while ( i < utftext.length ) {

                    c = utftext.charCodeAt(i);

                    if (c < 128) {
                        string += String.fromCharCode(c);
                        i++;
                    }
                    else if((c > 191) && (c < 224)) {
                        c2 = utftext.charCodeAt(i+1);
                        string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                        i += 2;
                    }
                    else {
                        c2 = utftext.charCodeAt(i+1);
                        c3 = utftext.charCodeAt(i+2);
                        string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                        i += 3;
                    }

                }

                return string;
            }

        }
    