var _listingIds = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16];
var _listingAddress = [];
var _listingPhoneInfo = [];
var _listingDescriptionLeft = [];
var _listingDescriptionRight = [];
var _listingPic = ['01.jpg','02.jpg','03.jpg','04.jpg','05.jpg','06.jpg','07.jpg','08.jpg','09.jpg','10.jpg','11.jpg','12.jpg','13.jpg','14.jpg','15.jpg','16.jpg','17.jpg'];
var _listingLink = [];
var _pictures = [];
var _listingIndex = -1;
var _timer;

function ShowPicture()
{
    //alert("Starting ShowListing - " + _listingIds.length);
    if(_listingIds.length > 0)
    {
		//alert(_listingIndex);
		
        if(_listingIndex >= _listingIds.length)
            _listingIndex = 0;
         
        //alert(_pictures.length);
         
        //check to see if the picture has been loaded yet   
        if(_pictures.length <= _listingIndex)
        {
            _pictures[_listingIndex] = new Image;
            //alert("loading images/gallery/santa" + _listingPic[_listingIndex]);
	        _pictures[_listingIndex].src = 'images/gallery/santa' + _listingPic[_listingIndex];
        }
        
        //show the picture if it is fully loaded, otherwise wait .5 sec and try again
	    if (_pictures[_listingIndex] && (_pictures[_listingIndex].complete || _pictures[_listingIndex].complete==null)) 
	    {
			//alert("READY");	
	    
	        var image = document.getElementById("pictureViewer");
		    if(image != null)
		    {
				//alert("got pictureViewer");
				
			    image.filters[0].apply();
			    image.src = 'images/gallery/santa' + _listingPic[_listingIndex];
			    image.filters[0].play();	
			    
			    //document.getElementById("listingAddress").innerHTML = _listingAddress[_listingIndex];
			    //document.getElementById("listingPhoneInfo").innerHTML = _listingPhoneInfo[_listingIndex];
			    //document.getElementById("listingLeftDescription").innerHTML = _listingDescriptionLeft[_listingIndex];
			    //document.getElementById("listingRightDescription").innerHTML = _listingDescriptionRight[_listingIndex];
			    //document.getElementById("listingLink").innerHTML = _listingLink[_listingIndex];
    			
			    _timer = window.setTimeout("ShowNextPicture()", 4000);
		    }
        }
        else
	    {
		    setTimeout("ShowPicture()", 250);
	    }
    }
}

function ShowNextPicture()
{
    //alert("Starting ShowNextPicture");
    _listingIndex++;
    ShowPicture();
}

function StartTimer()
{
    //alert("Starting Timer");
	_timer = window.setTimeout("ShowNextPicture()", 4000);
}

//validates an array of required controls to make sure that their value properties are not empty
//to use pass a multi-dimensional array in the following format - 
// [['control1Id', 'Control1 Name for Display'], ['control2Id', 'Control2 Name for Display],...] 
function ValidateRequiredStrings(requiredFieldArray)
{
	//alert("here");
	return ValidateRequiredStringsWithCustomMessage(requiredFieldArray, "");
}

function ValidateRequiredStringsWithCustomMessage(requiredFieldArray, customMessage)
{
	var requiredFields = "";
	
	for (var i = 0; i < requiredFieldArray.length; i++) 
	{ 		
		var controlId = requiredFieldArray[i][0]; 
		if(!ValidateRequiredStringValue(controlId))
			requiredFields += "\n     -" + requiredFieldArray[i][1]; 
	} 
	
	if(requiredFields == "")
	{
		return true;
	}
	else
	{
		var messageToDisplay = "";
		if(customMessage.length > 0)
		{
			messageToDisplay = customMessage + "\n\n";
		}
		alert(messageToDisplay + "The following fields are required:" + requiredFields);
		return false;
	}
}

//validates that the control with the passed id has a non empty value
function ValidateRequiredStringValue(controlId)
{
	var stringValueControl = document.getElementById(controlId);
	if(stringValueControl == null)
	{
		alert("DEBUG MSG: Cannot validate " + controlId + " because the control cannot be found on this page!");
		return false;
	} 
	else 
	{
		if(TrimString(stringValueControl.value) == "")
			return false;
	}
	return true;
}

//Trims any leading spaces off of the front and end of a string 
function TrimString(sInString) 
{
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}