//*****************************************************************************
//** function confirmDelete( pii_delrecordID, pii_currentrecordID )
//** function buildPrettyBox( pii_boxType, pci_boxWidth, pci_boxTitle, pci_boxBody, pci_boxFooter )
//** function checkminiEmailForm()
//** function getXYPosition(e) {

//** function scrollSmoothly( pci_linkName, pci_offsetLeft, pci_offsetTop, poi_duration, poi_steps ) {
//** function findPos( poi_object ) {


//** function openPicker( pci_pickerType, pci_fieldToReturnPickTo, pci_fieldCurrentValue, pci_initialDirectory, pci_pickerParameters ) {
//** function openNewModalPage( pci_pageNameToDisplay, pci_pageTitle )
//** function openPhotoboard( pci_initialDirectory, pci_initialPicture ) {
//** function waitForPictureFrameToLoad(pci_imageName){
//** function createCookie(name,value,days) {
//** function readCookie(name) {
//** function eraseCookie(name) {
//** function isBrowserIE(){
//** function preloadMenuImages()
//** function preloadImages()


//** function formatCurrency(num) {

//** function getFormFieldByName(pci_formName, pci_formFieldName, pci_formFieldRow ) {
//** function setFormFieldByName(pci_formName, pci_formFieldName, pci_formFieldNewValue, pci_formFieldRow ) {

//** function toggleDivisionVisibility( ppi_ptrControl, pci_divName )
//** function changeObjVis(poi_objectId, pci_newVisibility) {
//** function getObject(pci_ObjectName) {
//** function xxgetObject(poi_objID)
//** function getStyleObject(poi_objectId) {
//** function hideObject(poi_objID)
//** function showObject(poi_objID)

//** function findString(pci_String) {
//** function trimAll(pci_String)
//** function trimLeft(pci_String)
//** function trimRight(pci_String)
//** function xreplace(pci_incomingString, pci_lookForString, pci_replaceWithString)

//** function getQueryVariable( pci_stringToSearch, pci_namedValuePairToFind ) {
//** function validateFormEdits( pii_formToEdit ) {


//*****************************************************************************

//*****************************************************************************
//** GLOBAL VARIABLES
//*****************************************************************************
//* Define google maps starting address
var gc_googleStartAddress = "saddr=3301+Glen+Carlyn+Road,+Falls+Church,+VA+22044&om=1&ll=38.856596,-77.139612&spn=0.026601,0.11158&z=14&layer=c&cbll=38.856596,-77.139612&panoid=nTgPzpDtijh7NrFrE-jtew&cbp=11,70.39999999999989,,0,5";
var gptr_winPicker

//*****************************************************************************
//** FUNCTION: verify that the user really wants to delete the listing. This confirm is primarily for the index.asp application.
//*****************************************************************************
//** pii_delrecordID     : The record ID of the page to be deleted
//** pii_currentrecordID : The record ID of the page to return to once the record has been deleted
//*****************************************************************************
function confirmDelete( pii_delrecordID, pii_currentrecordID )
{
	    if( confirm( "You are about to delete this record permanently.\n\nClick 'OK' to delete or 'Cancel' to keep." ))
			document.location='?action=delrecord&delid=' + pii_delrecordID + '&id=' + pii_currentrecordID;
}


