﻿// Navigator Menu Javascript
//***************************
var isInitialized = false;
var beginTime = null;
var boxBlowing = false;
var whereToGo = null;
var stillOpen = null;
var lastOpen = null;
var openNext = null;
var blowUpBox = function(item, orientation, endWidth, endHeight, timelength)
{
    if(item.id){
    }
    else {item = document.getElementById(item);}
    var fixedWidth = null;
    var fixedHeight = null;
    var x = new Number();
    var y = new Number();
    var posArray = new Array();
    posArray = findPos(item.parentNode);
    if (orientation=='Horizontal')
    {
        if (item.parentNode.style.width != "")
        {fixedWidth = item.parentNode.style.width;}
        else{fixedWidth = item.parentNode.scrollWidth;}
        if (isNaN(fixedWidth))
        {
            fixedWidth = fixedWidth.substr(0, fixedWidth.length-2);
        }
        x = parseInt(posArray[0]) + parseInt(fixedWidth);
        y = parseInt(posArray[1]);
    }
    else if(orientation=='Vertical')
    {
        if (item.parentNode.style.height != "")
        {fixedHeight = item.parentNode.style.height;}
        else{fixedHeight = item.parentNode.scrollHeight;}
        
        if (isNaN(fixedHeight))
        {
            fixedHeight = fixedHeight.substr(0, fixedHeight.length-2);
        }
        x = parseInt(posArray[0]);
        y = parseInt(posArray[1]) + parseInt(fixedHeight);
    }
    if (stillOpen)
    {
        openNext = item.id+';'+orientation+';'+endWidth+';'+endHeight+';'+timelength;
        if (lastOpen != openNext)
        {
            var argArray = lastOpen.split(';');
            boxBlowing = true;
            item = document.getElementById(argArray[0]);
            endHeight = argArray[2];
            endWidth = argArray[3];
            stillOpen = false;
        }else{
            boxBlowing = false;
        }
    }
    if (!isInitialized)
    {
        if(item.style.height == endHeight +'px' && item.style.width == endWidth +'px'){   
            whereToGo = 'back'; 
        }else{
            whereToGo = 'forward';
            item.style.left = x + 'px';
            item.style.top = y + 'px';
            item.style.visibility = 'visible';
            item.style.display = 'block';
            item.style.overflow = 'hidden';
            stillOpen = true;
            lastOpen = item.id+';'+orientation+';'+endWidth+';'+endHeight+';'+timelength;
        }
        beginTime = new Date().getTime();
        item.style.position = 'absolute';
        isInitialized = true;
    }
    var elapsed=new Date().getTime()-beginTime;
    if (elapsed < timelength){
        var distancepercent = fixPosAndHeight(elapsed/timelength);
        var newHeight = (whereToGo=='forward')? distancepercent * parseInt(endHeight) : parseInt(endHeight)-(distancepercent * parseInt(endHeight));
        var newWidth = (whereToGo=='forward')? distancepercent * parseInt(endWidth) : parseInt(endWidth)-(distancepercent * parseInt(endWidth));
        item.style.height=newHeight + 'px';
        item.style.width=newWidth + 'px';
        var doMeAgain = 'blowUpBox("'+item.id+'", "'+orientation+'", '+endWidth+', '+endHeight+', '+timelength+')';
        setTimeout(doMeAgain, 10);
    }else{
        if (whereToGo=='forward')
        {
            item.style.height = endHeight+'px';
            item.style.width = endWidth+'px';
            isInitialized = false;
            stillOpen = true;
        }else{
            item.style.display = 'none';
            item.style.visibility = 'hidden';
            isInitialized = false;
            stillOpen = false;
            if(boxBlowing){
                boxBlowing = false;
                var next = openNext.split(';');
                var doMeNext = 'blowUpBox("'+next[0]+'",'+next[1]+','+next[2]+','+next[3]+','+next[4]+')';
                setTimeout(doMeNext, 500);
                openNext = null;
            }
        }
    }
}
function fixPosAndHeight(percent)
{
    return (1-Math.cos(percent*Math.PI)) / 2;
}
//*****
//Find Position
//*****
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
////*****
////Root Menu Expander
////*****
//var runtimer = null;
//function nodeToggle(item, direction, timelength)
//{
//    var DivID = item;
//    var menuItem = document.getElementById(item);
//    menuItem.style.overflow = "hidden";
//    menuItem.style.display = 'block';
//    menuItem.style.visibility = 'visible';
//    if (direction == 'Vertical')
//    {
//        var contentheight = menuItem.scrollHeight;
//        
//        if(menuItem.style.height == '0px' || menuItem.style.height == "")
//        {
//            slideDown(contentheight, DivID, timelength);
//        }
//        else
//        {
//            slideUp(contentheight, DivID, timelength);
//        }
//    }
//    else if (direction == 'Horizontal')
//    {
//        var contentwidth = menuItem.scrollWidth;
//        
//        if(menuItem.style.width == '0px' || menuItem.style.width == "")
//        {
//            SlideRight(contentwidth, DivID, timelength)
//        }
//        else
//        {
//            SlideLeft(contentwidth, DivID, timelength);
//        }
//    }
//}
//function nodeDown(item)
//{
//    var DivID = item;
//    var menuItem = document.getElementById(item);
//    menuItem.style.overflow = "hidden";
//    menuItem.style.display = 'block';
//    var contentheight = menuItem.scrollHeight;
//    var timelength = 2000;
//    
//    if (menuItem.parentNode.style.display == 'none')
//    {
//        menuItem.parentNode.style.display = 'block';
//    }
//    slideDown(contentheight, DivID, timelength)
//}
//function slideMenu(direction, startTime, item, timelength, pixelParameter)
//{
//    if (!item.id) menuItem = document.getElementById(item);
//    else menuItem = item;
//    var elapsed=new Date().getTime()-startTime;
//    
//    if(elapsed<timelength)
//    {
//        if (direction=="down" || direction=="up")
//        {
//            elapsed = new Date().getTime()-startTime;
//            var distancepercent=(direction=="down")? curveIncrement(elapsed/timelength) : 1-curveIncrement(elapsed/timelength);
//            var newHeight = distancepercent * pixelParameter + "px";
//            menuItem.style.height=newHeight;
//            menuItem.parentNode.parentNode.style.height = '';
//            var funcIt = "slideMenu('"+direction+"',"+startTime+",'"+item+"',"+timelength+","+pixelParameter+")";
//            runtimer = setTimeout(funcIt, 10);
//        }
//        else
//        {
//            elapsed = new Date().getTime()-startTime;
//            var distancepercent=(direction=="right")? curveIncrement(elapsed/timelength) : 1-curveIncrement(elapsed/timelength);
//            var newwidth = distancepercent * pixelParameter + "px";
//            menuItem.style.width=newwidth;
//            menuItem.parentNode.parentNode.style.width = '';
//            var funcIt = "slideMenu('"+direction+"',"+startTime+",'"+item+"',"+timelength+","+pixelParameter+")";
//            runtimer = setTimeout(funcIt, 10);
//        }
//    }
//    else
//    {
//        if (direction=="down"){menuItem.style.height = pixelParameter+"px";}
//        else if(direction=="up"){menuItem.style.height = 0+"px";menuItem.style.display='none';}
//        else if(direction=="right"){menuItem.style.width = pixelParameter+"px";}
//        else if(direction=="left"){menuItem.style.width = 0+"px";menuItem.style.display='none';}
//        runtimer = null;
//    }
//}
//function slideDown(contentHeight, item, timelength)
//{
//    if(item.id) var menuItem = item;
//    else var menuItem = document.getElementById(item);
//    var fixed = "";

