
/**
 * Provides suggestions for state names (USA).
 * @class
 * @scope public
 */
function StateSuggestions() {
   var tmpinfo = "";
		       loadFlashOnBodyLoad();
                //alert("in"); 
                var xmlDoc;
                var file = "//www.spiritvoyage.com/xml/itemxml.xml";
                var moz = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument !='undefined');
                var ie  = (typeof window.ActiveXObject != 'undefined');
                if(moz)
                {
                try
                {
                xmlDoc = document.implementation.createDocument("","",null)
                xmlDoc.async = false;
                xmlDoc.load(file);
                //xmlDoc.onLoad = readXML();
                }
                catch(e)
                {
                //Error On Loading in IE
                }
                }
                else if(ie)
                {
                xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                xmlDoc.async = false;
                if(xmlDoc.readyState == 4)
                {
                 try{
                    xmlDoc.load(file);
                    }
                catch(e)
                {
                //Error On Loading in IE
                }
                    //readXML();
                }
                else
                {
                    //document.write("<font face =verdana size =2>Unable to perform.<br>Encountered Error on loading.....</font>");
                }
                }
                else
                {
                    //document.write("<font face =verdana size =2>Your Browser unable to manipulate this script !!!</font>");
                }
                var ckF = 1;
                var xyz = "";
//                var ItemId=xmlDoc.getElementsByTagName("ItemId");
//                //alert(site.length);
//                for(var i=0;i<ItemId.length;i++)
//                {
//                    xyz = ItemId[i].firstChild.nodeValue.toLowerCase();
//                    //if(xyz.indexOf(ot_) >= 0)
//                    //{
//                        if(i == 0 )
//                        {
//                             tmpinfo = tmpinfo + "^" + ItemId[i].firstChild.nodeValue.toString();
//				
//                        }
//                        else if(tmpinfo.toLowerCase().indexOf(xyz) == -1)
//                        {
//                            tmpinfo = tmpinfo + "^" + ItemId[i].firstChild.nodeValue.toString();
//				
//                        }
//                    //}
//                    
//                }
                var cnt =0;
                  //if((a == 0) || (a == 1)) 
                 // { 
                      var ArtistName = xmlDoc.getElementsByTagName("ArtistName");
                        for(var i=0;i<ArtistName.length;i++)
                        {
                            xyz = ArtistName[i].firstChild.nodeValue.toLowerCase();
    //                        //if(xyz.indexOf(ot_) >= 0)
    //                        //{
                                if(i == 0)
                                {
                                    tmpinfo = tmpinfo + "^" + ArtistName[i].firstChild.nodeValue.toString();
                                     //tmpinfo = tmpinfo + "^" +  xyz;
                                }
                                else if(tmpinfo.toLowerCase().indexOf(xyz) == -1)
                                {
                                    tmpinfo = tmpinfo + "^" + ArtistName[i].firstChild.nodeValue.toString();
                                     //tmpinfo = tmpinfo + "^" +  xyz;
                                }
    //                       // }
                        }
                   // }
                    //if(a == 0)
                    //{
                        var Itemname = xmlDoc.getElementsByTagName("ItemName");
                        for(var i=0;i<Itemname.length;i++)
                        {
                            xyz = Itemname[i].firstChild.nodeValue.toLowerCase();
                            //if(xyz.indexOf(ot_) >= 0)
                            //{
                                if(i == 0)
                                {
                                    tmpinfo = tmpinfo + "^" + Itemname[i].firstChild.nodeValue.toString();
                                    //tmpinfo = tmpinfo + "^" +  xyz;
                                }
                                else if(tmpinfo.toLowerCase().indexOf(xyz) == -1)
                                {
                                    tmpinfo = tmpinfo + "^" + Itemname[i].firstChild.nodeValue.toString();
                                    // tmpinfo = tmpinfo + "^" +  xyz;
                                }
                                
                            //}
                        }
                    //}
                   
                   // if((a == 0 ) || (a == 2)) 
                    //{ 
                        var SubCategory = xmlDoc.getElementsByTagName("SubCategory");
                        for(var i=0;i<SubCategory.length;i++)
                        {
                            xyz = SubCategory[i].firstChild.nodeValue.toLowerCase();
    //                        //if(xyz.indexOf(ot_) >= 0)
    //                        //{
                                if(i == 0)
                                {
                                    tmpinfo = tmpinfo + "^" + SubCategory[i].firstChild.nodeValue.toString();
                                     //tmpinfo = tmpinfo + "^" +  xyz;
                                }
                                else if(tmpinfo.toLowerCase().indexOf(xyz) == -1)
                                {
                                    tmpinfo = tmpinfo + "^" + SubCategory[i].firstChild.nodeValue.toString();
                                     //tmpinfo = tmpinfo + "^" +  xyz;
                                }
    //                        //}
                        }
                   // }
                    //if((a == 0) || (a == 2)) 
                    //{ 
                        var Category = xmlDoc.getElementsByTagName("Category");
                        for(var i=0;i<Category.length;i++)
                        {
                            xyz = Category[i].firstChild.nodeValue.toLowerCase();
    //                        //if(xyz.indexOf(ot_) >= 0)
    //                        //{
                                if(i == 0)
                                {
                                    tmpinfo = tmpinfo + "^" + Category[i].firstChild.nodeValue.toString();
                                     //tmpinfo = tmpinfo + "^" +  xyz;
                                }
                                else if(tmpinfo.toLowerCase().indexOf(xyz) == -1)
                                {
                                    tmpinfo = tmpinfo + "^" + Category[i].firstChild.nodeValue.toString();
                                     //tmpinfo = tmpinfo + "^" +  xyz;
                                }
    //                        //}
                        }
                    //}
                    