//*****************************************************************************
//** FUNCTION: build a Pretty box to display data in
//*****************************************************************************
//** pii_boxType     : The type of box to display, from 1-9
//** pci_boxWidth    : The width of the box to display
//** pci_boxTitle    : The title to display at the top of the message
//** pci_boxBody     : The body of the message to display in the box
//** pci_boxFooter   : The message to display at the bottom of the message
//*****************************************************************************
function buildPrettyBox( pii_boxType, pci_boxWidth, pci_boxTitle, pci_boxBody, pci_boxFooter )
{
var lc_msgBody
    lc_msgBody = ""

    lc_msgBody = lc_msgBody + " <div id='box" + pii_boxType + "' xstyle='position:absolute; xtop:150; xleft:200;width:" + pci_boxWidth + ";'>" + "\n"
    lc_msgBody = lc_msgBody + "    <table id=toptable cellspacing=0 cellpadding=0 border=0 width=" + pci_boxWidth + " >" + "\n"
    lc_msgBody = lc_msgBody + "        <tr>" + "\n"
    lc_msgBody = lc_msgBody + "            <td class=box" + pii_boxType + "btl1 ><img src='images/boxlayout/box" + pii_boxType + ".tl1.gif'></td><td class=box" + pii_boxType + "btm1></td><td class=box" + pii_boxType + "btr1><img src='images/boxlayout/box" + pii_boxType + ".tr1.gif' ></td><td></td>" + "\n"
    lc_msgBody = lc_msgBody + "        </tr>" + "\n"

    //*** If there is a title provided, display it.
    if (pci_boxTitle.length > 0 ) {
        lc_msgBody = lc_msgBody + "        <tr>" + "\n"
        lc_msgBody = lc_msgBody + "            <td class=box" + pii_boxType + "btl2 ><img src='images/icon.blank.gif' ></td>" + "\n"
        lc_msgBody = lc_msgBody + "            <td class=box" + pii_boxType + "btm2>" + "\n"
        lc_msgBody = lc_msgBody + "                <div style='position:relative;'>" + pci_boxTitle + "\n"
        lc_msgBody = lc_msgBody + "                    <div style='position:absolute; top:2; right:0; display:inline;float:right;'>" + "\n"
        lc_msgBody = lc_msgBody + "                        <a href='#' onclick='getElementById(\"toptable\").parentNode.id=(getElementById(\"toptable\").parentNode.id==\"box7\")?\"box1\":(\"box\"+(parseInt(getElementById(\"toptable\").parentNode.id.substr(3,1))+1));return false;' style='text-decoration:none;font-weight:bold;'>" + "\n"
        lc_msgBody = lc_msgBody + "                        <ximg src='images/icon.doc.delete2.gif' border=0>" + "\n"
        lc_msgBody = lc_msgBody + "                    </div>" + "\n"
        lc_msgBody = lc_msgBody + "                </div>" + "\n"
        lc_msgBody = lc_msgBody + "            </td>" + "\n"
        lc_msgBody = lc_msgBody + "            <td class=box" + pii_boxType + "btr2 valign=top>" + "\n"
        lc_msgBody = lc_msgBody + "                <img src='images/icon.blank.gif' >" + "\n"
        lc_msgBody = lc_msgBody + "            </td>" + "\n"
        lc_msgBody = lc_msgBody + "            <td></td>" + "\n"
        lc_msgBody = lc_msgBody + "        </tr>" + "\n"
    }
    lc_msgBody = lc_msgBody + "        <tr>" + "\n"
    lc_msgBody = lc_msgBody + "            <td class=box" + pii_boxType + "btl3 ><img src='images/icon.blank.gif' ></td><td class=box" + pii_boxType + "btm3></td><td class=box" + pii_boxType + "btr3><img src='images/icon.blank.gif'></td><td></td>" + "\n"
    lc_msgBody = lc_msgBody + "        </tr>" + "\n"
    lc_msgBody = lc_msgBody + "        <tr>" + "\n"
    lc_msgBody = lc_msgBody + "            <td class=box" + pii_boxType + "bl  ></td>" + "\n"
//*******************************************
//*******************************************
//*******************************************
    lc_msgBody = lc_msgBody + "            <td class=box" + pii_boxType + "bm  >" + "\n"
    lc_msgBody = lc_msgBody + pci_boxBody + "\n"
    lc_msgBody = lc_msgBody + "            </td>" + "\n"
//*******************************************
//*******************************************
//*******************************************
    lc_msgBody = lc_msgBody + "            <td class=box" + pii_boxType + "br ></td>" + "\n"
    lc_msgBody = lc_msgBody + "            <td class=box" + pii_boxType + "bsr></td>" + "\n"
    lc_msgBody = lc_msgBody + "        </tr>" + "\n"
    lc_msgBody = lc_msgBody + "        <tr>" + "\n"
    lc_msgBody = lc_msgBody + "            <td class=box" + pii_boxType + "bbl1 ><img src='images/icon.blank.gif' ></td><td class=box" + pii_boxType + "bbm1></td><td class=box" + pii_boxType + "bbr1 ><img src='images/icon.blank.gif' ></td><td class=box" + pii_boxType + "bsr1></td>" + "\n"

    lc_msgBody = lc_msgBody + "        </tr>" + "\n"
    lc_msgBody = lc_msgBody + "        <tr>" + "\n"
    lc_msgBody = lc_msgBody + "            <td class=box" + pii_boxType + "bbl2 ><img src='images/icon.blank.gif' ></td><td class=box" + pii_boxType + "bbm2>" + pci_boxFooter + "</td><td class=box" + pii_boxType + "bbr2 ><img src='images/icon.blank.gif' ></td><td class=box" + pii_boxType + "bsr2></td>" + "\n"

    lc_msgBody = lc_msgBody + "        </tr>" + "\n"
    lc_msgBody = lc_msgBody + "        <tr>" + "\n"
    lc_msgBody = lc_msgBody + "            <td class=box" + pii_boxType + "bbl3 ><img src='images/icon.blank.gif' ></td><td class=box" + pii_boxType + "bbm3></td><td class=box" + pii_boxType + "bbr3 ><img src='images/icon.blank.gif' ></td><td class=box" + pii_boxType + "bsr3></td>" + "\n"

    lc_msgBody = lc_msgBody + "        </tr>" + "\n"
    lc_msgBody = lc_msgBody + "        <tr>" + "\n"
    lc_msgBody = lc_msgBody + "            <td          ></td><td class=box" + pii_boxType + "bsb></td><td class=box" + pii_boxType + "bsb></td><td class=box" + pii_boxType + "bsbr></td>" + "\n"
    lc_msgBody = lc_msgBody + "        </tr>" + "\n"
    lc_msgBody = lc_msgBody + "    </table>" + "\n"
    lc_msgBody = lc_msgBody + "</div>" + "\n"


    return lc_msgBody

}

//*****************************************************************************
//** FUNCTION: Verify that the miniemail division form has valid email addresses in them
//*****************************************************************************
function checkminiEmailForm()
{
var lb_noErrorFound = false
var li_i, li_j, li_errorCountPop=0, li_errorCountFormat=0
var lc_errorText = ""
var lp_errorField
var li_fieldErrorLevel

//alert(getObject('fieldvalueR1_91').value.length);

    //if ( trimAll(getObject('fieldvalueR1_91').value).length > 0 ) return true;
    //if ( trimAll(getObject('fieldvalueR1_92').value).length > 0 ) return true;
    //if ( trimAll(getObject('fieldvalueR1_93').value).length > 0 ) return true;

    // Loop through the three email forms named fieldvalueR1_91 thru fieldvalueR1_93
    for ( li_i=91; li_i <= 93; li_i++ )
    {

        lp_fieldPtr = getObject( 'fieldvalueR1_' + li_i )

//alert("li+i/lp_fieldPtr.value.length=" + li_i + "/" + lp_fieldPtr.value.length + "/" + li_errorCountPop);

        // Check to see if at least one field is populated
        if ( lp_fieldPtr.value.length > 0 )
        {
            li_errorCountPop++;
        }

        // Check to make sure the formatting is correct
        if (!validateFormEmail( lp_fieldPtr ))
        {
            li_errorCountFormat++;
        }
    }


        // This logic is slightly different than the common logic in js.formedit.js
        if (li_errorCountPop    == 0 ) lc_errorText += '\n\r - Please enter at least one email address';
        if (li_errorCountFormat >  0 ) lc_errorText += '\n\r - Please correct the ' + li_errorCountFormat + ' field(s) with format errors';


    //* Take the results of any custom edits performed here
    if ( lc_errorText.length > 0 ) alert("Please correct the following errors before continuing:\n\r" + lc_errorText); else lb_noErrorFound = true;

//alert("lb_noErrorFound=" + lb_noErrorFound);
    return lb_noErrorFound
}
//*****************************************************************************
//** FUNCTION: Capture mouse movements to Dynamically set the location of a hidden popup menu to display an overlay like Netflix
//** e    : The event being handled
//*****************************************************************************
var mi_formTop  = 25
var mi_formLeft = 100

