﻿$(document).ready(function() {
    /* Pop up mySaveList dialog box */
    $("#leftMenu_mySavedList").click(function() {
        callAjaxGridSaveList('');
        $("#mySavedList_dialog").dialog("open");
        $.cookie('dialogOpen', 'true', { path: '/', expires: 1000 });
    });

    /* Dynamic Top menu */
    //	  $("#topMenu2UL li").hover(
    //		  function(){ $("ul", this).fadeIn("fast"); }, 
    //		  function() { } 
    //	  );
    //	  if (document.all) {
    //		  $("#topMenu2UL li").hoverClass ("sfHover");
    //	  }


    /* Share This mouseover */
    $("#sharethisimg").hover(function() {
        $("#leftMenuAnywhere").css("height", "320px");
        b();
    },
		  function() { }
	  );

    /* Clear the field in text box when focus */
    //$('#leftMenuMY_Pwsd').focus(function() { $('#leftMenuMY_Pwsd').val('') });
    $('input[@name*=leftMenuMY_Email]').focus(function() { if ($('input[@name*=leftMenuMY_Email]').val() == 'Type Your Email') { $('input[@name*=leftMenuMY_Email]').val('') } });
    $('#leftMenuQS_Keyword').focus(function() { $('#leftMenuQS_Keyword').val('') });

    /* Left menu collapse */
    /* check personalisation left menu collapse */
    if ($.cookie('#leftMenuMy') == 'true') {
        $('#leftMenuMy').css('display', 'none');
        $('#leftMenuMy_m').css('background-position', '0 -11px');
    }

    if ($.cookie('#leftMenuQuickSearch') == 'true') {
        $('#leftMenuQuickSearch').css('display', 'none');
        $('#leftMenuQuickSearch_m').css('background-position', '0 -11px');
    }

    //  if($.cookie('#leftMenuNewsLetter') == 'true') { 
    //    $('#leftMenuNewsLetter').css('display', 'none');
    //    $('#leftMenuNewsLetter_m').css('background-position', '0 -11px');
    //  }

    if ($.cookie('#leftMenuExtra') == 'true') {
        $('#leftMenuExtra').css('display', 'none');
        $('#leftMenuExtra_m').css('background-position', '0 -11px');
    }

    if ($.cookie('#leftMenuAnywhere') == 'true') {
        $('#leftMenuAnywhere').css('display', 'none');
        $('#leftMenuAnywhere_m').css('background-position', '0 -11px');
    }

    if ($.cookie('#leftMenuThink') == 'true') {
        $('#leftMenuThink').css('display', 'none');
        $('#leftMenuThink_m').css('background-position', '0 -11px');
    }

    //  $('#leftMenuNew_m').click(function() { Com_Acc('#leftMenuNew', this) });
    $('#leftMenuMy_m').click(function() { Com_Acc('#leftMenuMy', this) });
    $('#leftMenuQuickSearch_m').click(function() { Com_Acc('#leftMenuQuickSearch', this) });
    //$('#leftMenuNewsLetter_m').click(function() { Com_Acc('#leftMenuNewsLetter', this) });
    $('#leftMenuExtra_m').click(function() { Com_Acc('#leftMenuExtra', this) });
    $('#leftMenuAnywhere_m').click(function() { Com_Acc('#leftMenuAnywhere', this) });
    $('#leftMenuThink_m').click(function() { Com_Acc('#leftMenuThink', this) });

    /* Redirect to other page with querystring */
    //  $('#btnLeftMenuRegister').click(function() {
    //    window.location = '/useracc/signup.aspx?name=' + URLEncode($('#leftMenuMY_RegName').val()) + "&email=" + URLEncode($('#leftMenuMY_Email').val());
    //  });

    function validationFind() {
        if ($('input[@name*=leftMenuMY_Email]').val() == '' || $('input[@name*=leftMenuMY_Email]').val() == 'Type Your Email') {
            alert("Your Email Is Required!");
            $('input[@name*=leftMenuMY_Email]').focus();
            return false
        }
        else {
            if (validateEmail() == false) {
                alert('Invalid Email Address!');
                $('input[@name*=leftMenuMY_Email]').focus();
                return false
            }
        }

        if ($('input[@name*=leftMenuMY_Pwsd]').val() == '') {
            alert("Your Password Is Required!");
            document.getElementById('divLeftMenuShowPswdText').style.display = 'none';
            document.getElementById('divLeftMenuPswd').style.display = '';
            $('input[@name*=leftMenuMY_Pwsd]').focus();
            return false
        }

        return true;
    }

    $('#btnLeftMenuFind').click(function() {

        if ($('#leftMenuQS_Keyword').val() == '' || $('#leftMenuQS_Keyword').val() == 'Enter keyword') {
            alert("Pls enter keyword!");
            $('#leftMenuQS_Keyword').focus();
        }
        else {
            window.location = '/keywordSearch.aspx?k=' + URLEncodeKeywordSearch($('#leftMenuQS_Keyword').val());
        }
    });

});