//                    if((a == 0) || (a == 4)) 
//                    { 
//                        var TrackName = xmlDoc.getElementsByTagName("TrackName");
//                        for(var i=0;i<TrackName.length;i++)
//                        {
//                            xyz = TrackName[i].firstChild.nodeValue.toLowerCase();
//    //                        //if(xyz.indexOf(ot_) >= 0)
//    //                        //{
//                                if(i == 0)
//                                {
//                                    tmpinfo = tmpinfo + "^" + TrackName[i].firstChild.nodeValue.replace('_',' ');
//                                     //tmpinfo = tmpinfo + "^" +  xyz;
//                                }
//                                else if(tmpinfo.toLowerCase().indexOf(xyz) == -1)
//                                {
//                                    tmpinfo = tmpinfo + "^" + TrackName[i].firstChild.nodeValue.replace('_',' ');
//                                     //tmpinfo = tmpinfo + "^" +  xyz;
//                                }
//    //                        //}
//                        }
//                    }
                    
                  
                   

    //this.states = [
       // "Alabama", "Alaska", "Arizona", "Arkansas",
      //  "California", "Colorado", "Connecticut",
      //  "Delaware", "Florida", "Georgia", "Hawaii",
     //   "Idaho", "Illinois", "Indiana", "Iowa",
     //   "Kansas", "Kentucky", "Louisiana",
      //  "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", 
       // "Mississippi", "Missouri", "Montana",
       // "Nebraska", "Nevada", "New Hampshire", "New Mexico", "New York",
        //"North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", 
        //"Pennsylvania", "Rhode Island", "South Carolina", "South Dakota",
        //"Tennessee", "Texas", "Utah", "Vermont", "Virginia", 
        //"Washington", "West Virginia", "Wisconsin", "Wyoming"  
   // ];
	//alert(tmpinfo.length);
	

	this.states =tmpinfo.split("^");
	 
	Synchronize(); 
}

/**
 * Request suggestions for the given autosuggest control. 
 * @scope protected
 * @param oAutoSuggestControl The autosuggest control to provide suggestions for.
 */
StateSuggestions.prototype.requestSuggestions = function (oAutoSuggestControl /*:AutoSuggestControl*/,
                                                          bTypeAhead /*:boolean*/) {
    var aSuggestions = [];
    var sTextboxValue = oAutoSuggestControl.textbox.value;
    var cntkey = 0;
    if (sTextboxValue.length > 0){
    
        //search for matching states
        for (var i=0; i < this.states.length; i++) { 
            if(parseInt(cntkey) > 50)
            {
                break;
            }
            else if (this.states[i].toLowerCase().indexOf(sTextboxValue.toLowerCase()) == 0) {
                aSuggestions.push(this.states[i]);
                cntkey = parseInt(cntkey)+1;
            } 
           
        }
    }
    
    //provide suggestions to the control
    oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
};

