// info@capeseo.com


	tacu = '';
	tacu1 = '';
	tacu2 = '';
	tacu3 = '';
	function slideupdown(name)
	{


        if(tacu != 1 ) 
        {
         Effect.SlideDown(name);
         tacu = 1;
    	    }		
			else{
        	 Effect.SlideUp(name);
			 tacu = 0;	
			}

   	
	}

	function slideupdown2(name)
	{

        if(name == 'reservations'){
         	if(tacu2 == 1)Effect.SlideUp('enquiries');
	    	if(tacu3 == 1)Effect.SlideUp('bookings');
            tacu1 = 1;
			tacu2 = 0;
			tacu3 = 0;

         }
         if(name == 'enquiries'){
	    	if(tacu3 == 1)Effect.SlideUp('bookings');
			if(tacu1 == 1)Effect.SlideUp('reservations'); 
            tacu2 = 1;
        	tacu1 = 0;
			tacu3 = 0;
   
         }
         if(name == 'bookings'){
 	     	if(tacu2 == 1)Effect.SlideUp('enquiries');
			if(tacu1 == 1)Effect.SlideUp('reservations'); 
            tacu3 = 1;
        	tacu1 = 0;
			tacu2 = 0;
   
         }
         Effect.SlideDown(name);
   	
	}
   function onEnter( evt, frm ) {
	var keyCode = null;
	
	if( evt.which ) {
	keyCode = evt.which;
	} else if( evt.keyCode ) {
	keyCode = evt.keyCode;
	}
	if( 13 == keyCode ) {
	frm.btnEnter.click();
	return false;
	}
	return true;
	}