function getXYPosition(e) {
var offsetfromcursorX=50
var offsetfromcursorY=75

var li_browserHeight = window.document.body.clientHeight;
var li_browserWidth  = window.document.body.clientWidth;

var li_midscreen     = parseInt(window.document.body.clientWidth/2);

var ie5 = (document.getElementById && document.all);
var ns6 = (document.getElementById && !document.all);
var li_IEVersion = parseFloat(navigator.appVersion.split('MSIE')[1]);

var ua = navigator.userAgent.toLowerCase();
var isapple = (ua.indexOf('applewebkit') != -1 ? 1 : 0);
//alert(window.event.clientX +"/" + li_IEVersion)
    if ((document.getElementById) && (window.event))
    {
        var iebody=(document.compatMode &&
                document.compatMode != 'BackCompat') ?
                        document.documentElement : document.body;
        pagex  = (isapple == 1 ? window.pageXOffset:(ie5)?iebody.scrollLeft:window.pageXOffset);
        pagey  = (isapple == 1 ? window.pageYOffset:(ie5)?iebody.scrollTop:window.pageYOffset);

        if (li_IEVersion==5) {
			mousex = event.x;
			mousey = event.y;
		}
		else if (li_IEVersion >= 7)  {
			mousex = window.event.clientX;
			mousey = window.event.clientY;
//alert(window.event.clientX +"/" + li_IEVersion)
		}
		else if (ns6) {
			mousex = clientX = e.clientX;
			mousey = clientY = e.clientY;
		}
		else {
			mousex = false;
			mousey = false;
		}
		
        mi_formLeft = (mousex+pagex+offsetfromcursorX)+'px';
        mi_formTop  = (mousey+pagey+offsetfromcursorY)+'px';


        mi_formLeft = pagex+offsetfromcursorX+'px';
        mi_formTop  = pagey+offsetfromcursorY+'px';

//alert("pagex/pagey/mousex/mousey/mi_formleft/mi_formRight:= " + pagex + "/" +  pagey + "/" + mousex + "/" + mousey + "/" + mi_formLeft + "/" + mi_formTop);

        //If the cursor is on the left hand side of the screen, then move the popup box to the right side of the screen
        mi_formLeft = ( mousex < li_midscreen ? pagex+offsetfromcursorX+li_midscreen-100+'px' : pagex+offsetfromcursorX+li_midscreen-400+'px' );

    }

//window.status =  mi_formLeft+":"+mi_formTop+":"+isapple;

}

//*** Change this to onmousemove if you need to constantly be able to track the user's mouse movements like with a popup definition
//document.onmousemove = getXYPosition  //Useful to track when mouse moves each time
document.onmouseup = getXYPosition    //Useful to track when user clicks on event only - less CPU intensive


//*****************************************************************************
//** FUNCTION: Scroll the window smoothly to the specified window
//** pci_linkName    : The name of the link that we are trying to scroll to
//** pci_offsetLeft  : The left offset we are scrolling to
//** pci_offsetTop   : The top offset we are scrolling to
//** duration        : The duration it should take to scroll
//** steps           : The number of steps to complete the scroll in for smooth animation
//*****************************************************************************
function scrollSmoothly( pci_linkName, pci_offsetLeft, pci_offsetTop, poi_duration, poi_steps ) {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    //poi_duration is in seconds
    stepPoi_duration = Math.round(poi_duration/poi_steps) ; // Value is in miliseconds.

    //Find out the offset from the top of the page to the requested object
    if ((pci_offsetLeft==-1) || (pci_offsetTop==-1)) {
        var la_linkOffsets    = findPos(getObject(pci_linkName))
        var li_linkoffsetLeft = la_linkOffsets[0];
        var li_linkoffsetTop  = la_linkOffsets[1];
    }
    else {
        var li_linkoffsetLeft = pci_offsetLeft;
        var li_linkoffsetTop  = pci_offsetTop;
    }


    if (document.documentElement) {
        //x1 = document.documentElement.scrollLeft || li_linkoffsetLeft;
        //y1 = document.documentElement.scrollTop  || li_linkoffsetTop ;
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop  || 0 ;
    }

    if (document.body) {
        //x2 = document.body.scrollLeft || li_linkoffsetLeft;
        //y2 = document.body.scrollTop  || li_linkoffsetTop ;
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop  || 0 ;
    }

    //x3 = window.scrollX || li_linkoffsetLeft;
    //y3 = window.scrollY || li_linkoffsetTop ;
    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0 ;

    var x = parseInt(Math.max(x1, Math.max(x2, x3)));
    var y = parseInt(Math.max(y1, Math.max(y2, y3)));

    // Determine how far we need to jump from the current location to the next location based on remaining poi_steps
    difX = parseInt((li_linkoffsetLeft-x)/poi_steps/ 1.15);
    difY = parseInt((li_linkoffsetTop-y)/poi_steps/ 1.15);

    // Ensure the resultant number is not NaN and it is not Infinity
    difX = ((isNaN(difX))||(difX==Infinity)||(difX==-Infinity))?0:difX;
    difY = ((isNaN(difY))||(difY==Infinity)||(difY==-Infinity))?0:difY;

    //If all the differences are 0, then set Poi_steps to 0 to cancel the timers
    poi_steps = ((difX==0)&&(difY==0))?0:poi_steps;

    //window.scrollTo(Math.floor(x / 1.15), Math.floor(y / 1.15));
    window.scrollBy(difX,difY);
//alert( poi_steps + "/" + y2 + "/" + y3 + "/" + li_linkoffsetLeft + "/" + li_linkoffsetTop);

    //We take out the amount of time used, and a step already being executed
    poi_duration = (poi_duration - stepPoi_duration);
    poi_steps --;

    //if (x > li_linkoffsetLeft || y > li_linkoffsetTop) {
    if(poi_steps>=0){
        window.setTimeout('scrollSmoothly("' + pci_linkName + '",'+li_linkoffsetLeft+', '+li_linkoffsetTop+', '+poi_duration+','+poi_steps+')',stepPoi_duration);
    }
}

