/*========================================================================================
  
$rcsfile: BookingRetrieveInput.js $

$Revision: 1.1 $ $Date: 2006/09/07 09:35:06 $

Summary:	JavaScript file for the BookingRetrieveInput control. Content moved from the C# code.

------------------------------------------------------------------------------------------
This file is part of the Navitaire NewSkies application.
Copyright (C) Navitaire.  All rights reserved.
========================================================================================*/



function BookingRetrieveValues_Validate()
{
    var ds = $("#SkySales");
	var controls = $("input,select", ds)
	var sectionPopulateCounter = 0;    
    var missing = false;
    var empty = true;	
	
	//get the sections
	var sectionList = applicationSections.split(",")    
	
	for(var i=0; i < sectionList.length; i++)
	{
	    var controlList = sectionList[i].split("|");
	    var sectionIndex = i+1;
	    var controlPopulatedCount = 0;
	    
	    for(var j=0; j < controlList.length; j++)
	    {   
	        var controlName = applicationBookingRetrieveJavaScriptHtmlId + '$' + controlList[j] + sectionIndex;
			var control = controls.filter("[name=" + controlName + "]");
	        var controlIsPopulated = false;
	        
	        if (controlList[j] == "DEPARTMONTH"
                || controlList[j] == "DEPARTDAY"
                || controlList[j] == "DEPARTYEAR"
                || controlList[j] == "CARDTYPE")
            {
                controlIsPopulated = control.val() != control.attr("requiredempty");
            }
            else if(controlList[j] == "ORIGINCITY"
                || controlList[j] == "DESTINATIONCITY")
            {
                controlIsPopulated = control.val() != "---";
            }
	    else {
		 controlIsPopulated = (control.val() || (0));
	    }
            
            if (controlIsPopulated)
            {
                controlPopulatedCount++;
                empty = false;
            }
	    }//end control loop

        //check if all items are answered
        missing = missing ||((controlPopulatedCount < controlList.length) && (controlPopulatedCount > 0));
	    
	    //monitor number of sections answered
        if (controlPopulatedCount > 0)
        {
            sectionPopulateCounter++;
        }       
	}//end section loop

	if (sectionPopulateCounter > 1)
	{
	    s2.tuifly.widget.dialog.alert(localizedenteredInfoInMoreThanOneSection);
	    return false;
	}

    if (missing || empty)	
    {
        s2.tuifly.widget.dialog.alert(localizedMissingInformation);
        return false;
    }        

	
	return true;
}