text = new Array(); //This array will hold variables to tell the script the state that it should switch to

	function switchState(id,pid,name)
	{

        var content = ''; 
        if(text[id] != 1 ) //Check if text['id'] is set to 1 (explained later)
        {
                content = document.getElementById('child' + id).innerHTML; //Define content as the inner content of the div
                content = content.replace(/<em>/g, '');
                content = content.replace(/<\/em>/g, '');
                new_html = '<input type="text" id="child' + id + '" value="' + content + '" onchange="saveinput(' + id + ')">'; //Define the new HTML (textbox)
                document.getElementById('parent' + id).innerHTML = new_html; //Set the parent div's HTML to the new HTML
                text[id] = 1; //We set this variable for the script to remember that we already set it to a text box
        }		
		else{
		saveinput(id,pid,name);
		}


   	
	}

	function addOption(selectbox,text,value )
	{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
	}
  	function saveinput(id,pid,name)
   	{
                var content = ''; 
     //So with this case we will be doing the opposite and switching back to a div
                content = document.getElementById('child' + id).value; //Define content as the value of the textbox
				content = content.replace(/&/g, '@12');
				content = content.replace(/\//g, '@2f');
				if(!content)content = 'Null';
			    ajaxUpdater('update','/properties/save/' + pid + '/' + name + '/' + content);

				content = content.replace(/\@2f/g, '/');
				content = content.replace(/@12/g, '&');
                new_html = '<div id="child' + id + '">' + content + '</div>'; //Define the new HTML (div)
				if(name == 'allurelink')new_html = '<img src="/img/logo-allure.png" alt="">';
                document.getElementById('parent' + id).innerHTML = new_html; //Set the parent div's HTML to the new HTML
                text[id] = 0; 
	}


	function switchState2(id,pid,name)
	{
	        content2 = ''; //Nullify the content variable
        if( text[id] != 1 ) //Check if text['id'] is set to 1 (explained later)
        {
                content2 = document.getElementById('child2' + id).innerHTML; //Define content as the inner content of the div
                content2 = content2.replace(/<em>/g, '');
                content2 = content2.replace(/<\/em>/g, '');
			  new_html = '<select  id="child2' + id + '" onchange=savedropdown(' + id + ')><option value="0" >Select Type</option><option value="1" >Text</option><option value="2" >TextArea</option><option value="3" >Dropdown</option><option value="4" >Date</option><option value="5" >Amount</option></select>'; //Define the new HTML (textbox)
                document.getElementById('parent2' + id).innerHTML = new_html; //Set the parent div's HTML to the new HTML
                text[id] = 1; //We set this variable for the script to remember that we already set it to a text box
        }
       
	}
  	function savedropdown(id,pid,name)
	{
	
	n = document.getElementById('child2' + id).value;

	if(n == 1)content2 = 'Text Input';
	if(n == 2)content2 = 'Text Area';
	if(n == 3)content2 = 'DropDown';
	if(n == 4)content2 = 'Date Picker';
	if(n == 5)content2 = 'Amount';
	if(n == 0)content2 = 'Please Select';
	             //So with this case we will be doing the opposite and switching back to a div       
                new_html = '<div id="child2' + id + '">' + content2 + '</div>'; //Define the new HTML (div)
				 ajaxUpdater("update","/properties/save/" + id + "/"+ n);
				 if( n == 3)
			  {
				 ajaxUpdater("sidedropdown","/admin/site/wizards/dropdown/"+id);
				}
                document.getElementById('parent2' + id).innerHTML = new_html; //Set the parent div's HTML to the new HTML
                       text[id] = 0; 
        }
		
		function save_dropdown(id,value) {
      	ajaxUpdater("sidedropdown","/admin/site/wizards/dropdown/" + id + "/" + value);
	}



	text3 = new Array(); //This array will hold variables to tell the script the state that it should switch to
	

	function switchState3(id,pid,name)
	{
        content3 = ''; //Nullify the content variable
        if(text3[id] != 1 )         {
                content3 = document.getElementById('child' + id).innerHTML; //Define content as the inner content of the div
                content3 = content3.replace(/<br>/g, '\n');
                content3 = content3.replace(/<em>/g, '');
                content3 = content3.replace(/<\/em>/g, '');
				new_html3 = '<textarea id="child' + id + '" onchange="savetextarea(' + id + ')" style="width:97%">' + content3 + '</textarea>'; //Define the new HTML (textbox)
                document.getElementById('parent' + id).innerHTML = new_html3; //Set the parent div's HTML to the new HTML
                text3[id] = 1;         }		
		else
		{
		savetextarea(id,pid,name);
		}
   	
	}

	function savetextarea(id,pid,name)
    {

     //So with this case we will be doing the opposite and switching back to a div
                content3 = document.getElementById('child' + id).value; //Define content as the value of the textbox
				content3 = content3.replace(/&/g, '@12');
				content3 = content3.replace(/\//g, '@2f');
				content3 = content3.replace(/\n/g, '<br>');
				//content3 = escape(content3);
				if(!content3)content3 = 'Null';
			    ajaxUpdater('update','/properties/save/' + pid + '/' + name + '/' + content3);
				content3 = content3.replace(/\@2f/g, '/');
				content3 = content3.replace(/@12/g, '&');
				content3 = content3.replace(/\n/g, '<br>');
				//content3 = unescape(content3);
                new_html3 = '<div id="child' + id + '">' + content3 + '</div>'; //Define the new HTML (div)
                document.getElementById('parent' + id).innerHTML = new_html3; //Set the parent div's HTML to the new HTML
                text3[id] = 0; 
        

	}
       
       text4 = new Array(); //This array will hold variables to tell the script the state that it should switch to

 	function switchState4(id,pid,name)
	{
        content4 = ''; //Nullify the content variable
        if(text4[id] != 1 )         {
                content4 = document.getElementById('child' + id).innerHTML; //Define content as the inner content of the div
                content4 = content4.replace(/<br>/g, '\n');
                content4 = content4.replace(/<em>/g, '');
                content4 = content4.replace(/<\/em>/g, '');
				new_html4 = '<textarea id="child' + id + '" onchange="savetextarea(' + id + ')" style="width:97%">' + content4 + '</textarea>'; //Define the new HTML (textbox)
                document.getElementById('parent' + id).innerHTML = new_html4; //Set the parent div's HTML to the new HTML
                text4[id] = 1;         }		
		else
		{
		savetextarea5(id,pid,name);
		}
   	
	}

	function savetextarea5(id,pid,name)
    {

     //So with this case we will be doing the opposite and switching back to a div
                content1 = document.getElementById('child' + id).value; //Define content as the value of the textbox
				//content1 = escape(content1);
				content1 = content1.replace(/&/g, '@12');
				content1 = content1.replace(/\//g, '@2f');
				content1 = content1.replace(/\n/g, '<br>');
				if(!content1)content1 = 'Null';
			    ajaxUpdater('update','/pages/save/' + pid + '/' + name + '/' + content1);
				//alert('/pages/save/' + pid + '/' + name + '/' + content1);
				content1 = content1.replace(/\@2f/g, '/');
				content1 = content1.replace(/@12/g, '&');
				content1 = content1.replace(/\n/g, '<br>');
				//content1 = unescape(content1);
                new_html1 = '<div id="child' + id + '">' + content1 + '</div>'; //Define the new HTML (div)
                document.getElementById('parent' + id).innerHTML = new_html1; //Set the parent div's HTML to the new HTML
            	text4[id] = 0; 
        
	}
		function isValidEmail(strEmail){
		  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
		
		   // search email text for regular exp matches
		    if (strEmail.search(validRegExp) == -1) 
		   {
		     
		      return false;
		    } 
		    return true; 
		}

		function cempty(section,name){
		value = document.getElementById(name).value;
		if(value == '')
			{
			ajaxUpdater(section,'/owners/valid/Must not be Empty');
			return false;		
			}
		else
			{
			return true;
			}
		
		}
		function setempty(section){

			ajaxUpdater(section,'/owners/valid/empty');
		
		}

	function validate(){

        valid = true;
		if(cempty('vname','name')==false){valid = false;}else{ setempty('vname');}
		if(cempty('vsurname','surname')==false){valid = false;}else{ setempty('vsurname');}
		if(cempty('vtelephone','telephone')==false){valid = false;}else{ setempty('vtelephone');}
		if( isValidEmail(document.getElementById('email').value) == false){ajaxUpdater('vemail','/owners/valid/Email not Valid');valid = false;}else{ setempty('vemail');}
		if(document.getElementById('password2').value != '' && (document.getElementById('password').value != document.getElementById('password2').value))
		{ajaxUpdater('vpassword2','/owners/valid/Passwords not Match');valid = false;}
		else{ setempty('vpassword2');}

		if(valid == true)document.frm.submit();
	}
	function account(){

        valid = true;
		if(cempty('vname','data[Owner][name]')==false){valid = false;}else{ setempty('vname');}
		if(cempty('vsurname','data[Owner][surname]')==false){valid = false;}else{ setempty('vsurname');}
		if(cempty('vtelephone','data[Owner][telephone]')==false){valid = false;}else{ setempty('vtelephone');}
		if(valid == true)document.frm.submit();
	}


	function switchSelect(id,pid,name)
	{
        content = ''; //Nullify the content variable
        if(text[id] != 1 ) //Check if text['id'] is set to 1 (explained later)
        {
                content = document.getElementById('child' + id).innerHTML; //Define content as the inner content of the div
                new_html = '<select type="text" id="child' + id + '" value="' + content + '" onchange="saveinput(' + id + ')"><option>test</option></select>'; //Define the new HTML (textbox)
                document.getElementById('parent' + id).innerHTML = new_html; //Set the parent div's HTML to the new HTML
                text[id] = 1; //We set this variable for the script to remember that we already set it to a text box
        }
		
		else
		{
		saveinput(id,pid,name);
		}
   	
	}

      function ajaxUpdater(id,url) {
	  new Ajax.Updater(id,url, {asynchronous:true, evalScripts:true, onComplete:function(request, json) {Element.hide('spinner');}, onLoading:function(request) {Element.show('spinner');}, requestHeaders:['X-Update', 'CALCupdate']});		
    }

	function fadearea(id, color) {
	var item;
	if (document.getElementById) {
	item = document.getElementById(id);
	} else if (document.all) {
	item = document.all(id);
	}
	
	if (item && item.style) {
	item.style.backgroundColor = color;
	}
	
	item.disabled=true;
	
	}

	function getGroupOrder() 
	{
	var sorted = Sortable.serialize("imageFloatContainer");
	new Ajax.Updater('update','/files/oupdate?' + sorted);
	}


	function getTeamsOrder() 
	{
	var sorted = Sortable.serialize("imageFloatContainer");
	new Ajax.Updater('update','/teams/oupdate?' + sorted);
	}
	function getPartnersOrder() 
	{
	var sorted = Sortable.serialize("imageFloatContainer");
	new Ajax.Updater('update','/partners/oupdate?' + sorted);
	}


	function delPic(id) 
	{
	if (confirm("Are you sure you want to delete ?") )
	{
	new Ajax.Updater('update','/files/delete/' + id);
	myimg = document.getElementById("img_" + id);
	myimg.style.display = "none";
	}
	}
