/* 
 This file was generated by Dashcode.  
 You may edit this file to customize your widget or web page 
 according to the license.txt file included in the project.
 */

var country = [];
var states = [];
var cities = [];
var theState = "";
var theCity = "";

////////////////////////////////////////////////////////////////
var listController = {
    // This object acts as a controller for the list UI.
    // It implements the dataSource methods for the list.
    
    numberOfRows: function() {
        // The List calls this dataSource method to find out how many rows should be in the list.
        return selectCountries.length;
    },
    
    prepareRow: function(rowElement, rowIndex, templateElements) {
        // The List calls this dataSource method for every row.  templateElements contains references to all elements inside the template that have an id. We use it to fill in the text of the rowTitle element.
        if (templateElements.rowTitle) {
            templateElements.rowTitle.innerText = selectCountries[rowIndex].name;
        }

        // We also assign an onclick handler that will cause the browser to go to the detail page.
        var self = this;
        var handler = function() {
            country = selectCountries[rowIndex];
            states = selectStates(country.location);
            //citiesListController.prepareRow(country);
            var browser = document.getElementById('browser').object;
            // The Browser's goForward method is used to make the browser push down to a new level.  Going back to previous levels is handled automatically.
            browser.goForward(document.getElementById('statesList'), country.name);
            document.getElementById("list2").object.reloadData();
        };
        rowElement.onclick = handler;
    }
};

////////////////////////////////////////////////////////////////
var statesListController = {
    // This object acts as a controller for the list UI.
    // It implements the dataSource methods for the list.
    
    numberOfRows: function() {
        // The List calls this dataSource method to find out how many rows should be in the list.
        return states.length;
    },
    
    prepareRow: function(rowElement, rowIndex, templateElements) {
        // The List calls this dataSource method for every row.  templateElements contains references to all elements inside the template that have an id. We use it to fill in the text of the rowTitle element.
        if (templateElements.stateLabel) {
            templateElements.stateLabel.innerText = states[rowIndex];
        }

        // We also assign an onclick handler that will cause the browser to go to the detail page.
        var self = this;
        var handler = function() {
            //var country = countries[rowIndex];
            //theState=states[rowIndex];
            cities = selectCities(country.location,states[rowIndex]);
            //citiesListController.prepareRow(country);
            var browser = document.getElementById('browser').object;
            // The Browser's goForward method is used to make the browser push down to a new level.  Going back to previous levels is handled automatically.
            browser.goForward(document.getElementById('citiesList'), states[rowIndex]);
            document.getElementById("list1").object.reloadData();
        };
        rowElement.onclick = handler;
    }
};

////////////////////////////////////////////////////////////////
var citiesListController = {

    numberOfRows: function() {
        // The List calls this dataSource method to find out how many rows should be in the list.
        return cities.length;
    },
    
    prepareRow: function(rowElement, rowIndex, templateElements) {
        // The List calls this dataSource method for every row.  templateElements contains references to all elements inside the template that have an id. We use it to fill in the text of the rowTitle element.
        if (templateElements.cityLabel) {
            templateElements.cityLabel.innerText = cities[rowIndex].n;
        }

        // We also assign an onclick handler that will cause the browser to go to the detail page.
        var self = this;
        var handler = function() {
            theCity = cities[rowIndex];
            detailController.setcity(theCity);
            var browser = document.getElementById('browser').object;
            // The Browser's goForward method is used to make the browser push down to a new level.  Going back to previous levels is handled automatically.
            browser.goForward(document.getElementById('detailLevel'), theCity.n);
        };
        rowElement.onclick = handler;
    }
};

////////////////////////////////////////////////////////////////
var detailController = {
    // This object acts as a controller for the detail UI.
    
    setcity: function(city) {
        this._city = city;
        this._representedObject = city.n;
        
        // When the country is set, this controller also updates the DOM for the detail page appropriately.  As you customize the design for the detail page, you will want to extend this code to make sure that the correct information is populated into the detail UI.
        //var detailTitle = document.getElementById('detailTitle');
        //detailTitle.innerHTML = this._city.n;
        var detailLocation = document.getElementById('detailLocation');
        detailLocation.innerHTML = country.location + ',' + this._city.l;
        var detailDescription = document.getElementById('detailDescription');
        detailDescription.innerHTML = "<div dir=rtl>١) ﺍﺿﻐﻂ ﻋﻠﻰ ﺍﻟﺰﺭ ﻓﻲ ﺍﻷﺳﻔﻞ ﻟﻌﺮﺽ ﺻﻮﺭﺓ ﺍﻟﺠﺪﻭﻝ<br>٢) ﺑﻌﺪ ﺫﻟﻚ، ﺍﺿﻐﻂ ﻋﻠﻰ ﺍﻟﺼﻮﺭﺓ ﺣﺘﻰ ﺗﻈﻬﺮ ﺍﻟﺨﻴﺎﺭﺍﺕ<br> ٣) ﺍﺧﺘﺮ ﺣﻔﻆ ﺍﻟﺼﻮﺭﺓ<br> ٤) ﺷﻐﻞ ﺑﺮﻧﺎﻣﺞ ﺍﻟﺼﻮﺭ ﻭﻋﻴﻦ ﺍﻟﺼﻮﺭﺓ ﺍﻟﻤﺤﻔﻮﻇﺔ ﻛﺨﻠﻔﻴﺔ <br><center><br>ﻭﻻ ﺗﻨﺴﻰ ﺇﺿﺎﻓﺔ ﻋﻨﻮﺍﻥ ﺍﻟﺼﻮﺭﺓ ﺇﻟﻰ ﺍﻟﻤﻔﻀﻼﺕ ﻓﻲ ﻣﺘﺼﻔﺢ ﺍﻵﻱ ﻓﻮﻥ، ﻭﺫﻟﻚ ﻟﺘﻌﻮﺩ ﺇﻟﻴﻬﺎ ﺍﺳﺒﻮﻋﻴﺎً</div>";
    }
};