//    if (isNaN(menuItem.style.height))
//    {
//        fixed = menuItem.style.height;
//        fixed = fixed.substr(0, fixed.length-2);
//    }
//    else {fixed = menuItem.style.height;}
//    if(runtimer==null)
//    {
//        if(fixed==0)
//        {
//            var startTime = new Date().getTime();
//            slideMenu('down', startTime, item, timelength, contentHeight);
//        }
//    }
//}
//function slideUp(contentHeight, item, timelength)
//{
//    if(item.id) var menuItem = item;
//    else var menuItem = document.getElementById(item);
//    var fixed = "";

//    if (isNaN(menuItem.style.height))
//    {
//        fixed = menuItem.style.height;
//        fixed = fixed.substr(0, fixed.length-2);
//    }
//    else {fixed = menuItem.style.height;}
//    if(runtimer==null)
//    {
//        if(contentHeight==fixed || fixed =="")
//        {
//            var startTime = new Date().getTime();
//            slideMenu('up', startTime, item, timelength, contentHeight);
//        }
//    }
//}
//function slideOut(item, direction, timelength)
//{
//    if(item.id) var menuItem = item;
//    else var menuItem = document.getElementById(item);
//    menuItem.style.display = 'block';
//    menuItem.style.position = 'absolute';
//    menuItem.style.overflow = 'hidden';
//    var fixed = "";
//    if (direction=='Horizontal')
//    {
//        var posArray = new Array();
//        posArray = findPos(menuItem.parentNode);
//        var fixParent = menuItem.parentNode.width;
//        if (isNaN(fixParent))
//        {
//            fixParent = fixParent.substr(0, fixParent.length-2);
//        }
//        menuItem.style.left = (parseInt(posArray[0]) + fixParent) + 'px';
//        menuItem.style.top = posArray[1] + 'px';
//        var contentwidth = menuItem.scrollWidth;
//        if (isNaN(menuItem.style.width))
//        {
//            fixed = menuItem.style.width;
//            fixed = fixed.substr(0, fixed.length-2);
//        }
//        else {fixed = menuItem.style.width;}
//        if(runtimer==null)
//        {
//            if(contentwidth==fixed || fixed =="")
//            {
//                var startTime = new Date().getTime();
//                slideMenu('right', startTime, item, timelength, contentwidth);
//            }
//        }
//        else
//        {
//            runtimer=null;
//            var FuncIt = new String();
//            var startTime = new Date().getTime();
//            FuncIt = "slideMenu('right',"+startTime+",'"+item+"',"+timelength+","+contentwidth+");";
//            runtimer = setTimeout(FuncIt,100);
//        }
//    }
//    else if(direction=='Vertical')
//    {
//        var posArray = new Array();
//        posArray = findPos(menuItem.parentNode);
//        var fixParent = menuItem.parentNode.height;
//        if (isNaN(fixParent))
//        {
//            fixParent = fixParent.substr(0, fixParent.length-2);
//        }
//        menuItem.style.top = (parseInt(posArray[1]) + fixParent) + 'px';
//        menuItem.style.left = posArray[0] + 'px';
//        var contentheight = menuItem.scrollHeight;
//        if (isNaN(menuItem.style.height))
//        {
//            fixed = menuItem.style.height;
//            fixed = fixed.substr(0, fixed.length-2);
//        }
//        else {fixed = menuItem.style.height;}
//        if(runtimer==null)
//        {
//            if(contentheight==fixed || fixed =="")
//            {
//                var startTime = new Date().getTime();
//                slideMenu('right', startTime, item, timelength, contentwidth);
//            }
//        }
//        else
//        {
//            runtimer=null;
//            var FuncIt = new String();
//            var startTime = new Date().getTime();
//            FuncIt = "slideMenu('right',"+startTime+",'"+item+"',"+timelength+","+contentwidth+");";
//            runtimer = setTimeout(FuncIt,100);
//        }
//    }
//}
//function slideIn(item, direction, timelength)
//{
//    if(item.id) var menuItem = item;
//    else var menuItem = document.getElementById(item);
//    var fixed = "";
//    if (direction=='Horizontal')
//    {
//        var contentwidth = menuItem.scrollWidth;
//        if (isNaN(menuItem.style.width))
//        {
//            fixed = menuItem.style.width;
//            fixed = fixed.substr(0, fixed.length-2);
//        }
//        else {fixed = menuItem.style.width;}
//        if(runtimer==null)
//        {
//            if(contentwidth==fixed || fixed =="")
//            {
//                var startTime = new Date().getTime();
//                slideMenu('left', startTime, item, timelength, contentwidth);
//            }
//        }
//        else
//        {
//            runtimer=null;
//            var FuncIt = new String();
//            FuncIt = "$("+item+").style.display='none'"
//            runtimer=setTimeout(FuncIt,400);
//        }
//    }
//    else if(direction=='Vertical')
//    {
//        var contentheight = menuItem.scrollHeight;
//        if (isNaN(menuItem.style.height))
//        {
//            fixed = menuItem.style.height;
//            fixed = fixed.substr(0, fixed.length-2);
//        }
//        else {fixed = menuItem.style.height;}
//        if(runtimer==null)
//        {
//            if(contentheight==fixed || fixed =="")
//            {
//                var startTime = new Date().getTime();
//                slideMenu('up', startTime, item, timelength, contentwidth);
//            }
//        }
//        else
//        {
//            runtimer=null;
//            var FuncIt = new String();
//            var startTime = new Date().getTime();
//            FuncIt = "slideMenu('right',"+startTime+",'"+item+"',"+timelength+","+contentwidth+");";
//            runtimer = setTimeout(FuncIt,100);
//        }
//    }
//}
//function curveIncrement(percent)
//{
//    return (1-Math.cos(percent*Math.PI)) / 2;
//}
//****
//Testing
//****
var lastItem = null;
var lastItemChildren = new Array();
var RollIt = {
     timeout : null,
     showPopup : function(item, direction, timelength){
        clearTimeout(this.timeout);
        item = $(item);
        if(item.style.position != 'absolute'){
            var posArray = new Array();
            var fixParent = item.parentNode.scrollHeight;
            if (isNaN(fixParent))
            {
            fixParent = fixParent.substr(0, fixParent.length-2);
            }
            posArray = findPos(item.parentNode);
            item.style.position = 'absolute';
            item.style.left = posArray[0]+'px';
            item.style.top = (parseInt(posArray[1]) + fixParent) + 'px';
        }
        Change(item.id);
        if(item.style.display == 'none'){
            if(direction=='Vertical'){
            hideOthers(item.id, timelength);
            new Effect.Appear(item.id, {duration:parseInt(timelength)/1000, fps:40});
            lastItem = item.id;
            lastItemChildren = item.childNodes;
            }
            else if(direction=='Horizontal'){
            hideOthers(item.id, timelength);
            new Effect.Appear(item.id, {duration:parseInt(timelength)/1000, fps:40});
            lastItem = item.id;
            lastItemChildren = item.childNodes;
            }
        }
    },     
    hidePopup : function(item, direction, timelength){         
        if($(item).style.display == 'none'){
                     clearTimeout(this.timeout);
        }
        else
        {
            if(direction=='Vertical'){
            this.timeout = setTimeout(function(){new Effect.Fade(item, {duration:parseInt(timelength)/1000, fps:40});}, 600);
            }
            else if(direction=='Horizontal'){
            this.timeout = setTimeout(function(){new Effect.Fade(item, {duration:parseInt(timelength)/1000, fps:40});}, 600);
            }
        }
    } 
} 
var RollOut = {
     timeout : null,
     showPopup : function(item, direction, timelength){
            clearTimeout(this.timeout);
            item = $(item);
            item.style.position = 'absolute';
            Change(item.id);
            if(item.style.display == 'none'){
                if(direction=='Vertical'){
                hideOthers(item.id, timelength);
                Effect.Appear(item.id, {duration:parseInt(timelength)/1000, fps:40});
                lastItem = item.id;
                lastItemChildren = item.childNodes;
                }
                else if(direction=='Horizontal'){
                hideOthers(item.id, timelength);
                Effect.Appear(item.id, {duration:parseInt(timelength)/1000, fps:40});
                lastItem = item.id;
                lastItemChildren = item.childNodes;
                }
            }
        },     
        hidePopup : function(item, direction, timelength){ 
        if($(item).style.display == 'none'){
                     clearTimeout(this.timeout);
        }
        else
        {
            if(direction=='Vertical'){
            this.timeout = setTimeout(function(){new Effect.Fade(item, {duration:parseInt(timelength)/1000, fps:40})}, 600);
            }
            else if(direction=='Horizontal'){
            this.timeout = setTimeout(function(){new Effect.Fade(item, {duration:parseInt(timelength)/1000, fps:40})}, 600);
            }
        }
    } 
}
function hideOthers(item, timelength){
    item = $(item);
    if (lastItem != null && lastItem != item){
        var chkArr = lastItem.split("&");
        var chkThis = item.id.split("&");
        var chkSibs = item.parentNode.childNodes;
        if (isNaN(chkThis[1])){
        if (isNaN(chkArr[1])){
            if($(lastItem).style.display != 'none'){
            Effect.Fade(lastItem, {duration:parseInt(timelength)/1000, fps:40});
        }else{
            for (var i=0;i<chkSibs.length;i++){
                if(item.id == chkSibs[i].id){
                    return;
        }}}
        }else{
            for (var i=0;i<chkSibs.length;i++){
                if(item.id == chkSibs[i].id){
                    Effect.Fade(lastItem, {duration:parseInt(timelength)/1000, fps:40});
    }}}}}
}
var iStart = 4
function Change(item) {
	iStart++
  $(item).style.zIndex = iStart;
}
//********
//Add rows to a table
//********
function addRow(table)
{
    var tbl = document.getElementById(table);
    var hid = document.getElementById('hidNoOfHorses');
    var lastRow = tbl.rows.length;
    // if there's no header row in the table, then iteration = lastRow + 1
    hid.value = lastRow-1;
    var iteration = lastRow;
    var row = tbl.insertRow(lastRow);

    var cel1 = row.insertCell(0);
    var el1 = document.createElement("input");
    el1.type = 'text';
    el1.id = 'txtHName' + iteration;
    el1.name = 'txtHName' + iteration;
    el1.className = 'txtBox';
    el1.style.width = '90px';
    cel1.appendChild(el1);
    
    var cel2 = row.insertCell(1);
    var el2 = document.createElement("input");
    el2.type = 'text';
    el2.id = 'txtHColor' + iteration;
    el2.name = 'txtHColor' + iteration;
    el2.className = 'txtBox';
    el2.style.width = '65px';
    cel2.appendChild(el2);
    
    var cel3 = row.insertCell(2);
    var el3 = document.createElement("select");
    el3.id = 'ddlHSex' + iteration;
    el3.name = 'ddlHSex' + iteration;
    el3.options[0] = new Option('Select...', 'NULL');
    el3.options[1] = new Option('M', 'M');
    el3.options[2] = new Option('F', 'F');
    cel3.appendChild(el3);
    
    var cel4 = row.insertCell(3);
    var el4 = document.createElement("input");
    el4.type = 'text';
    el4.id = 'txtHAge' + iteration;
    el4.name = 'txtHAge' + iteration;
    el4.className = 'txtBox';
    el4.style.width = '20px';
    cel4.appendChild(el4);
    
    var cel5 = row.insertCell(4);
    var el5 = document.createElement("input");
    el5.type = 'text';
    el5.id = 'txtHSire' + iteration;
    el5.name = 'txtHSire' + iteration;
    el5.className = 'txtBox';
    el5.style.width = '90px';
    cel5.appendChild(el5);
    
    var cel6 = row.insertCell(5);
    var el6 = document.createElement("input");
    el6.type = 'text';
    el6.id = 'txtHDam' + iteration;
    el6.name = 'txtHDam' + iteration;
    el6.className = 'txtBox';
    el6.style.width = '90px';
    cel6.appendChild(el6);
    
    var cel7 = row.insertCell(6);
    var el7 = document.createElement("input");
    el7.type = 'text';
    el7.id = 'txtHBreeder' + iteration;
    el7.name = 'txtHBreeder' + iteration;
    el7.className = 'txtBox';
    el7.style.width = '90px';
    cel7.appendChild(el7);
    
    var cel8 = row.insertCell(7);
    var el8 = new String();
    el8 = "<SELECT id=\"ddlState" + iteration + "\" name=\"ddlState" + iteration + "\"> <OPTION value=NULL selected>Select...</OPTION> <OPTION value=AK>Alaska</OPTION> <OPTION value=AL>Alabama</OPTION> <OPTION value=AR>Arkansas</OPTION> <OPTION value=AZ>Arizona</OPTION> <OPTION value=CA>California</OPTION> <OPTION value=CO>Colorado</OPTION> <OPTION value=CT>Connecticut</OPTION> <OPTION value=DC>Dist. of Columbia</OPTION> <OPTION value=DE>Delaware</OPTION> <OPTION value=FL>Florida</OPTION> <OPTION value=GA>Georgia</OPTION> <OPTION value=HI>Hawaii</OPTION> <OPTION value=IA>Iowa</OPTION> <OPTION value=ID>Idaho</OPTION> <OPTION value=IL>Illinois</OPTION> <OPTION value=IN>Indiana</OPTION> <OPTION value=KS>Kansas</OPTION> <OPTION value=KY>Kentucky</OPTION> <OPTION value=LA>Louisiana</OPTION> <OPTION value=MA>Massachusetts</OPTION> <OPTION value=MD>Maryland</OPTION> <OPTION value=ME>Maine</OPTION> <OPTION value=MI>Michigan</OPTION> <OPTION value=MN>Minnesota</OPTION> <OPTION value=MO>Missouri</OPTION> <OPTION value=MS>Mississippi</OPTION> <OPTION value=MT>Montana</OPTION> <OPTION value=NC>North Carolina</OPTION> <OPTION value=ND>North Dakota</OPTION> <OPTION value=NE>Nebraska</OPTION> <OPTION value=NH>New Hampshire</OPTION> <OPTION value=NJ>New Jersey</OPTION> <OPTION value=NM>New Mexico</OPTION> <OPTION value=NV>Nevada</OPTION> <OPTION value=NY>New York</OPTION> <OPTION value=OH>Ohio</OPTION> <OPTION value=OK>Oklahoma</OPTION> <OPTION value=OR>Oregon</OPTION> <OPTION value=PA>Pennsylvania</OPTION> <OPTION value=RI>Rhode Island</OPTION> <OPTION value=SC>South Carolina</OPTION> <OPTION value=SD>South Dakota</OPTION> <OPTION value=TN>Tennessee</OPTION> <OPTION value=TX>Texas</OPTION> <OPTION value=UT>Utah</OPTION> <OPTION value=VA>Virginia</OPTION> <OPTION value=VT>Vermont</OPTION> <OPTION value=WA>Washington</OPTION> <OPTION value=WI>Wisconsin</OPTION> <OPTION value=WV>West Virginia</OPTION> <OPTION value=WY>Wyoming</OPTION></SELECT>"
    cel8.innerHTML = el8;
    
    var divBodyStyle = document.getElementById('divBody').style
    
    divBodyStyle.height = parseInt(fixIt(divBodyStyle.height)) + parseInt(30) + 'px';
}
function fixIt(str)
{
    if(isNaN(str)){
        str = str.substr(0, str.length-2);
    }
    return str;
}
//*****
//Check for blank fields
//*****
function checkRow()
{
    var tbl = document.getElementById('tblHorse');
    var willReturn = false;
    var txtArray = "";
    var txtChkMaster = 0;
    var total = 0;
    for (var i=1;i<tbl.rows.length;i++){
        var row = tbl.rows[i];
        total = total + row.cells.length
        var txtChk = 0;
        for (var x=0;x<row.cells.length;x++){
            var children = row.cells[x].childNodes;
            for (var c=0;c<children.length;c++){
                if(children[c].type == 'text'){
                    if(children[c].value==null||children[c].value==''){
                        children[c].style.backgroundColor='#ffcccc';
                        var txtName = children[c].id.replace('txtH', '').replace('[0-9]', '');
                        txtArray += txtName + ';';
                    }else{txtChk = parseInt(txtChk) + 1;}
                }else if(children[c].tagName == 'SELECT'){
                    if(children[c].selectedIndex == 0){
                        children[c].style.backgroundColor='#ffcccc';
                        var txtName = children[c].id.replace('ddl', '').replace('H', '').replace('[0-9]', '');
                        txtArray += txtName + ';';
                    }else{
                        children[c].disabled=false;
                        txtChk = parseInt(txtChk) + 1;
                    }
                }
            }
        }
        if (txtChk == 0){
            for(var q=total;q>(total-(row.cells.length+1));q--)
            {
                txtArray = txtArray.substr(0, txtArray.lastIndexOf(';'));
            }
            total = total - row.cells.length;
            delElem(tbl.rows[i]);
        }else{txtChkMaster = parseInt(txtChkMaster) + parseInt(txtChk);}
    }
    if(txtChkMaster == total){willReturn=true;}
    else{
        var arr = new Array();
        var alMess = 'You must supply us information for the following field(s):\n ';
        arr = txtArray.split(';');
        for(var i=0;i<arr.length-1;i++){
            alMess += '\n' + arr[i].toString();
        }
        alert(alMess);
        willReturn = false;
    }
    var noOfItems = document.getElementById('hidNoOfHorses');
    noOfItems.value = tbl.rows.length-1;
    return willReturn;
}
function delElem(elemToDel){
if(!elemToDel)return;
elemToDel.parentNode.removeChild(elemToDel);
}
//*****
//Sets total cost for items
//*****
var cost = 0;
function setCost(num){
    var amount = document.getElementById('ppAmount').value;
    if(isNaN(amount)||amount==0){
        amount = 1;}
    else{amount = num;
}}   
function detCost()
{
    var now = new Date();
    var changeDate = new Date();
    changeDate.setFullYear(2008, 0, 19);
    cost = document.getElementById('ppCost').value;
    if (changeDate < now){
        cost = 6000;
    }
}
//*****
//Close editable row, move to next
//*****
function closeRow(){
    var tbl = document.getElementById('tblHorse');
    var lastRow = tbl.rows.length-1;
    var row = tbl.rows[lastRow]
    var willReturn = false;
    var txtArray = "";
    var txtChk = 0;
    for (var i=0;i<row.cells.length;i++){
        var children= row.cells[i].childNodes;
        for(var c=0;c<children.length;c++){
            if(children[c].type == 'text'){
                if(children[c].value!=null&&children[c].value!=''){
                    children[c].readOnly = true;
                    txtChk = txtChk + 1;
                }else{
                    children[c].style.backgroundColor='#ffcccc';
                    var txtName = children[c].id.replace('txtH', '').replace('[0-9]', '');
                    txtArray += txtName + ';';
                }
            }else if(children[c].tagName == 'SELECT'){
                if(children[c].selectedIndex != 0){
                    children[c].disabled = true;
                    txtChk = txtChk + 1;
                }else{
                    children[c].style.backgroundColor='#ffcccc';
                    var txtName = children[c].id.replace('ddl', '').replace('H', '').replace('[0-9]', '');
                    txtArray += txtName + ';';
                }
            }
        }
    }
    if(txtChk = row.cells.length-1){willReturn=true;}
    if(willReturn){
        addRow('tblHorse');
    }else{
        var arr = new Array();
        var alMess = 'You must supply us information for the ';
        arr = txtArray.split(';');
        for(var i=0;i<arr.length-1;i++){
            alMess += '<br/>' + arr[i].toString();
        }
        alMess += '<br/>field(s).';
        alert(alMess);
        return false;
    }
}
//***
//Add value for recreated controls
//***
function addValues(rowNumber, values){
    var valArray = values.split(';');
    var tbl = document.getElementById('tblHorse');
    var c1 = document.getElementById('txtHName'+rowNumber);
    c1.value = valArray[0];
    var c2 = document.getElementById('txtHColor'+rowNumber);
    c2.value = valArray[1];
    var c3 = document.getElementById('ddlHSex'+rowNumber);
    setDDL(valArray[2], c3);
    var c4 = document.getElementById('txtHAge'+rowNumber);
    c4.value = valArray[3];
    var c5 = document.getElementById('txtHSire'+rowNumber);
    c5.value = valArray[4];
    var c6 = document.getElementById('txtHDam'+rowNumber);
    c6.value = valArray[5];
    var c7 = document.getElementById('txtHBreeder'+rowNumber);
    c7.value = valArray[6];
    var c8 = document.getElementById('ddlState'+rowNumber);
    setDDL(valArray[7], c8);
}
function setDDL(val, ddl){
    for (var i=0;i<ddl.options.length-1;i++){
        var ddlVal = ddl.options[i].outerText;
        if (val == ddlVal){
            ddl.selectedIndex = i
            break;
}}}
function fixHeight(id){
    var Item = document.getElementById(id);
    var Item2 = document.getElementById('repImages');
    Item.style.height = (parseInt(Item.scrollHeight) + parseInt(Item2.scrollHeight) + 200) + 'px';
}

function fixHeight2(id){
    var Item = document.getElementById(id);
    var Item2 = document.getElementById('divList');
    Item.style.height = (parseInt(Item.scrollHeight) + parseInt(Item2.scrollHeight) + 20) + 'px';
}