﻿// A bunch of utilities

function modalValidate(popupControl,validationgroup)
{
     if(Page_ClientValidate(validationgroup))
     {
        //  find the popup behavior
        this._popup = $find(popupControl);
        // show the popup
        this._popup.show();
        //  kick-off the webservice, registering our callback
        
        PageMethods.Contact_Us($get('first_name').value,$get('last_name').value, $get('email').value, $get('phone').value, $get('comments').value,this.callback)
        //PageMethods.Contact_Us("mtpowers","mtpowers@gmail.com","7816400074","comments",this.callback);
    }
}

function modalValidateRegister(popupControl,validationgroup)
{
     if(Page_ClientValidate(validationgroup))
     {
        //  find the popup behavior
        this._popup = $find(popupControl);
        // show the popup
        this._popup.show();
        
        //alert($get('RegisterFirstName').value);
        //alert($get('RegisterLastName').value);
        //  kick-off the webservice, registering our callback
        PageMethods.RegisterUser($get('RegisterFirstName').value,$get('RegisterLastName').value,$get('RegisterUserName').value, $get('RegisterPassword').value, $get('RegisterPhone').value,$get('RegisterLetter').checked,$get('RegisterEmailReminder').checked, this.callback_register)
     
    }
}

function modalValidateFriend(popupControl,validationgroup)
{
     if(Page_ClientValidate(validationgroup))
     {
        //  find the popup behavior
        this._popup = $find(popupControl);
        //  kick-off the webservice, registering our callback
        
        // show the popup
        this._popup.show();
       
        PageMethods.Contact_Us_Friend($get('NameBox').value, $get('EmailBox').value,$get('FromBox').value,$get('CommentsBox').value,document.getElementById('MLSHeader').innerText,this.callback );
     
    }
}

function modalValidateLogin(popupControl, validationgroup)
{
  if(Page_ClientValidate(validationgroup))
  {
        //  find the popup behavior
        this._popup = $find(popupControl);
        //  kick-off the webservice, registering our callback
        this._popup.show();
        
        if($get('ForgotPass').checked)
        {
            PageMethods.ForgotPassword($get('LoginEmailBox').value, this.callback_email);
        }
        else
        { 
            PageMethods.Login($get('LoginEmailBox').value, $get('LoginPassBox').value,$get('LoginCheckBox').checked,this.callback_login );
        }
        //PageMethods.Contact_Us($get('name').value, $get('email').value, $get('phone').value, $get('comments').value, this.callback)
     
  }
}  
function callback(result)
{ 
    //  hide the popup
    setTimeout(HidePopup('Email sent - thank you for using Boston Condo Group'),2050);
 
           
}
 
function callback_login(result)
{
 //  hide the popup
 if(result)
 {
    this._popup.hide();
    
    redirect_to_mls();
 }
 else
 {
    txt = 'User credentials are invalid';
    setTimeout(HidePopup(txt),2050);
    
 } 
}

function callback_register(result)
{
alert(result);
if(result)
{
this._popup.hide();
    
    redirect_to_mls();
}
else
{
alert('User already exists in our database, please recover your password our contact a BCG representative.');

setTimeout(HidePopup(result),2050);
}

}


function callback_email(result)
{
 //  hide the popup
 if(result)
 {
    txt = 'Email has been sent, please check your email for your password';
 }
 else
 {
    txt = 'User credentials are invalid';
 }
 setTimeout(HidePopup(txt),2050); 
}

//We need this cause we cannot redirect in code behind
function redirect_to_mls()
{

 var strHref = window.location.search;
 var strQueryString = strHref.substr(strHref.indexOf("&id=") + 4).toLowerCase();
 var _loc = 'http://www.bostoncondogroup.com/mls/mls.aspx?id=' + strQueryString;        
 window.location = _loc;
 }
 
function close_win(popupControl)
{
this._popup = $find(popupControl);
this._popup.hide();
}

function HidePopup(txt)
{
alert(txt);
 this._popup.hide();
}


//Swap out the photo when the user hovers
function changePhoto(idx)
{

    document.getElementById("MainImage").src = idx;

}