//*****************************************************************************
//** FUNCTION: Calculate the offset position of the specified object and return the left and top offsets
//** poi_object    : The object that we are trying to find the top and left offset of
//*****************************************************************************
function findPos( poi_object ) {
        var curleft = curtop = 0;

        if (poi_object.offsetParent) {
            do {
                            curleft += poi_object.offsetLeft;
                            curtop += poi_object.offsetTop;
                    } while (poi_object = poi_object.offsetParent);
    }
        return [curleft,curtop];
        //return curleft;
}

//*****************************************************************************
//** FUNCTION: Opens a modal window and displays the specified lookup picker
//** pci_pickerType          : the type of picker to display
//** pci_fieldToReturnPickTo : the name of the field to return the picked value to
//** pci_fieldCurrentValue   : the current value of the field to return the picked value to
//** pci_initialDirectory    : initial photo directory to display
//** pci_pickerParameters    : any additional parameters the individual picker may need

//** Requirements: The HTML page must include DHTMLMODAL.CSS/JS and DHTMLWINDOW.CSS/JS
//*****************************************************************************
function openPicker( pci_pickerType, pci_fieldToReturnPickTo, pci_fieldCurrentValue, pci_initialDirectory, pci_pickerParameters ) {
var li_browserHeight = window.document.body.clientHeight;
var li_browserWidth  = window.document.body.clientWidth;
var lc_pageCachePrefix = ""

    if ((!li_browserHeight) || (li_browserHeight<400)) li_browserHeight = 400;
    li_browserWidth = 500/.8

    //alert ("browserHeight/width: " + li_browserHeight + "/" + li_browserWidth );

    //*** If the currently loaded page is in the pagecache directory, then prefix the location with the parent directory to get to the correct program
    if (( location.href.indexOf('pagecache') > 0 ) && ( location.href.indexOf('localhost') < 0 ) )
        lc_pageCachePrefix = "../";
//alert( pci_initialDirectory + " / " + pci_pickerParameters );
    gptr_winPicker=dhtmlmodal.open('handle3', 'IFRAME', lc_pageCachePrefix + 'cc.admin.iframe.picker.icon.asp?pt='+ pci_pickerType + '&fn=' + pci_fieldToReturnPickTo + '&cv=' + pci_fieldCurrentValue + '&id=' + pci_initialDirectory + pci_pickerParameters, pci_pickerType + ' Picker', 'width=' + parseInt(li_browserWidth*.80) + 'px,height=' + parseInt(li_browserHeight*.80) + 'px,center=1,resize=0,scrolling=0');
    //alert(screen.width)

    gptr_winPicker.onclose=function(){  //Run custom code when window is about to be closed
        return true
    }
}

//*****************************************************************************
//** FUNCTION: Opens a modal window and displays the selected page
//** pci_pageNameToDisplay: page to display
//** pci_pageTitle: Title to display at top of page
//** pci_pageWidth: Page Width   - integer of 300-800 or auto to autosize it based on browser height
//** pci_pageHeight: Page Height - integer of 300-800 or auto to autosize it based on browser height

//** Requirements: The HTML page must include DHTMLMODAL.CSS/JS and DHTMLWINDOW.CSS/JS
//*****************************************************************************
function openNewModalPage( pci_pageNameToDisplay, pci_pageTitle, pci_pageWidth, pci_pageHeight ) {
var li_browserHeight = parseInt( window.document.body.clientHeight * 0.8 );
var li_browserWidth  = parseInt( window.document.body.clientWidth  * 0.8 );
var lc_pageCachePrefix = ""
var winModalWindow

    if ((!li_browserHeight) || (li_browserHeight<400)) li_browserHeight = 400;
    li_browserWidth = parseInt(li_browserHeight * 1.25)

    if ( pci_pageWidth  != 'auto' )
        li_browserWidth  = parseInt( pci_pageWidth );

    if ( pci_pageHeight != 'auto' )
        li_browserHeight = parseInt( pci_pageHeight );

    //*** If the currently loaded page is in the pagecache directory, then prefix the location with the parent directory to get to the correct program
    if (( location.href.indexOf('pagecache') > 0 ) && ( location.href.indexOf('localhost') < 0 ) )
        lc_pageCachePrefix = "../";


//alert( lc_pageCachePrefix + pci_pageNameToDisplay );


//alert ("browserHeight/width: " + li_browserHeight + "/" + li_browserWidth );

    winModalWindow=dhtmlmodal.open('handle4', 'IFRAME', lc_pageCachePrefix + pci_pageNameToDisplay, pci_pageTitle, 'width=' + li_browserWidth + 'px,height=' + li_browserHeight + 'px,center=1,resize=0,scrolling=0');
    //alert(screen.width)

    winModalWindow.onclose=function(){  //Run custom code when window is about to be closed
        return true
    }

}

//*****************************************************************************
//** FUNCTION: Opens a modal window and displays the selected directory and/or photo
//** pci_initialDirectory: initial photo directory to display
//** pci_initialPicture  : Initial photo to display in the photo directory

