/*
 * jqModal - Minimalist Modaling with jQuery
 *   (http://dev.iceburg.net/jquery/jqModal/)
 *
 * Copyright (c) 2007,2008 Brice Burgess <bhb@iceburg.net>
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 * 
 * $Version: 03/01/2009 +r14
 */
(function($) {
$.fn.jqm=function(o){
var p={
overlay: 50,
overlayClass: 'jqmOverlay',
closeClass: 'jqmClose',
trigger: '.jqModal',
ajax: F,
ajaxText: '',
target: F,
modal: F,
toTop: F,
onShow: F,
onHide: F,
onLoad: F
};
return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s;
H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s};
if(p.trigger)$(this).jqmAddTrigger(p.trigger);
});};

$.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide');};
$.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow');};
$.fn.jqmShow=function(t){return this.each(function(){t=t||window.event;$.jqm.open(this._jqm,t);});};
$.fn.jqmHide=function(t){return this.each(function(){t=t||window.event;$.jqm.close(this._jqm,t)});};

$.jqm = {
hash:{},
open:function(s,t){var h=H[s],c=h.c,cc='.'+c.closeClass,z=(parseInt(h.w.css('z-index'))),z=(z>0)?z:3000,o=$('<div></div>').css({height:'100%',width:'100%',position:'fixed',left:0,top:0,'z-index':z-1,opacity:c.overlay/100});if(h.a)return F;h.t=t;h.a=true;h.w.css('z-index',z);
 if(c.modal) {if(!A[0])L('bind');A.push(s);}
 else if(c.overlay > 0)h.w.jqmAddClose(o);
 else o=F;

 h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F;
 if(ie6){$('html,body').css({height:'100%',width:'100%'});if(o){o=o.css({position:'absolute'})[0];for(var y in {Top:1,Left:1})o.style.setExpression(y.toLowerCase(),"(_=(document.documentElement.scroll"+y+" || document.body.scroll"+y+"))+'px'");}}

 if(c.ajax) {var r=c.target||h.w,u=c.ajax,r=(typeof r == 'string')?$(r,h.w):$(r),u=(u.substr(0,1) == '@')?$(t).attr(u.substring(1)):u;
  r.html(c.ajaxText).load(u,function(){if(c.onLoad)c.onLoad.call(this,h);if(cc)h.w.jqmAddClose($(cc,h.w));e(h);});}
 else if(cc)h.w.jqmAddClose($(cc,h.w));

 if(c.toTop&&h.o)h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);	
 (c.onShow)?c.onShow(h):h.w.show();e(h);return F;
},
close:function(s){var h=H[s];if(!h.a)return F;h.a=F;
 if(A[0]){A.pop();if(!A[0])L('unbind');}
 if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove();
 if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();} return F;
},
params:{}};
var s=0,H=$.jqm.hash,A=[],ie6=$.browser.msie&&($.browser.version == "6.0"),F=false,
i=$('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({opacity:0}),
e=function(h){if(ie6)if(h.o)h.o.html('<p style="width:100%;height:100%"/>').prepend(i);else if(!$('iframe.jqm',h.w)[0])h.w.prepend(i); f(h);},
f=function(h){try{$(':input:visible',h.w)[0].focus();}catch(_){}},
L=function(t){$()[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);},
m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);if(r)f(h);return !r;},
hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function() {
 if(!this[c]){this[c]=[];$(this).click(function(){for(var i in {jqmShow:1,jqmHide:1})for(var s in this[i])if(H[this[i][s]])H[this[i][s]].w[i](this);return F;});}this[c].push(s);});});};
})(jQuery);
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
function goto_page(el){
	if(el.options[el.selectedIndex].value != '-') {
		document.location.href = el.options[el.selectedIndex].value;
	}
}
$(document).ready(function(){
 	if($('#main-prop-search #search-country').val() != 4) {
		$('#main-prop-search #search-nor').attr('disabled', 'disabled');
		$('#main-prop-search #search-nor').val('');
	}
	$('#main-prop-search #search-country').change(function() {
		if($('#main-prop-search #search-country').val() == 4) {
			$('#main-prop-search #search-nor').attr('disabled', '');
		} else $('#main-prop-search #search-nor').attr('disabled', 'disabled');
	});

$('#more-stuff').before('<p id=""rmf><a id="rm" href="#">Read More &raquo</a></p>').css('display','none');
$('#rm').click(function(){$('#more-stuff').show("slow");$('#rm').css('display','none');$('#more-stuff').before('<h2>More Information</h2>');return false;});
function parseGetVars() {
var getVars = new Array();
var qString = unescape(top.location.search.substring(1));
var pairs = qString.split(/\&/);
for (var i in pairs) {
var nameVal = pairs[i].split(/\=/);
getVars[nameVal[0]] = nameVal[1];
}
return getVars;
}

	$('#main-prop-search #search-country').change(function() { 
		var dd = $("#prop_area");												   
		if($('#main-prop-search #search-country').val() == 4 || $('#main-prop-search #search-country').val() == 2) {
			$("#sf-area").append('<div style="text-align:center"><img src="/assets/images/v5structure/8-0.gif" /></div>');
			var foo = parseGetVars();
			$.ajax({
				type: "GET",
				url: '/a_/?f=createAreadropdown&n='+$('#main-prop-search #search-country').val(),
				data: '',
				error: function(obj, msg){
					// Die silently? noooo
				},
				success: function(msg){
					$("#sf-area").empty();
					$("#sf-area").append(msg);
					$("#sf-area").show('slow');
				}
			});
			
			return false;
		} else $("#sf-area").empty();
	});

$('#advanced-search #search-country').change(function() { 
		var dd = $("#prop_area");												   
		if($('#advanced-search #search-country').val() == 4 || $('#advanced-search #search-country').val() == 2) {
			$("#adv-area-target").append('<div style="text-align:center"><img src="/assets/images/v5structure/8-0.gif" /></div>');
			var foo = parseGetVars();
			$.ajax({
				type: "GET",
				url: '/a_/?f=createAreadropdown&n='+$('#advanced-search #search-country').val(),
				data: '',
				error: function(obj, msg){
					// Die silently? noooo
				},
				success: function(msg){
					$("#adv-area-target").empty();
					$("#adv-area-target").append(msg);
					$("#adv-area-target").show('slow');
					$("#area-label").show('slow');
				}
			});
			
			return false;
		} else {
			$("#adv-area-target").empty();
			$("#area-label").hide();
		}
	});
	$('#exn-content').css('display','none');
	$('#exn-show-hide').click(function() {$('#exn-content').slideToggle('slow');return false;});
		if($('#doss_tree').length > 0) {
			$('#doss_tree').treeview({
				persist: 'location'
			});
		}


var yload=function(hash){
	$('.jqmWindow').jqmAddClose('a#pop_no');
	$('#adv_box').css('display','none');	
	$('#ajax-forward_url').attr('value',document.location.href.replace('http://www.masainternational.com',""));	
	$('#ssp_box').css('display','none');	
	$.cookie('pu_cookie', 1, { expires: 14});
	$('#aweb_submit').click(function() {
		bar = 0;
		$('#aweber_form input.required').each(function(i){
			if($(this).val() == '') {
				bar = 1;
				$(this).css("border-color","red");	
				var foo = $(this).parent();
				$(foo).css("color","#990000");	
				$(foo).css("font-weight","bold");	
			} else {
				$(this).css("color","#333333");
				$(this).css("border-color","#000000");	
				var foo = $(this).parent();
				$(foo).css("color","#333333");
			}
		});
		if(bar == 1) {
			alert("It seems that you missed some mandatory fields. \nPlease ensure that all of the fields in red have been filled out.");
			return false;					 
		} else { // Submit form via Ajax and return the TY message:
			
			return true;
	}
	});
	
 };
var myClose=function(hash) { hash.w.fadeOut('2000',function(){ hash.o.remove();$('#adv_box').css('display','block');$('#ssp_box').css('display','block'); });$.cookie('pu_no', 1, { expires: 60, path: "/"}); }; 

/* Interstitial */
var pu_int_cookie = parseInt($.cookie('pu_int_cookie'));
if(!pu_int_cookie) {
	$.cookie('pu_int_cookie', 1, { expires: 14, path: "/"});
} else {
	$.cookie('pu_int_cookie', pu_int_cookie+1, { expires: 14, path: "/"});
}
if(pu_int_cookie+1 == 3 && !$.cookie('pu_no')) {
	$('.jqmWindow').jqm({ajax: '/a_/?f=masa_ppcpopup',onLoad: yload, modal: 1, toTop: 1, onHide: myClose}).jqmShow();
}

$('.hidden').css('display','none');
$("#past_data_toggle").click(function () {
  $("#past_data").toggle();
});


});