/* Mouseover function for Dynamic Top menu */
$.fn.hoverClass = function(c) {
  return this.each(function(){
    $(this).hover( 
      function() { $(this).addClass(c);  },
      function() { $(this).removeClass(c); }
    );
  });
};	  	
    
/* Collapse function used for left menu */
function Com_Acc(e, f) {
  if ($(e).is(':visible')) {
    $(e).slideToggle(700);
    $(f).css('background-position', '0 -11px');
    $.cookie(e, 'true', { path: '/', expires: 1000 });    
  } else {
    $(e).slideToggle(700);
    $(f).css('background-position', '0 0');
    $.cookie(e, null, { path: '/', expires: 1000 });    
  }
}	

/* Encode querystring */
function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
	    output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

function URLEncodeKeywordSearch(clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
      output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '_';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + (hexVal.length < 2 ? '0' : '') + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}  	  

function jumpTo(URL_List){
   	var URL = URL_List.options[URL_List.selectedIndex].value;

    //reset to first value
	URL_List.selectedIndex = 0;

   	if (URL.length > 0) {	
			window.location=URL;
		}	
}

  // Building Image RollOver 
  function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
      if (!d.MM_p) d.MM_p = new Array();
      var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
        if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
  }
  function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
  }
  function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
      d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
  }
  function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
      if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
  }

  function MM_showHideLayers() { //v6.0
    var i, p, v, obj, args = MM_showHideLayers.arguments;
    for (i = 0; i < (args.length - 2); i += 3) if ((obj = MM_findObj(args[i])) != null) {
      v = args[i + 2];
      if (obj.style) { obj = obj.style; v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v; }
      obj.visibility = v;
    }
  }
  
function validEmail(checkString) {
	var at = 0;
	var pt = 0;
	var validChar = "@0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz.";
	var allValid = true;
	if (checkString.length <= 0)
		return false;
	if (checkString.charAt(0) == "@")
		return false;
	for (var i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i + 1)
		if (validChar.indexOf(ch) < 0) {
			allValid = false;
			break;
		}
		if (ch == "@")
			at++;
		if (ch == ".")
			pt++;
    }
    if (((at == 0) || (at > 1)) || (checkString.charAt(checkString.length-1) == ".") || (pt == 0))
        return false;
	if (checkString.indexOf("@") == (checkString.indexOf(".") - 1))
		return false;
	return allValid;
}	

function mycarousel_initCallback(carousel)
{
//    $('.featuredtab a').bind('click', function() {
//       // carousel.startAuto(0);
//        carousel.scroll(carousel.first);
//        carousel.startAuto(2);
//        return false;
//    });

    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};  

    function un_checkAll(form)
    {

      for (i=form.chkEnquiry.length-1; i > -1; i--) {
          if (form.chkEnquiry[i].checked) {
              form.chkEnquiry[i].checked = false;
          }
          else {
            form.chkEnquiry[i].checked = true;
          }
      }     
    }  
    
    function SendMultipleEnquiries(form, target)
    {
     var bCheck = false;
     var sEnq = "";
      for (i=form.chkEnquiry.length-1; i > -1; i--) {
          if (form.chkEnquiry[i].checked) {
              sEnq += form.chkEnquiry[i].value + ",";
              bCheck = true;
          }
      }     
      if (bCheck == false){
          alert ("Please select at least 1 agent.");
          return false;
      }
      
       form.enquiries.value = sEnq;
       form.action = target;
       form.submit();
    }

    function sendenquiry(code, form, target) {
      form.enquiries.value = code;
      form.action = target;
      form.submit();
    }
       
function jsClickButton(e, buttonid) {
    var evt = e ? e : window.event;
    var bt = document.getElementById(buttonid);
    if (bt) {
        if (evt.keyCode == 13) {
            $('#' + buttonid).click();
            return false;
        }
    }
}

function jsClickNCheck(e, buttonid) {
    var b = (window.event) ? event.keyCode : e.which;
    var evt = e ? e : window.event;
    if (evt.keyCode == 13) {
        $('#' + buttonid).click();
        return false;        
    }
    else
    {
        return !((b >= 65 && b <= 90) || (b >= 97 && b <= 122) || (b >= 33 && b <= 47) || (b >= 58 && b <= 64) || (b >= 91 && b <= 96) || (b >= 123 && b <= 126)) 
    }
}

function g(c, e, d) { if (d) { if (c.value == e) c.value = '' } else { if (c.value == '') c.value = e } }