//** Requirements: The HTML page must include DHTMLMODAL.CSS/JS and DHTMLWINDOW.CSS/JS
//*****************************************************************************
function openPhotoboard( pci_initialDirectory, pci_initialPicture ) {
var li_browserHeight = window.document.body.clientHeight;
var li_browserWidth  = window.document.body.clientWidth;
var lc_pageCachePrefix = ""
var winPhotoViewer

    if ((!li_browserHeight) || (li_browserHeight<400)) li_browserHeight = 400;
    li_browserWidth = parseInt(li_browserHeight * 1.25)

//alert ("browserHeight/width: " + li_browserHeight + "/" + li_browserWidth );

    //*** If the currently loaded page is in the pagecache directory, then prefix the location with the parent directory to get to the correct program
    if (( location.href.indexOf('pagecache') > 0 ) && ( location.href.indexOf('localhost') < 0 ) )
        lc_pageCachePrefix = "../";


//alert( location.href + ":" + lc_pageCachePrefix );


    winPhotoViewer=dhtmlmodal.open('handle2', 'IFRAME', lc_pageCachePrefix + 'cc.photoboard.asp?sbw=' + parseInt(li_browserWidth*.90) +'&sbh=' + parseInt(li_browserHeight*.90) + '&sbc=000&df=pview&bpn=1&id=' + pci_initialDirectory + '&ip=' + pci_initialPicture, 'Corpus Christi Pictures', 'width=' + parseInt(li_browserWidth*.92) + 'px,height=' + parseInt(li_browserHeight*.92) + 'px,center=1,resize=0,scrolling=0');
    //alert(screen.width)

    winPhotoViewer.onclose=function(){  //Run custom code when window is about to be closed
        return true
    }

//    for (i=1; i<100; i++) {
//alert(i + ': height=' + parseInt(i*10+30) + "/" + 200 )
//alert('winPhotoViewer.setSize("' + getObject("handle2").id + '",'+ parseInt(i*10)+',100)');
//        window.setTimeout( 'winPhotoViewer.setSize("' + getObject("handle2") + '",' + parseInt(i*10) + ', 600)', parseInt(50*i));
//       window.setTimeout( 'winPhotoViewer.moveTo ("' + getObject("handle2") + '","middle","middle")', parseInt(50*i));
//   }
}

//******************************************************
//* FUNCTION will determine if image has loaded successfully and then set the sizing parameters and picture frame according to the picture ratio
//* pci_imageName - name of the image object to track until loaded successfully
//******************************************************
//* Assumption is that the id of the thumbnail image that is being tracked begins with "thumbimageHolder"
//* Assumption is that the id of the image to be updated begins with "imageHolder"
//* Assumption is that the id of the image with the picture frame to be updated begins with "frameHolder"
//******************************************************
function waitForPictureFrameToLoad(pci_imageName){
var li_ratio,imgWait
var tih_img, ih_img, fh_img
var la_imageParameters = new Array(76, 96, 7, 10);
var li_imageSizeMultiplier = 1


//alert('waitForImageToLoad:' + pci_imageName);
    tih_img = document.getElementById( pci_imageName )

    if(!tih_img.complete){
        imgWait=setTimeout('waitForPictureFrameToLoad("' + pci_imageName + '")', 250);
    }
    else
    {
//alert( pci_imageName + " wth/hgt: " + tih_img.width + "/" + tih_img.height );

        ih_img   = document.getElementById( pci_imageName.replace("thumbimageHolder","imageHolder") )
        fh_img   = document.getElementById( pci_imageName.replace("thumbimageHolder","frameHolder") )
        ph_img   = document.getElementById( pci_imageName.replace("thumbimageHolder","photoHolder") )

        li_ratio = tih_img.height / tih_img.width
//alert(li_ratio);

        ih_img.ratio = li_ratio;

        lc_frameSize           = fh_img.src.substr(fh_img.src.lastIndexOf('.',(fh_img.src.length-6))+1,5)
        li_imageSizeMultiplier = (lc_frameSize=='large')?2: (lc_frameSize=='mediu')?1.5:1;


        //* Depending on thumbnail size ratio, set the actual picture proportions and adjust the picture frame accordingly
        if (ih_img.ratio>1) {
            ih_img.width      = parseInt(la_imageParameters[0]*li_imageSizeMultiplier)
            ih_img.height     = parseInt(la_imageParameters[1]*li_imageSizeMultiplier)
            ih_img.style.top  = parseInt(la_imageParameters[2]*li_imageSizeMultiplier) + "px"
            ih_img.style.left = parseInt(la_imageParameters[3]*li_imageSizeMultiplier) + "px"

            ph_img.style.left = (((isNaN(parseInt(ph_img.style.left)))?0:parseInt(ph_img.style.left))+10) + "px"
            fh_img.src        = fh_img.src.replace('pictureframeW','pictureframeT')
        }
        else {
            ih_img.width      = parseInt(la_imageParameters[1]*li_imageSizeMultiplier)
            ih_img.height     = parseInt(la_imageParameters[0]*li_imageSizeMultiplier)
            ih_img.style.top  = parseInt(la_imageParameters[3]*li_imageSizeMultiplier) + "px"
            ih_img.style.left = parseInt(la_imageParameters[2]*li_imageSizeMultiplier) + "px"

            fh_img.src        = fh_img.src.replace('pictureframeT','pictureframeW')
        }

        ih_img.src            = ih_img.src.replace('thumbs/','')

//alert(ih_img.ratio);

//alert('Image Loaded:' + pci_imageName);

    }
}



