

		
		/*------------------------------------------------------------------- DOCUMENT READY -----------------------------------------------------------------*/
		$j(document).ready(function(){
			searchBox.UseFreshCountryData = true;
			searchBox.SubmitURL = '/property/search/';
			
			Init();
			/*
			Utils.DropDownSelect(searchBox.CurrencyDropDown,'GBP');
			$j(searchBox.CurrencyDropDown).click();
			
			searchBox.SelectedCurrencyCode = $j("option:selected",searchBox.CurrencyDropDown).val();

			searchBox.UpdateSubmitButton();
			if(searchBox.SelectedCurrencyCode=='GBP'||searchBox.SelectedCurrencyCode=='EUR'||searchBox.SelectedCurrencyCode=='USD'){

				searchBox.ExchangeRate = Utils.getCurrencyRateByCurrency(searchBox.SelectedCurrencyCode);
				searchBox.CurrencyCode = searchBox.SelectedCurrencyCode;
			}else{
				searchBox.ExchangeRate = parseInt(Utils.getCurrencyRate($j("option:selected",searchBox.CountryDropDown).text()));

				searchBox.CurrencyCode = $j("option:selected",searchBox.CurrencyDropDown).val();
			}
			
			if(searchBox.ExchangeRate==0){ExchangeRate=1;}
			searchBox.FillMinPriceDropDown();
			if($j(searchBox.MinPriceDropDown).is(":disabled")){searchBox.MinPriceDropDown.disabled=false;}
			searchBox.MaxPriceDropDown.disabled=true;
			searchBox.SelectedMixPrice = 0;
			searchBox.SelectedMaxPrice = 0;
			*/
			if($j(searchBox.MinBedDropDown).is(":disabled")){searchBox.MinBedDropDown.disabled=false;}
			searchBox.FillMinBedsDropDown();	
			
			//showVideo();
			
		});
		
		
		
		
		
		Array.prototype.exists = function(o) {
			for(var i = 0; i < this.length; i++)
			   if(this[i] === o)
			     return true;
			return false;
		}
		
		var detailsPage = {
			pageTitle : "Auction HomePage",
			pageVersion : "1.0",
			modalPopUpControlID : "btnMakeEnquiry",
			modalPopUpContent: "",
			isNewClient:true,
			enquiryFormInit:function(){
				$j('#facebox .userDetails').show();
				$j('#facebox #commentsRow').show();
				$j('#facebox #finalSubmitRow').hide();
				
				// -- set all fields as read-only;
				$j('#facebox #embedEnquiryForm > input[type="text"]').attr('readOnly',true);
				$j("#facebox #embedEnquiryForm > input[type='text']").addClass('readonly');
				
				$j('#facebox #btnCancelEnquiry').click(function(){
					$j.facebox.close();
				});
				
				$j('#facebox #btnConfrimDetails').click(function(){
					$j('#facebox .userDetails').show();
					$j('#facebox #commentsRow').hide();
					$j('#facebox #finalSubmitRow').show();
				});
				
				$j('#facebox #btnShowDetails').click(function(){
					$j('#facebox .userDetails').hide();
					$j('#facebox #commentsRow').show();
					$j('#facebox #finalSubmitRow').hide();
				});
				
				$j('#facebox #btnSubmitEnquiry').click(function(){
					// -- now validate email address and everthing, if they are all fine, submit the form now
					//alert('submit the form now');
					if($j('#facebox textarea[name="comments"]').attr('value')>""){	
						//$j('#facebox #embedEnquiryForm').submit();
						// get the form
						$j('#facebox #embedEnquiryForm').attr('target','');
						
						var f = $j('#facebox #embedEnquiryForm');
						var action = f.attr('action');
						var serializedForm = f.serialize();
						$j.post(
							action,
							serializedForm,
							function(data){
								//alert(data.returnValue);
								if (data.returnValue){
									var msg = $j('#enquirySent').html();
									
									detailsPage.ShowPopUpContent(msg);
									setTimeout(function(){$j.facebox.close();},3500);
								}else{
									detailsPage.ShowPopUpContent($j('#enquirySent').html());
									$j('#facebox .content .text').text('There was an error while submitting your enquiry, Please contact support for help.');
								}										
							},
							"json"
						);
					}
				});
			},
			loadRenquiryForm:function(){
				$j.ajax({
					url:document.location.href,
					type:"POST",
					async:false,
					data:{"EnquiryFormOnly":"yes","client_email":'"'+$j('#contact_email').val()+'"'},
					complete:function(data){
						var email = $j('#contact_email').val();
						detailsPage.ShowPopUpContent(data.responseText);
						$j('#facebox #enquiryFormWrapper').show();
						$j('#facebox > input[name="contact_email"]').attr('value',email);
						detailsPage.enquiryFormInit();
						$j.facebox.reveal();
					}
				});
			},
			submitRegisterFormNewsletters:function(){
				var f = $j('#facebox #frmRegister');
				var action = "http://auctions.themovechannel.com/my/subscriptions/" ; //document.location.href; //f.attr('action');
				var serializedForm = f.serialize();
				$j.post(
					action,
					serializedForm,
					function(data){
						//alert(data.returnValue);
						$j('#facebox #registerFormMessagePanel .msg').html('Newsletters subscribed<br/>Submitting enquiry....please wait');
					},
					"json"
				);
			},
			submitRegisterForm:function(){
				
				$j('#facebox #registerFormMessagePanel .msg').html('Submitting enquiry... please wait');
				
				var f = $j('#facebox #frmRegister');
				var action = "http://auctions.themovechannel.com/auction_enquiry/" ; //document.location.href; //f.attr('action');
				var serializedForm = f.serialize();
				$j.post(
					action,
					serializedForm,
					function(data){
						//alert(data.returnValue);
						if (data.returnValue){
							var msg = $j('#enquirySent').html();
							detailsPage.ShowPopUpContent(msg);
							setTimeout(function(){$j.facebox.close();},3500);
						}else{
							detailsPage.ShowPopUpContent($j('#enquirySent').html());
							$j('#facebox .content .text').text('There was an error while submitting your enquiry, Please contact support for help.');
						}										
					},
					"json"
				);
			},
			isAlreadyRegister:function(email){
				return $j.ajax({
						url:'http://auctions.themovechannel.com/en/services/Ajax.Users.asp?isUserExist=' + $j('#contact_email').val(),
						method:'GET',
						async:false,
						beforesend:function(){
							$j.facebox.loading();
						},
						complete:function(data){
							var result = $j.evalJSON(data.responseText);
							//alert(result.returnValue);
							return result.returnValue;
						}
					});
			},
			registerFormAutoFill:function(){
				$j.ajax({
					url:'http://auctions.themovechannel.com/en/services/Ajax.Users.asp?GetUserObject='+$j('#contact_email').val(),
					method:'GET',
					async:true,
					complete:function(data){
						var userObject = $j.evalJSON(data.responseText);
						$j('#contact_title').attr('value',userObject.user.title);
						$j('#contact_name').attr('value',userObject.user.firstname);
						$j('#contact_surname').attr('value',userObject.user.lastname);
						if(userObject.user.country=='UK'){
							$j('#contact_country').attr('value','England');
						}else{
							$j('#contact_country').attr('value',userObject.user.country);
						}
						if(userObject.user.daytimephone!=""&&userObject.user.daytimephone!=null)
							$j('#best_phone').attr('value',userObject.user.daytimephone);
						else if(userObject.user.homephone!=""&&userObject.user.homephone!=null)
							$j('#best_phone').attr('value',userObject.user.homephone);
						else if(userObject.user.mobilephone!=""&&userObject.user.mobilephone!=null)
							$j('#best_phone').attr('value',userObject.user.mobilephone);
						detailsPage.registerFormGetNewsletters();
						// now update onChangeCountry
						onChangeCountry($j('#contact_country')[0]);
					}
				});
			},
			registerFormValidateAndFillup:function(){
				// -- do the check now
				if(!detailsPage.isNewClient){
					$j.ajax({
						url:"http://auctions.themovechannel.com/en/services/Ajax.Users.asp",
						data:{"pwd":$j('#facebox #contact_pwd').val(),"ValidateUserLogin":$j('#facebox #contact_email').val()},
						method:"POST",
						complete:function(data){
							var result = $j.evalJSON(data.responseText);
							if(result.returnValue){
								//-- now load the form with user details
								detailsPage.registerFormAutoFill();
								$j('#facebox #registerFormMessagePanel .msg').html('');
							}else{
								//-- now tell the user that password is wrong
								alert('Password does not match!\nPlease enter correct password or click \'Mail me my password\'');
							}
						}
					});
				}
			},
			registerFormValidate:function(){
				// -- do the check now
				if(!detailsPage.isNewClient){
					$j.ajax({
						url:"http://auctions.themovechannel.com/en/services/Ajax.Users.asp",
						data:{"pwd":$j('#facebox #contact_pwd').val(),"ValidateUserLogin":$j('#facebox #contact_email').val()},
						method:"POST",
						complete:function(data){
							var result = $j.evalJSON(data.responseText);
							if(result.returnValue){
								//-- now load the form with user details
								//detailsPage.registerFormAutoFill();
							}else{
								//-- now tell the user that password is wrong
								alert('Password does not match!\nPlease enter correct password or click \'Mail me my password\'');
							}
						}
					});
				}
			},
			registerFormGetNewsletters:function(){
				$j('#facebox #popUpNewsletters').show();
				var template = '<p><input type="checkbox" id="newsletter_@newsletter_id@" data="@newsletter_id@" name="newsletter_@newsletter_id@" class="JajoMore7 newsSubscribeChk" value="yes" checked="checked"/>@newsletter_name@</p>';
				var dummy;
				var dummyList = "";
				var nID;
				var nName;
				$j('#facebox #popUpNewsletters .list p').remove();
				nID = 1198;
				nName = "Auction news";
				if($j('#facebox #newsletter_'+nID)!=undefined)
				{
										$j('#facebox #newsletter_'+nID).fadeOut("slow",function(){
											$j('#facebox #newsletter_'+nID).parent().remove();
										});
				}
				dummy = template.replace("@newsletter_id@",nID);
				dummy = dummy.replace("@newsletter_id@",nID);
				dummy = dummy.replace("@newsletter_id@",nID);
				dummy = dummy.replace("@newsletter_name@",nName);
				dummyList += dummy;

				$j('#facebox #popUpNewsletters .list').append(dummyList);
				if($j('#facebox #popUpNewsletters .list p').size()==0){
					$j('#facebox #popUpNewsletters').hide();
				}
				
			},
			registerFormInit:function(){
				// -- grab newsletters if there is any
				$j('p > input.newsSubscribeChk').each(function(index){
					//alert($j(this).parent().html());
					$j('#facebox #popUpNewsletters .list').append('<p>'+$j(this).parent().html()+'</p>');
				});
				
				$j('#facebox #event_id').val(detailsPage.event_id);
				
				$j('#facebox #btnCancelEnquiry').click(function(){
					$j.facebox.close();
					return false;
				});
				
				$j('#facebox #btnResendPassword').click(function(){
					//alert('here');
					$j.post(
						"http://auctions.themovechannel.com/services/register/",
						{"action":"forgot","ajaxed":"yes","email":$j('#facebox #contact_email').val()},
						function(data){
							if(data.returnValue){
								//-- successful, then says that an email is already sent.
								$j('#facebox #registerFormMessagePanel .msg').html('We have sent you an email containing your password details.');
							}else{
								//-- failed, then says there was an error
								$j('#facebox #registerFormMessagePanel .msg').html('There was an error whilst we trying to sent your details, plesae contact us.');
							}
							//alert(data);
						},
						"json"
					);
					return false;
				});
				
				$j('#contact_email').unbind('change');
				
				$j('#facebox #btnSubmitEventRegister').click(function(){
					// -- do the form validation first
					var validFields = validateTMCForm(document.frmRegister);
					if(!validFields)return false;
					// -- do the authentication here and load logged-in enquiry form after successful authentication.
					//alert('here');
					if($j('#facebox #contact_pwd').val() == ""){
						alert('Please type in your password.');
					}else{
						// -- do the check now
						$j.ajax({
							url:"http://auctions.themovechannel.com/en/services/Ajax.Users.asp",
							data:{"pwd":$j('#facebox #contact_pwd').val(),"ValidateUserLogin":$j('#facebox #contact_email').val()},
							method:"POST",
							complete:function(data){
								var result = $j.evalJSON(data.responseText);
								if(result.returnValue){
									//user.isLoggedIn = true;
									//user.name = data.name;
									// -- now load enquiry form 
									//detailsPage.loadRenquiryForm();
									//alert(result.client_id);
									$j('#facebox #enquiry_ClientID').attr('value',result.client_id);
									// -- and add the comment and submit the form
									// now submit the form]
									// now subscribe newsletters
									detailsPage.submitRegisterFormNewsletters();
									detailsPage.submitRegisterForm();
								}else{
									//-- user got wrong password or havent register yet.
									//-- check if email is already registered?
									var isUserExist = detailsPage.isAlreadyRegister($j('#facebox #contact_email').val());
									var exist = $j.evalJSON(isUserExist.responseText).returnValue;
									//alert(exist);
									if (exist){
										// -- let user know that the password is wrong.!!!!
										alert('User name and password does not match. Click \'Email me my password\' link to retrieve your password.');
									}else{
										// -- now register user
										var f = $j('#facebox #frmRegister');
										var action = 'http://auctions.themovechannel.com/services/register/'; //f.attr('action');
										var serializedForm = f.serialize();
										$j.post(
											action,
											serializedForm,
											function(data){
												//alert(data.returnValue);
												if (data.returnValue!=0){
													$j('#facebox #registerFormMessagePanel .msg').html('User Account created.');
												}else{
													$j('#facebox #registerFormMessagePanel .msg').html('Error creating user account, please contact us.');
												}										
												$j('#facebox #enquiry_ClientID').attr('value',data.returnValue);
												// -- and add the comment and submit the form
												// now submit the form]
												// now subscribe newsletters
												detailsPage.submitRegisterFormNewsletters();
												detailsPage.submitRegisterForm();
											},
											"json"
										);
									}	
								}
							}
						});
					}
					return false;
				});
				
				$j('#contact_pwd').change(function(){
				
					detailsPage.registerFormValidateAndFillup();
					$j('#facebox #registerFormMessagePanel .msg').html('Please confirm your password.');
				});
				
				$j('#contact_name').change(function(){
					
					detailsPage.registerFormValidate();
				});
				
				$j('#contact_surname').change(function(){
					
					detailsPage.registerFormValidate();
				});
				
				$j('#contact_email').change(function(){
					
					
					$j.ajax({
						url:'http://auctions.themovechannel.com/en/services/Ajax.Users.asp?isUserExist=' + $j('#contact_email').val(),
						method:'GET',
						async:false,
						beforesend:function(){
							$j.facebox.loading();
						},
						complete:function(data){
							var result = $j.evalJSON(data.responseText);
							if(result.returnValue){
								//-- now show one password field and ask user to log in
								detailsPage.isNewClient = false;
								$j('#facebox #registerFormMessagePanel .msg').html('If you do not remember your password, click "Email me my password" to re-send the password.');
								$j('#facebox .resendPasswordRow').show();
								$j('#facebox .passwordConfirmRow').hide();
								$j('#facebox #contact_pwd2').removeClass('rfv');
								$j('#facebox #contact_pwd2').removeClass('rfv');
								$j('#facebox .passwordRow').show();
								
							}else{
								
								detailsPage.isNewClient = true;
								$j('#facebox #registerFormMessagePanel .msg').html('Please confirm you password.');
								$j('#facebox .resendPasswordRow').hide();
								$j('#facebox .passwordConfirmRow').show();
								$j('#facebox #contact_pwd2').addClass('rfv');
								$j('#facebox #contact_pwd2').addClass('rfv');
							}
						}
					});
					
					return true;
				});
			},
			BindControls:function(){
				$j(detailsPage.modalPopUpControlID).click(function(){
					
					if (!user.isLoggedIn){
						
						$j('#facebox #registerFormMessagePanel .msg').html('Please type in your email address first.');
						var formContent = '';
						
							$j.ajax({
								type:"GET",
								async:true,
								processData:false,
								url:'http://auctions.themovechannel.com/en/pages/tmc.com.Auction.RegisterForm.html',
								data:"",
								complete:function(data){
									detailsPage.ShowPopUpContent(data.responseText);
									detailsPage.registerFormInit();
								}
							});
						
					}else{
											
						var EnquiryForm = $j('#enquiryFormWrapper').clone();
						$j(EnquiryForm).show();
						detailsPage.ShowPopUpContent(EnquiryForm);
					
						detailsPage.enquiryFormInit();
					}
					return false;
				});
			},
			ShowPopUpContent:function(content){
				$j.facebox(content);
			},
			ShowPopUp:function(){
				$j.facebox(detailsPage.modalPopUpContent);
			}
		}
		
		function init(){
			//alert('here');
			InitRegister();
			$j('#formPlaceHolder').html = '';
			detailsPage.modalPopUpControlID = 'a.btnMakeEnquiry';
			detailsPage.modalPopUpContent = $j('#MessageBox').html();
			detailsPage.BindControls();
		}
		
		$j(document).ready(function(){
			$j('a[rel*=facebox]').facebox();
			init();
		});
		
	
	
	function showTip(tp){
		/*$('tips').select('.tip').each(function (t){
			if (t.id==('tip_' + tp))
				t.style.display="block";
			else
				t.style.display="none";
			}
		);*/
		return false;
	}
	
	function fnCheckEmail(str_email)
	{
		if (!str_email.match(/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i))
		{
		$("contact_email").value = "";
		$("contact_email").focus(); 
		$("efv_contact_email").style.display="";
		return false;
		}
		else
		{
		$("efv_contact_email").style.display="none";
		}

		
		new Ajax.Request("/_shared/property/test/getClient.asp",{
			method:'post',
			parameters:{email:str_email},
			onSuccess:function(xhr)
		 	 {
			 onAjaxCheckEmailSuccess(str_email,xhr.responseText);
			 }
			});
		 return false;
	}

	function onAjaxCheckEmailSuccess(str_email,txt)
	{
		res=eval('(' + txt + ')');

		if (res.result=="found" )
		{
		$("email_exists").innerHTML="<p style='height:30px'>The email - "+ str_email +" already exists in our database.<br/>If you would like the details sent to you please use the form on the right</p>";
		}
	}