/* Start Share This js */
a = document; d = 'http://www.iproperty.com/images/common/bookmarks/'; a.writeln('<style type="text/css">'); a.writeln('#sb_box {background-image:url(' + d + 'bg.png);background-repeat:no-repeat;height:185px;width:300px;visibility:hidden;position:absolute;}'); a.writeln('#sb_desc {width:278px;height:25px;padding-left:10px;}'); a.writeln('.sb_bodyWhite {color:#FFFFFF;font-size:8pt;line-height:50px;font-family:Arial, Helvetica, sans-serif;text-decoration:none;font-weight:bold;}'); a.writeln('#sb_menu {top:25px;padding: 0 0 0 0;margin-left:15px;margin-top:28px;position:absolute;}'); a.writeln('#sb_menu li {margin-left:5px;list-style:none;}'); a.writeln('#sb_menu2 {top:25px;padding:0 0 0 0;margin-left:165px;margin-top:28px;position:absolute;}'); a.writeln('#sb_box a {color:#333333;font-size:11px;font-family:Geneva, Arial, Helvetica, sans-serif;text-decoration:none;}'); a.writeln('#sb_box a:hover {color:#006699;}'); a.writeln('#sb_menu2 li {margin-left:5px;width:120px;list-style:none;}'); a.writeln('#sb_reddit {width:18px;height:23px;text-indent:25px;background:url(' + d + 'ico1.gif) 0 0 no-repeat;}'); a.writeln('#sb_facebook {width: 18px;height:23px;text-indent:25px;background:url(' + d + 'ico1.gif) 0 -21px no-repeat;}'); a.writeln('#sb_delicious {width:18px;height:23px;text-indent:25px;background:url(' + d + 'ico1.gif) 0 -45px no-repeat;}'); a.writeln('#sb_Digg {width:18px;height:23px;text-indent:25px;background:url(' + d + 'ico1.gif) 0 -67px no-repeat;}'); a.writeln('#sb_StumbleUpon {width:18px;height:23px;text-indent:25px;background:url(' + d + 'ico1.gif) 0 -91px no-repeat;}'); a.writeln('#sb_Google {width:18px;height:23px;text-indent:25px;background:url(' + d + 'ico2.gif) 0 0 no-repeat;}'); a.writeln('#sb_MySpace {width:18px;height:23px;text-indent:25px;background: url(' + d + 'ico2.gif) 0 -21px no-repeat;}'); a.writeln('#sb_Yahoo {width:18px;height:23px;text-indent:25px;background:url(' + d + 'ico2.gif) 0 -45px no-repeat;}'); a.writeln('#sb_Live {width:18px;height:23px;text-indent:25px;background:url(' + d + 'ico2.gif) 0 -67px no-repeat;}'); a.writeln('#sb_LinkedIn {width:18px;height:23px;text-indent:25px;background:url(' + d + 'ico2.gif) 0 -91px no-repeat;}'); a.writeln('</style>'); function b() { d = window.location; a = document; c = a.getElementById('sb_box'); c.innerHTML = '<div><div class="sb_bodyWhite" id="sb_desc">Share this on:</div><ul id="sb_menu"><li id="sb_reddit"><a href="http://www.reddit.com/submit?url=' + d + '">Reddit</a></li><li id="sb_facebook"><a href="http://www.facebook.com/share.php?u=' + d + '">Facebook</a></li><li id="sb_delicious"><a href="http://www.delicious.com/post?url=' + d + '">del.icio.us</a></li><li id="sb_Digg"><a href="http://www.digg.com/submit?url=' + d + '">Digg</a></li><li id="sb_StumbleUpon"><a href="http://www.stumbleupon.com/submit?url=' + d + '">StumbleUpon</a></li></ul><ul id="sb_menu2"><li id="sb_Google"><a href="http://www.google.com/bookmarks/mark?op=add&bkmk=' + d + '">Google</a></li><li id="sb_MySpace"><a href="http://www.myspace.com/Modules/PostTo/Pages/?l=3&u=' + d + '">MySpace</a></li><li id="sb_Yahoo"><a href="http://bookmarks.yahoo.com/toolbar/savebm?opener=&u=' + d + '">Yahoo! Bookmark</a></li><li id="sb_Live"><a href="https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url=' + d + '">Windows Live</a></li><li id="sb_LinkedIn"><a href="http://www.linkedin.com/shareArticle?mini=true&url=' + d + '">LinkedIn</a></li></ul></div>'; c.style.visibility = 'visible'; }
/* End Share This js */

function closeshare(id) {
    var zxcevt = window.event || arguments.callee.caller.arguments[0];
    var obj = document.getElementById(id);
    if (zxcCkEventObj(zxcevt, obj)) {
        obj.style.visibility = 'hidden';
        $('#leftMenuAnywhere').css('height', '160px');
    }
}


/*<![CDATA[*/
function zxcCkEventObj(zxce, zxcp) {
    if (!zxce) var zxce = window.event;
    zxce.cancelBubble = true;
    if (zxce.stopPropagation) zxce.stopPropagation();
    if (zxce.target) zxceobj = zxce.target;
    else if (zxce.srcElement) zxceobj = zxce.srcElement;
    if (zxceobj.nodeType == 3) zxceobj = zxceobj.parentNode;
    var zxceobj = (zxce.relatedTarget) ? zxce.relatedTarget : (zxce.type == 'mouseout') ? zxce.toElement : zxce.fromElement;
    if (!zxceobj || zxceobj == zxcp) return false;
    while (zxceobj.parentNode) {
        if (zxceobj == zxcp) return false;
        zxceobj = zxceobj.parentNode;
    }
    return true;
}