//**********************************************
//* FUNCTION will create a cookie with the given name, the value assigned to the name, and the days to keep before expiration.
//**********************************************
function createCookie(name,value,days) {
        if (days) {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
}

//**********************************************
//* FUNCTION will read a cookie with the given name and return the value of the cookie
//**********************************************
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 will erase a cookie of the given name
//**********************************************
function eraseCookie(name) {
        createCookie(name,"",-1);
}


//*****************************************************************************
//** FUNCTION: Check to see if the current browser is MSIE
//*****************************************************************************
function isBrowserIE(){
    return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}



//*****************************************************************************
//** FUNCTION: preload background images used in the menu structure.
//*****************************************************************************
//* Example: preloadMenuImages( )
//*****************************************************************************
function preloadMenuImages( )
{
  if (!document.images) return;

  var limg_imageHolder = new Image();
  var la_preloadImages = new Array();

  //*** Cycle through all the links in the document
  for (var i = 0; i < document.links.length; i++)
  {

  //*** If you find a link with a background image with a gif in it, then extract the file path and name and create set the temporary object to hold it.
    if ( document.links[ i ].style.backgroundImage.indexOf('gif') > 1 ) {
        //alert( document.links[ i ].style.backgroundImage );

        lc_imagePath = document.links[ i ].style.backgroundImage.substring(4, (document.links[ i ].style.backgroundImage.length-1) );

        limg_imageHolder.src = lc_imagePath;


        la_preloadImages[ i ]     = new Image();
        la_preloadImages[ i ].src = lc_imagePath
        //alert(limg_imageHolder.src)

    }

  }
}


//*****************************************************************************
//** FUNCTION: preload all images in current document
//*****************************************************************************
//* Example: preloadImages( )
//*****************************************************************************
function preloadImages()
{
  if (!document.images) return;

  //var la_currentImages = new Array();
  var la_preloadImages = new Array();

  //alert( document.images.length );

  //*** Cycle through all the images in the document and store them in an array.
  for (var i = 0; i < document.images.length; i++)
  {
    //la_currentImages[i] = document.images[ i ].src
    //limg_imageHolder.src = document.images[ i ].src

    la_preloadImages[ i ]     = new Image();
    la_preloadImages[ i ].src = document.images[ i ].src

    //alert( la_preloadImages[ i ].src );
  }

    //alert( la_preloadImages.length );
}


//*****************************************************************************
//** FUNCTION: replaces all instances of a string with another string
//*****************************************************************************
function xreplace(pci_incomingString, pci_lookForString, pci_replaceWithString){

var temp = pci_incomingString;


//alert( "typeof(temp)/pci_lookForString/pci_replaceWithString=" + typeof(temp) + "/" + temp  + "/{" + pci_lookForString +"}{" + pci_replaceWithString + "}");

    if ( typeof( temp ) == 'string' ) {

        var i    = temp.indexOf(pci_lookForString);
        while(i > -1)
        {
            temp = temp.replace(pci_lookForString, pci_replaceWithString);
            i    = temp.indexOf(pci_lookForString, i + pci_replaceWithString.length + 1);
        }
    }

    return temp;

}


//*****************************************************************************
//** FUNCTION: hides the specified object (Not currently Used anywhere, just an example)
//** poi_objID: The ID of the object to hide
//** Note     : Function was extrapolated from bugbook.com
//*****************************************************************************
function hideObject(poi_objID)
{
        var obj = getObject(poi_objID);
        var rtn = false;
        if (obj != null) {
        obj.style.display = "none";
                rtn = true;
        }
        return rtn;
}

//*****************************************************************************
//** FUNCTION: Shows the specified object (Not currently Used anywhere, just an example)
//** poi_objID: The ID of the object to show
//** Note     : Function was extrapolated from bugbook.com
//*****************************************************************************
function showObject(poi_objID)
{
        var obj = getObject(poi_objID);
        var rtn = false;
        if (obj != null) {
          obj.style.visibility = "visible";
          obj.style.display = "inline";
          obj.style.position = "static";
          obj.style.width = "auto";
          obj.style.height = "auto";
          obj.style.overflow = "visible";
        //  obj.style.innerHTML = "<b>new name</b>";

          rtn = true;
        }
        return rtn;
}

//*********************************************************************************
// ppi_ptrControl: The ptr to a graphical image that contails ".on." in it and has a counterpart with ".of." in it.
//                 This control will be used to hide or show the named division.
// pci_divName   : The name of the division to show or hide
//*********************************************************************************
// Examples: toggleDivisionVisibility( this, 'orderhistory13' )
//*********************************************************************************
function toggleDivisionVisibility( ppi_ptrControl, pci_divName )
{
//alert( getObject( pci_divName ).style.display );

    if ( getObject( pci_divName ).style.display == "none" ) {
        ppi_ptrControl.src = ppi_ptrControl.src.replace('.on.','.of.');
        showObject( pci_divName )
    }
    else {
        ppi_ptrControl.src = ppi_ptrControl.src.replace('.of.','.on.');
        hideObject( pci_divName );
    }
//alert(1);

//alert( getObject( pci_divName ).style.display );

    return false;
}


//*****************************************************************************
//** FUNCTION: Will set the specified object to the specified visibility (Not currently Used anywhere, just an example)
//** poi_objID:         The ID of the object to set the visibility
//** pci_newVisibility: The visibility to set the object to
//** Note     : Function was extrapolated from bugbook.com
//*****************************************************************************
function changeObjVis(poi_objectId, pci_newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(poi_objectId);
    if(styleObject) {
//alert(2);
        styleObject.visibility = pci_newVisibility;
        return true;
    } else {
//alert(3);
        //we couldn't find the object, so we can't change its visibility
        return false;
    }
}


//*****************************************************************************
//** FUNCTION: Formats the incoming number for US Currency
//*****************************************************************************
function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g,'');
    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: Returns a ptr to style object of the requested object name
//** poi_objID: The name of the object to show
//*****************************************************************************
function getStyleObject(poi_objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(poi_objectId)) {
        // W3C DOM
        return document.getElementById(poi_objectId).style;
    } else if (document.all && document.all(poi_objectId)) {
        // MSIE 4 DOM
        return document.all(poi_objectId).style;
    } else if (document.layers && document.layers[poi_objectId]) {
        // NN 4 DOM.. note: this won't find nested layers
        return document.layers[poi_objectId];
    } else {
        return false;
    }
}