function dstToggle(event)
{
    var DSTime = document.getElementById('checkboxbutton1');
    DSTime.checked=!DSTime.checked;
}

function setTheImage(event) {
    var detailLocation = document.getElementById('detailLocation');
    var CalcMethod = document.getElementById('CalcMethod');
    var DSTime = document.getElementById('checkboxbutton1');
    var DST=0;
    if (DSTime.checked==true) {DST=1;}
    location.href='http://isalawat.com/weeklysch.php?cnt=' + detailLocation.innerHTML + ',' + CalcMethod.value + ',' + DST;

}
//
// Function: load()
// Called by HTML body element's onload event when the web application is ready to start
//
function load()
{
    dashcode.setupParts();
}

/*function selectCities(country)
{
	if (country == "0"){
		return [
            { name: "Abqaiq", location: "0" },
            { name: "Atawlah", location: "1" },
            { name: "Abha", location: "2" }];
	}
	else if (country == "1"){
		return [
            { name: "Kabul", location: "0" },
            { name: "Swat", location: "1" },
            { name: "Bab", location: "2" }];
	}
	else if (country == "2"){
		return [
            { name: "X1", location: "0" },
            { name: "X2", location: "1" },
            { name: "X3", location: "2" }];
	}
	else if (country == "3"){
		return [
            { name: "Y1", location: "0" },
            { name: "Y2", location: "1" },
            { name: "Y3", location: "2" }];
	}
	else {
	   return [{ name: "Oops!", location: "0" }];
	} 
}
*/

