//<script LANGUAGE="javascript">
	//<!--
	function PreferenceWithOption_OnClick(pThis)	{
		var vlChecked = pThis.checked
		var vlInd = 0
		for (vlInd = 1; vlInd < 10; vlInd++) {
			var vlOption = document.getElementById("<%=ccOptionName%>_" + pThis.value + "_" + vlInd)
			if (vlOption == null) {	return }
			else {
				vlOption.disabled = !vlChecked
				if (!vlChecked) { vlOption.checked = false; }
			}
		}
	}
		
	function PreferenceCitiesList(pChecked) {
		document.getElementById("tblCities").disabled = !pChecked
	}

	function SelectCities_OnClick(lang) {
		if (!document.getElementById("tblCities").disabled) {
			var vlSelectedCities = document.getElementById("hRegistrationForm_Cities").value;
			newwin = window.open ("RegistrationForm_SelectCities.html?hSelectCities_Cities=" + vlSelectedCities, lang ,"resizable=no,toolbar=no,status=0,height=450px,width=665px");
			newwin.focus();
		}
	}
		
	function EditCity() {
		if (!document.getElementById("tblCities").disabled) {
			alert(document.getElementById("hRegistrationForm_Cities").value)
		}
	}
		
	function RemoveCity(pCityID) {
		var vloCities = document.getElementById("hRegistrationForm_Cities")
		var vltblCities = document.getElementById("tblCities")
		var vloCity = document.getElementById("txt" + pCityID)
		vltblCities.deleteRow(vloCity.rowIndex)
		vloCities.value = vloCities.value.replace("," + pCityID + ",",",")
		if (vloCities.value == ",") vloCities.value = "";
	}
		
	function NoCitySelected(pValue) {
		return (pValue.search("(\\d)+") == -1)
	}
	
	function valid()
	{
		var chk;
		var bValid = true;
		var temp;
		var lblErrorTitle;
		var lblErrorStory;
		var lblErrorCheck;
		
		SiteLanguage = document.getElementById("hdLanguage").value;
		
		if(SiteLanguage == "fr")
		{
			lblErrorTitle = "<li>Vous devez entrer un titre &#224; votre histoire pour continuer.</li>";
			lblErrorStory = "<li>Vous devez entrer une histoire pour continuer.</li>";
			lblErrorCheck = "<li>Vous devez cocher la case pour &#234;tre &#233;ligible au concours.</li>";
		}
		else
		{
			lblErrorTitle = "<li>You must enter a title for your story to continue.</li>";
			lblErrorStory = "<li>You must enter your story to continue.</li>";
			lblErrorCheck = "<li>You must check this box to be eligible for the contest.</li>";
		}
		
		chk = document.getElementById("ckAuthorized");
		document.getElementById("error").innerHTML = "";
	
		
		if(document.getElementById("hdTitle").value.length == 0)
		{
			document.getElementById("error").innerHTML = document.getElementById("error").innerHTML + lblErrorTitle;
			bValid = false;
		}

		if(document.getElementById("hdAnswer").value.length == 0)
		{
			document.getElementById("error").innerHTML = document.getElementById("error").innerHTML + lblErrorStory;
			bValid = false;
		}		
		
		if(chk.checked == false)
		{
			document.getElementById("error").innerHTML = document.getElementById("error").innerHTML + lblErrorCheck;
			bValid = false;
		}

		if(bValid == true)
			document.forms[0].submit();

	}
	
	function textCounter(field, countfield, maxlimit)
	{
		if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
		// otherwise, update 'characters left' counter
		else 
		countfield.value = maxlimit - field.value.length;
	}
	
	function wordCounter(field, countfield, maxlimit)
	{
		wordcounter=0;
		for (x=0;x<field.value.length;x++) 
		{
			if (field.value.charAt(x) == " " && field.value.charAt(x-1) != " ")  {wordcounter++}  // Counts the spaces while ignoring double spaces, usually one in between each word.
			if (wordcounter > 250) {field.value = field.value.substring(0, x);}
			else {countfield.value = maxlimit - wordcounter;}
		}
   }
   
   function setHidden(value)
   {
		if(parseInt(document.formStorySample.hdCurrentPage.value) + value < document.formStorySample.hdTotalPage.value || parseInt(document.formStorySample.hdCurrentPage.value) + value > 1) 
		{
			document.formStorySample.hdCurrentPage.value = parseInt(document.formStorySample.hdCurrentPage.value) + value;
			//alert(document.formStorySample.hdCurrentPage.value);
		}
		//Fin de la liste des stories
		if(parseInt(document.formStorySample.hdCurrentPage.value) > document.formStorySample.hdTotalPage.value) 
		{
			document.formStorySample.hdCurrentPage.value = 1;
			//alert(document.formStorySample.hdCurrentPage.value);
		}	
		//Debut de la liste des stories
		if(parseInt(document.formStorySample.hdCurrentPage.value) < 1) 
		{
			document.formStorySample.hdCurrentPage.value = document.formStorySample.hdTotalPage.value;
			//alert(document.formStorySample.hdCurrentPage.value);
		}
   }
   
   function langue()
   {

		var the_url = document.URL;

		if (the_url.indexOf("/en/", 0)!=-1){

			document.location = the_url.replace(/((?:\/)|(?:%2F))en\1/gi, "$1fr$1");

		}	

		else if (the_url.indexOf("/de/", 0)!=-1){

			document.location = the_url.replace(/((?:\/)|(?:%2F))de\1/gi, "$1fr$1");

		}	

		else if (the_url.indexOf("/fr/", 0)!=-1){

			document.location = the_url.replace(/((?:\/)|(?:%2F))fr\1/gi, "$1en$1");

		}

		else {

		}	

	}
   
   //Ajax script
	var xmlHttp;
	var IsValidating = false;
	var IsValidated = false;
	var strHTML
	
	function validateFormat(intPage,targetURL) {;
		IsValidating = true;
		IsValidated = false;
		if (intPage == 0) {
			intPage =1 
		}
		if (intPage == null) { 
		  document.getElementById("StoryContent").innerHTML="";
		  document.getElementById("StoryTitle").innerHTML="";
		  return;
		}
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
		} 
		
		//Get the url from the header
		var url = window.location.href;
		var page;
		var size;
		
		//Remove the end of the string and adjust the URL to get the current story
		/*page = url.split("/");
		size = page.length - 1;
		url = url.replace(page[size],"");
		url = url + "stories/" + intPage + ".htm";*/
		url = targetURL + intPage + ".htm";

		
		//Hardcoded URL version
		//var url="http://www.dev.cirquedusoleil.com/CirqueDuSoleil/en/contest/wintuk/stories/";
				
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	} 



	function stateChanged() { 
		if (xmlHttp.readyState==4) {
			IsValidating = false;
			IsValidated = true;
						
			//Parse Body
			strHTML = xmlHttp.responseText;
			
			//Parse Title
			var myarray;	
			var arrayTitle;
			var sizeArray;
			var storyTitle;
			var arrayStory;
			var arrayFullStory;
			var SiteLanguage;
			var lblStory;
			var lblStoryOf;
			var blnFullStory;
			var strFullStory;
			var strShortStory;
			var fullURL;
			var param;
			var paramValue;
			
			
			myarray = strHTML.split("[TITLE]");
			sizeArray = myarray.length - 1;

			if(sizeArray>0)
			{	
				arrayTitle = myarray[1].split("[/TITLE]")
				sizeArray = arrayTitle.length - 1;
				
				if(sizeArray>0)
				{
					storyTitle = arrayTitle[0]
				}
			}
			
			//Remove Title from Body
			strHTML = strHTML.replace("[TITLE]" + storyTitle + "[/TITLE]","")	
							
			//Parse Short Story
			myarray = strHTML.split("[STORY]")
			sizeArray = myarray.length - 1;
			if(sizeArray > 0)
			{
				arrayStory = myarray[1].split("[/STORY]")
				sizeArray = arrayStory.length - 1;
				if(sizeArray > 0)
				{
					strShortStory = arrayStory[0]
				}
			}
			
			//Parse Full Story
			myarray = strHTML.split("[STORY_FULL]")
			sizeArray = myarray.length - 1;
			if(sizeArray > 0)
			{
				arrayFullStory = myarray[1].split("[/STORY_FULL]")
				sizeArray = arrayFullStory.length - 1;
				if(sizeArray > 0)
				{
					strFullStory = arrayFullStory[0];
				}
			}
			
			fullURL = parent.document.URL;
			//alert(fullURL)
			param = fullURL.substring(fullURL.indexOf('?')+1, fullURL.length);
			//alert(param) 
			paramValue = param.substring(param.indexOf('=')+1, param.length); 
			//alert(paramValue)
			if(param == "s=" + paramValue)
			{
				blnFullStory = true //Full Story
			}
			else
			{
				blnFullStory = false //Short Story
			}
						
			if(blnFullStory == true)
			{
				if(strFullStory != null)
				{
					strHTML = strFullStory
					//Remove the short story from the content
					strHTML = strHTML.replace("[STORY]" + strShortStory + "[/STORY]","")
				}
				//document.formStorySample.hdFullStory.value = true;
			}
			else
			{
				if(strShortStory != null)
				{
					strHTML = strShortStory
					//Remove the short story from the content
					strHTML = strHTML.replace("[STORY_FULL]" + strFullStory + "[/STORY_FULL]","")
				}
				//document.formStorySample.hdFullStory.value = false;
			}
			
			SiteLanguage = document.getElementById("hdLanguage").value;
			if(SiteLanguage == "fr")
			{
				lblStory = "Histoire";
				lblStoryOf = "de";
			}
			else
			{
				lblStory = "Story";
				lblStoryOf = "of";
			}
			
			document.getElementById("StoryContent").innerHTML=strHTML;
			document.getElementById("StoryTitle").innerHTML= lblStory + " " + document.formStorySample.hdCurrentPage.value + " " + lblStoryOf + " " + document.formStorySample.hdTotalPage.value;
			//document.getElementById("StoryTitle").innerHTML=storyTitle + " - " + lblStory + " " + document.formStorySample.hdCurrentPage.value + " " + lblStoryOf + " " + document.formStorySample.hdTotalPage.value;
		}
	}

	function GetXmlHttpObject() {
		var xmlHttp=null;
		try {
		  // Firefox, Opera 8.0+, Safari
		  xmlHttp=new XMLHttpRequest();
		} catch (e) {

		  // Internet Explorer
		  try {
		    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		  } catch (e) {
		    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		}
		return xmlHttp;
	}
		
//-->