//*****************************************************************************
//** FUNCTION: Finds the specified object and returns a pointer to it
//** poi_objID: The ID of the object to find
//** Note     : Function was extrapolated from bugbook.com
//*****************************************************************************
function xxgetObject(poi_objID)
{
   if (document.all)
   {
      var obj = document.all[poi_objID];
   }
   else if (document.getElementById)
   {
      var obj = document.getElementById(poi_objID);
   }
        return obj;
}

//*****************************************************************************
//** FUNCTION: Returns a ptr to requested object name
//** poi_objID: The name of the object to show
//*****************************************************************************
function getObject(pci_ObjectName) {
    // cross-browser function to get an object's style object given its id

    if(document.getElementById && document.getElementById(pci_ObjectName)) {
        // W3C DOM
        //alert("getObject: W3C DOM: " + pci_ObjectName)
        return document.getElementById(pci_ObjectName);
    } else if (document.all && document.all(pci_ObjectName)) {
        // MSIE 4 DOM
        //alert("getObject: MSIE: " + pci_ObjectName)
        return document.all(pci_ObjectName);
    } else if (document.layers && document.layers[pci_ObjectName]) {
        // NN 4 DOM.. note: this won't find nested layers
        //alert("getObject: NN: " + pci_ObjectName)
        return document.layers[pci_ObjectName];
    } else {
        //alert("getObject: Not Found: " + pci_ObjectName)
        return false;
    }

}

//*****************************************************************************
//** FUNCTION: Returns a ptr to the requested field in the form so that the value can be manipulated.
//**           This Function is useful for generically generated forms where the fieldname that matches
//**           the database name is stored in a separate hidden value, and that is what has to be found to be able
//**           to manipulate the associated value field.
//** pci_formName:      The name of the form that contains the field to be manipulated
//** pci_formFieldName: The name of the field to be manipulated
//** pci_formFieldRow:  The row number that the field appears on. Useful when there are multiple rows displayed with the same field on each row.
//*****************************************************************************
//** Examples: getFormFieldByName( "edittable", "nameLastMember", 1 )
//*****************************************************************************
function getFormFieldByName(pci_formName, pci_formFieldName, pci_formFieldRow ) {
var li_i


    lc_form            = getObject( pci_formName );
//alert("lc_form.name=" + lc_form.name );
//alert("pci_formFieldName=" + pci_formFieldName );

    lc_NumFields       = getObject( "rowColumnsR" + pci_formFieldRow );
    lc_formFieldResult = false;

//alert ( "lc_NumFields=" + lc_NumFields.value);


    if ( lc_form && lc_NumFields ) {


        for (li_i=1; li_i <= lc_NumFields.value; li_i++) {

//alert ( eval("getObject( '" + pci_formName + "' ).fieldnameR"+pci_formFieldRow+"_"+li_i+".value") );

            lc_formField = eval("lc_form.fieldnameR"+pci_formFieldRow+"_"+li_i);

            if (lc_formField)
            {

                lc_formFieldName = lc_formField.value;

//alert( "lc_formFieldName=" + lc_formFieldName )

                // Try to find the field in the form
                if ( lc_formFieldName == pci_formFieldName ) {

//alert( "lc_formFieldName/pci_formFieldName=" + lc_formFieldName + "/" + pci_formFieldName )

                     lc_formFieldResult = eval("lc_form.fieldvalueR"+pci_formFieldRow+"_"+li_i);

//alert("lc_formFieldResult=" + lc_formFieldResult.name);

                     li_i               = lc_NumFields.value + 1;
                }
            }

        }
        if ( !lc_formFieldResult) {
           alert ( "Field: " +  pci_formName + "." + pci_formFieldName + " not found.");
        }
    }
    else {
        alert ( "Form: " +  pci_formName + " not found.");
    }

    return lc_formFieldResult

}

//*****************************************************************************
//** FUNCTION: Will set a specified field on specified form to a specified value
//** pci_formName:          The name of the form that contains the field to be manipulated
//** pci_formFieldName:     The name of the field to be manipulated
//** pci_formFieldNewValue: The value to set the field to
//** pci_formFieldRow:  The row number that the field appears on. Useful when there are multiple rows displayed with the same field on each row.
//*****************************************************************************
function setFormFieldByName(pci_formName, pci_formFieldName, pci_formFieldNewValue, pci_formFieldRow ) {

var lc_formField

    lc_formField       =  getFormFieldByName(pci_formName, pci_formFieldName, pci_formFieldRow )

    //** If this is a checkbox, then change the "checked" property, not the "value" property
    if ( pci_formFieldName.indexOf("YN") > 0 ) {
        lc_formField.checked =  pci_formFieldNewValue
    }
    else {
        //*** Replace the HTML versions of single and double-quotes with their real versions for display purposes
        lc_formField.value   =  xreplace( xreplace( pci_formFieldNewValue, "&#34;", '"' ), "&#39;", "'" );
//alert( "2:pci_formFieldName/lc_formField.value=" + pci_formFieldName + "/" + lc_formField.value );
    }


}


//*****************************************************************************
//** FUNCTION: Will find occurrence of string in page and highlight string
//** pci_String:       The string to find
//*****************************************************************************
var TRange=null