// Sample data.  Some applications may have static data like this, but most will want to use information fetched remotely via XMLHttpRequest.
var selectCountries = [
    { name: "Saudi Arabia", location: "0" },
{ name: "Afghanistan", location: "1" },
{ name: "Albania", location: "2" },
{ name: "Algeria", location: "3" },
{ name: "Andorra", location: "4" },
{ name: "Angola", location: "5" },
{ name: "Anguilla", location: "6" },
{ name: "Antarctica", location: "7" },
{ name: "Antigua Barbuda", location: "8" },
{ name: "Argentina", location: "9" },
{ name: "Armenia", location: "10" },
{ name: "Aruba", location: "11" },
{ name: "Ashmore Cartier Islands", location: "12" },
{ name: "Australia", location: "13" },
{ name: "Austria", location: "14" },
{ name: "Azerbaijan", location: "15" },
{ name: "Bahamas", location: "16" },
{ name: "Bahrain", location: "17" },
{ name: "Bangladesh", location: "18" },
{ name: "Barbados", location: "19" },
{ name: "Bassas De India", location: "20" },
{ name: "Belarus", location: "21" },
{ name: "Belgium", location: "22" },
{ name: "Belize", location: "23" },
{ name: "Benin", location: "24" },
{ name: "Bermuda", location: "25" },
{ name: "Bhutan", location: "26" },
{ name: "Bolivia", location: "27" },
{ name: "Bosnia Herzegovina", location: "28" },
{ name: "Botswana", location: "29" },
{ name: "Bouvet Island", location: "30" },
{ name: "Brazil", location: "31" },
{ name: "British Indian Ocean Territory", location: "32" },
{ name: "British Virgin Islands", location: "33" },
{ name: "Brunei Darussalam", location: "34" },
{ name: "Bulgaria", location: "35" },
{ name: "Burkina Faso", location: "36" },
{ name: "Burma", location: "37" },
{ name: "Burundi", location: "38" },
{ name: "Canada", location: "39" },
{ name: "Cambodia", location: "40" },
{ name: "Cameroon", location: "41" },
{ name: "Cape Verde", location: "42" },
{ name: "Cayman Islands", location: "43" },
{ name: "Central African Republic", location: "44" },
{ name: "Chad", location: "45" },
{ name: "Chile", location: "46" },
{ name: "China", location: "47" },
{ name: "Christmas Island", location: "48" },
{ name: "Clipperton Island", location: "49" },
{ name: "Cocos Islands", location: "50" },
{ name: "Colombia", location: "51" },
{ name: "Comoros", location: "52" },
{ name: "Congo", location: "53" },
{ name: "Congo Democratic Republic", location: "54" },
{ name: "Cook Islands", location: "55" },
{ name: "Coral Sea Islands", location: "56" },
{ name: "Costa Rica", location: "57" },
{ name: "Cote Dlvoire", location: "58" },
{ name: "Croatia", location: "59" },
{ name: "Cuba", location: "60" },
{ name: "Cyprus", location: "61" },
{ name: "Czech Republic", location: "62" },
{ name: "Denmark", location: "63" },
{ name: "Djibouti", location: "64" },
{ name: "Dominica", location: "65" },
{ name: "Dominican Republic", location: "66" },
{ name: "East Timor", location: "67" },
{ name: "Ecuador", location: "68" },
{ name: "Egypt", location: "69" },
{ name: "El Salvador", location: "70" },
{ name: "Equatorial Guinea", location: "71" },
{ name: "Eritrea", location: "72" },
{ name: "Estonia", location: "73" },
{ name: "Ethiopia", location: "74" },
{ name: "Europa Island", location: "75" },
{ name: "Falkland Islands Malvinas", location: "76" },
{ name: "Faroe Islands", location: "77" },
{ name: "Fiji", location: "78" },
{ name: "Finland", location: "79" },
{ name: "France", location: "80" },
{ name: "French Guiana", location: "81" },
{ name: "French Polynesia", location: "82" },
{ name: "French Southern Antarctic Lands", location: "83" },
{ name: "Gabon", location: "84" },
{ name: "Gambia", location: "85" },
{ name: "Georgia", location: "86" },
{ name: "Germany", location: "87" },
{ name: "Ghana", location: "88" },
{ name: "Gibraltar", location: "89" },
{ name: "Glorioso Islands", location: "90" },
{ name: "Greece", location: "91" },
{ name: "Greenland", location: "92" },
{ name: "Grenada", location: "93" },
{ name: "Guadeloupe", location: "94" },
{ name: "Guam", location: "95" },
{ name: "Guatemala", location: "96" },
{ name: "Guernsey", location: "97" },
{ name: "Guinea", location: "98" },
{ name: "Guinea Bissau", location: "99" },
{ name: "Guyana", location: "100" },
{ name: "Haiti", location: "101" },
{ name: "Heard Island Mcdonald Islands", location: "102" },
{ name: "Honduras", location: "103" },
{ name: "Hong Kong", location: "104" },
{ name: "Hungary", location: "105" },
{ name: "Iceland", location: "106" },
{ name: "India", location: "107" },
{ name: "Indonesia", location: "108" },
{ name: "Iran", location: "109" },
{ name: "Iraq", location: "110" },
{ name: "Ireland", location: "111" },
{ name: "Isle Of Man", location: "112" },
{ name: "Italy", location: "113" },
{ name: "Jamaica", location: "114" },
{ name: "Jan Mayen", location: "115" },
{ name: "Japan", location: "116" },
{ name: "Jersey", location: "117" },
{ name: "Jordan", location: "118" },
{ name: "Juan De Nova Island", location: "119" },
{ name: "Kazakstan", location: "120" },
{ name: "Kenya", location: "121" },
{ name: "Kiribati", location: "122" },
{ name: "Kuwait", location: "123" },
{ name: "Kyrgyzstan", location: "124" },
{ name: "Lao Peoples Democratic Republic", location: "125" },
{ name: "Latvia", location: "126" },
{ name: "Lebanon", location: "127" },
{ name: "Lesotho", location: "128" },
{ name: "Liberia", location: "129" },
{ name: "Libya", location: "130" },
{ name: "Liechtenstein", location: "131" },
{ name: "Lithuania", location: "132" },
{ name: "Luxembourg", location: "133" },
{ name: "Macau", location: "134" },
{ name: "Macedonia", location: "135" },
{ name: "Madagascar", location: "136" },
{ name: "Malawi", location: "137" },
{ name: "Malaysia", location: "138" },
{ name: "Maldives", location: "139" },
{ name: "Mali", location: "140" },
{ name: "Malta", location: "141" },
{ name: "Marshall Islands", location: "142" },
{ name: "Martinique", location: "143" },
{ name: "Mauritania", location: "144" },
{ name: "Mauritius", location: "145" },
{ name: "Mayotte", location: "146" },
{ name: "Mexico", location: "147" },
{ name: "Micronesia", location: "148" },
{ name: "Moldova", location: "149" },
{ name: "Monaco", location: "150" },
{ name: "Mongolia", location: "151" },
{ name: "Montserrat", location: "152" },
{ name: "Morocco", location: "153" },
{ name: "Mozambique", location: "154" },
{ name: "Namibia", location: "155" },
{ name: "Nauru", location: "156" },
{ name: "Nepal", location: "157" },
{ name: "Netherlands", location: "158" },
{ name: "Netherlands Antilles", location: "159" },
{ name: "New Caledonia", location: "160" },
{ name: "New Zealand", location: "161" },
{ name: "Nicaragua", location: "162" },
{ name: "Niger", location: "163" },
{ name: "Nigeria", location: "164" },
{ name: "Niue", location: "165" },
{ name: "No Mans Land", location: "166" },
{ name: "Norfolk Island", location: "167" },
{ name: "North Korea", location: "168" },
{ name: "Norway", location: "169" },
{ name: "Oceans", location: "170" },
{ name: "Oman", location: "171" },
{ name: "Pakistan", location: "172" },
{ name: "Palau", location: "173" },
{ name: "Palestine", location: "174" },
{ name: "Panama", location: "175" },
{ name: "Papua New Guinea", location: "176" },
{ name: "Paracel Islands", location: "177" },
{ name: "Paraguay", location: "178" },
{ name: "Peru", location: "179" },
{ name: "Philippines", location: "180" },
{ name: "Pitcairn Islands", location: "181" },
{ name: "Poland", location: "182" },
{ name: "Portugal", location: "183" },
{ name: "Puerto Rico", location: "184" },
{ name: "Qatar", location: "185" },
{ name: "Reunion", location: "186" },
{ name: "Romania", location: "187" },
{ name: "Russia", location: "188" },
{ name: "Rwanda", location: "189" },
{ name: "Saint Helena", location: "190" },
{ name: "Saint Kitts Nevis", location: "191" },
{ name: "Saint Lucia", location: "192" },
{ name: "Saint Pierre Miquelon", location: "193" },
{ name: "Saint Vincent Grenadines", location: "194" },
{ name: "Samoa", location: "195" },
{ name: "San Marino", location: "196" },
{ name: "Sao Tome And Principe", location: "197" },
{ name: "Senegal", location: "198" },
{ name: "Seychelles", location: "199" },
{ name: "Sierra Leone", location: "200" },
{ name: "Singapore", location: "201" },
{ name: "Slovakia", location: "202" },
{ name: "Slovenia", location: "203" },
{ name: "Solomon Islands", location: "204" },
{ name: "Somalia", location: "205" },
{ name: "South Africa", location: "206" },
{ name: "South Georgia The South Sandwitch Islands", location: "207" },
{ name: "South Korea", location: "208" },
{ name: "Spain", location: "209" },
{ name: "Spratly Islands", location: "210" },
{ name: "Sri Lanka", location: "211" },
{ name: "Sudan", location: "212" },
{ name: "Suriname", location: "213" },
{ name: "Svalbard And Jan Mayen", location: "214" },
{ name: "Swaziland", location: "215" },
{ name: "Sweden", location: "216" },
{ name: "Switzerland", location: "217" },
{ name: "Syria", location: "218" },
{ name: "Taiwan", location: "219" },
{ name: "Tajikistan", location: "220" },
{ name: "Tanzania", location: "221" },
{ name: "Thailand", location: "222" },
{ name: "Togo", location: "223" },
{ name: "Tokelau", location: "224" },
{ name: "Tonga", location: "225" },
{ name: "Trinidad Tobago", location: "226" },
{ name: "Tromelin Island", location: "227" },
{ name: "Tunisia", location: "228" },
{ name: "Turkey", location: "229" },
{ name: "Turkmenistan", location: "230" },
{ name: "Turks Caicos Islands", location: "231" },
{ name: "Tuvalu", location: "232" },
{ name: "Uganda", location: "233" },
{ name: "Ukraine", location: "234" },
{ name: "Under Sea Features", location: "235" },
{ name: "United Arab Emirates", location: "236" },
{ name: "United Kingdom", location: "237" },
{ name: "Uruguay", location: "238" },
{ name: "Us Virgin Islands", location: "239" },
{ name: "USA", location: "240" },
{ name: "Uzbekistan", location: "241" },
{ name: "Vanuatu", location: "242" },
{ name: "Vatican City", location: "243" },
{ name: "Venezuela", location: "244" },
{ name: "Viet Nam", location: "245" },
{ name: "Wallis Futuna", location: "246" },
{ name: "West Bank", location: "247" },
{ name: "Yemen", location: "248" },
{ name: "Yugoslavia", location: "249" },
{ name: "Zambia", location: "250" },
{ name: "Zimbabwe", location: "251" }
];


