/******************************************
 * @author Maria A. Zamora
 * @company Digitec Interactive Inc.
 * @version 0.1
 * @date 12/14/2010
 *
 * BaseCEE class is the Super class of all pages for  CEE application
 * Home, About, Search, lessons & Concept class will extend BaseCEE
 * CS5 version of com.digitec.cee.BaseCEE
 *
 *******************************************/
package com.digitec.cee {
	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.events.*;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.display.LoaderInfo;
	import flash.net.*;

	//import flash.errors.IllegalOperationError;	


	public class BaseCEE extends MovieClip {

		private var _xmlPath: String;

		public static const HOMEPAGE: String = MainConstants.HOMEPAGE;
		public static const ABOUT: String = MainConstants.ABOUT;
		public static const CONCEPTS: String = MainConstants.CONCEPTS;
		public static const SEARCH: String = MainConstants.SEARCH;
		public static const LESSONS: String = MainConstants.LESSONS;
		public static const PUBS: String = MainConstants.PUBS;

		private var xmlMovie: String;



		public function BaseCEE(xmlstr: String) {
			//super();
			xmlMovie = xmlstr;
			setupListeners();
		}

		/*******************************************************************
		 * FUNCTION:  SET UP ALL LISTENERS
		 *******************************************************************/
		private function setupListeners(): void {
			addEventListener(Event.ADDED_TO_STAGE, init);
		}

		/*******************************************************************
		 * FUNCTION:  TO INITIALIZE APPLICATION
		 *******************************************************************/

		private function init(e: Event): void {
			removeEventListener(Event.ADDED_TO_STAGE, init);
			loadXML();
		}

		/*******************************************************************
		 * FUNCTION:  TO LOAD TEXT FOR TEXTFIELDS FROM A XML FILE
		 *******************************************************************/
		private function loadXML(): void {
			var vidpicpath = Object(parent).getDpath();

			_xmlPath = vidpicpath + "_VE50DATA/" + MainConstants.XMLPATH + xmlMovie;
			//_xmlPath = MainConstants.XMLPATH + xmlMovie;		
			var xmlLoaderobj: XMLLoader = new XMLLoader();
			xmlLoaderobj.loadXML(_xmlPath, 'xml0');
			xmlLoaderobj.addEventListener(CustomEvent.XMLLoaded, XMLLoaded);
			function XMLLoaded(evt: CustomEvent) {
				if (evt.XMLRef == 'xml0') {
					var _xml: XML = new XML(evt.XMLData);
					//_xml.ignoreWhite = true;					
					setFramesText(_xml);
				}
			}
		}

		/*************************************************************************************************************
		 * FUNCTION TO BE OVERRIDE IT FOR HOME, ABOUT, CONCEPTS, SEARCH & LESSONS
		 *************************************************************************************************************/
		public function setFramesText(_xml: XML): void {}


		/*************************************************************************************************************
		 * FUNCTIONS:  GO TO PAGES HOME, ABOUT, CONCEPTS, SEARCH & LESSONS
		 *************************************************************************************************************/
		//go to HOME page
		public function gotoHomeFrm(evt: MouseEvent): void {
			Object(parent).gotoPage(HOMEPAGE);
		}

		//go to ABOUT page
		public function gotoAboutFrm(evt: MouseEvent): void {
			Object(parent).gotoPage(ABOUT);
		}

		//go to CONCEPTS page
		public function gotoConceptsFrm(evt: MouseEvent): void {
			Object(parent).gotoPage(CONCEPTS);
		}
		//Register DAVE Code
		public function onRegisterDown(evt: MouseEvent): void {
			var myDate = new Date();
			trace(myDate);
			var unixTime = Math.round(myDate.getTime() / 1000);
			trace("unixTime" + unixTime);
			var dw_linkvar = "http://ve.councilforeconed.org/register/check.php?v=4.0&t="
			trace(dw_linkvar + unixTime + "]");
			var url: String = dw_linkvar + unixTime;
			var request: URLRequest = new URLRequest(url);
			try {
				navigateToURL(request, '_blank'); // second argument is target
			} catch (e: Error) {
				trace("Error occurred!");
			}
		}
		//go to SEARCH page
		public function gotoSearchFrm(evt: MouseEvent): void {
			Object(parent).gotoPage(SEARCH);
		}

		//go to LESSONS page
		public function gotoLessonsFrm(evt: MouseEvent): void //onPageJumpClick
		//public function gotoLessonsFrm( concept:ConceptItem) :void
		{
			Object(parent).gotoPage(LESSONS);
			//Object(parent).setConceptLesson( concept );			
		}

		//go to SEARCH page
		public function gotoPubsFrm(evt: MouseEvent): void {
			Object(parent).gotoPage(PUBS);
		}

		//go to BACK to last page
		public function gotoLastFrm(evt: MouseEvent): void {
			Object(parent).gotoLastPage();
		}

		//go to LESSONS page and fill concept		
		public function gotoConceptLessons(concept: ConceptItem): void {
			trace("-----------------------------BASE= " + concept.conceptID);
			Object(parent).setConceptLesson(concept);
		}

		//go to BACK to last page
		public function onCloseClick(evt: MouseEvent): void {
			Object(parent).closeApplication();
		}


	} // Base CEE class

} //end package