function findString (pci_String) {

    if (parseInt(navigator.appVersion)<4)
        return;

    if ( pci_String == null )
        return;

    if ( pci_String.length < 1 )
        return;




        var strFound;
        if (navigator.appName=="Netscape") {
            // NAVIGATOR-SPECIFIC CODE
           strFound=self.find(pci_String);
           if (!strFound) {
                strFound=self.find(pci_String,0,1);
                while (self.find(pci_String,0,1))
                   continue
           } else {
               if (confirm("Search item '"+pci_String+"' was found and is highlighted. \n\r\n\rSearch for next entry?")) {
                   findString (pci_String);
               }
           }
        }

        if (navigator.appName.indexOf("Microsoft")!=-1) {
            // EXPLORER-SPECIFIC CODE
            if (TRange!=null) {
                TRange.collapse(false)
                primero=true;
                strFound=TRange.findText(pci_String)
                if (strFound) {
                    TRange.select();
                    if (confirm("Search item '"+pci_String+"' was found and is highlighted. \n\r\n\rSearch for next entry?")) {
                        findString (pci_String);
                    }
                }
            }

            if (TRange==null || strFound==0) {
                TRange=self.document.body.createTextRange()
                strFound=TRange.findText(pci_String)
                if (strFound) {
                    TRange.select();
                    if (confirm("Search item '"+pci_String+"' was found and is highlighted. \n\r\n\rSearch for next entry?")) {
                        findString (pci_String);
                    }
                }
            }
        }

        if (!strFound)
            alert ("String '"+pci_String+"' not found!")
}



//*****************************************************************************
//** FUNCTION: Will trim spaces off the left side of a string
//** pci_String:       The string to trim spaces off the right side of
//*****************************************************************************
function trimLeft(pci_String)
{
    while (pci_String.substring(0,1) == ' ')
    {
        pci_String = pci_String.substring(1, pci_String.length);
    }
    return pci_String;
}

//*****************************************************************************
//** FUNCTION: Will trim spaces off the right side of a string
//** pci_String:       The string to trim spaces off the left of
//*****************************************************************************
function trimRight(pci_String)
{
    while (pci_String.substring(pci_String.length-1, pci_String.length) == ' ')
    {
        pci_String = pci_String.substring(0,pci_String.length-1);
    }
    return pci_String;
}


//*****************************************************************************
//** FUNCTION: Will trim spaces off the left and right side of a string
//** pci_String:       The string to trim spaces off of
//*****************************************************************************
function trimAll(pci_String)
{
    while (pci_String.substring(0,1) == ' ')
    {
        pci_String = pci_String.substring(1, pci_String.length);
    }
    while (pci_String.substring(pci_String.length-1, pci_String.length) == ' ')
    {
        pci_String = pci_String.substring(0,pci_String.length-1);
    }
    return pci_String;
}

//*****************************************************************************
//** FUNCTION: Will parse a string looking for a specified named-value pair
//** pci_String:       The string to trim spaces off of
//*****************************************************************************
function getQueryVariable( pci_stringToSearch, pci_namedValuePairToFind ) {

  var lc_query = pci_stringToSearch;
  var la_variablePairsArray = lc_query.split("&");

  for (var i=0; i < la_variablePairsArray.length; i++) {
    var lc_pair = la_variablePairsArray[i].split("=");
    if ( lc_pair[0] == pci_namedValuePairToFind ) {
      return lc_pair[1];
    }
  }
  //alert('Query namedValuePairToFind' + pci_namedValuePairToFind+ ' not found');

  return null;
}

//**********************************************************************************************************
//* This function should be called from any script with a form generated by the buildFormComponent Routines
//* It will start by calling the global routine to validate any required fields or any fields that have formatting errors
//* Once this is done, there are custom edits that can be fired as necessary
//**********************************************************************************************************
//* The parameter pii_formToEdit is optional and can be used for further selective processing within the page
//**********************************************************************************************************
//* This function can be copied and redefined in the local ASP file if additional functionality is needed for localized processing
//**********************************************************************************************************
function validateFormEdits( pii_formToEdit ) {

////////////////////////////////////////////////////////////////////////////////////////////////////////////
//    var lb_noError = true;

//alert( eval( "getObject( 'edittable' ).fieldvalue" + 5).onchange)
//    for (li_i=1; li_i <= <%= mi_fieldCount %>; li_i++)
//    {
//      //alert( eval("getObject( 'edittable' ).fieldvalue" + li_i) );
//
//         //getFormFieldByName("edittable", "eventDate").onchange  = function() {validateFormEmail(this)};
//         //alert(getObject( 'edittable' ).fieldvalue5.onchange);
//
//      lb_noError = lb_noError || eval("getObject( 'edittable' ).fieldvalue" + li_i).onChange
//
//      //** This is not working correctly but will be used to refire each JS edit upon commit and stop the submit if any fail.
//      //**
//      //** Need to figure out how to systematically call each onchange to ensure they are all checked. Also need to set errors to blank if user cancels form.
//      //alert(eval("getObject( 'edittable' ).fieldvalue" + li_i).onchange)
//
//      //eval(eval("getObject( 'edittable' ).fieldvalue" + li_i).onchange( eval("getObject( 'edittable' ).fieldvalue" + li_i) ) ) );
//      //lb_noError = getObject( 'edittable' ).fieldvalue5.onchange( getObject( 'edittable' ).fieldvalue5 );
//
//  };
//
//  return lb_noError
////////////////////////////////////////////////////////////////////////////////////////////////////////////

var lb_noErrorFound = false
var lc_errorText = ""


        //*****************************************************************
        // Peform global edits for each required field or field with edit specified
        //*****************************************************************
        lc_errorText = processRequiredFormattingFieldEdits()

        //*****************************************************************
        // Peform custom edits depending on the page
        //*****************************************************************
        switch( pii_formToEdit )
        {
            case 1:
                        {
                            break;
                        }

            case 2:
                        {
                            break;
                        }

            case 3:
                        {
                            break;
                        }

            default:
                        {
                            break;
                        }
        }


    //* Take the results of any custom edits performed here

    if ( lc_errorText.length > 0 ) alert("Please correct the following errors before continuing:\n\r" + lc_errorText); else lb_noErrorFound = true;

    return lb_noErrorFound

}

