// $Id$

var undefined; // Safeguards against anyone who wants to change the value of undefined in the global space

function is_numeric (o) {
  return typeof o === 'number' && isFinite(o);
}

function addslashes_regex(str) {
  str = str.replace(/\./g, '\\.');
  str = str.replace(/\//g, '\\/');
  str = str.replace(/\^/g, '\\^');
  str = str.replace(/\$/g, '\\$');
  str = str.replace(/\*/g, '\\*');
  str = str.replace(/\+/g, '\\+');
  str = str.replace(/\?/g, '\\?');
  str = str.replace(/\{/g, '\\{');
  str = str.replace(/\}/g, '\\}');
  str = str.replace(/\(/g, '\\(');
  str = str.replace(/\)/g, '\\)');
  str = str.replace(/\!/g, '\\!');
  str = str.replace(/\[/g, '\\[');
  str = str.replace(/\]/g, '\\]');
  str = str.replace(/\|/g, '\\|');
  str = str.replace(/\\/g, '\\\\');
  return str;
}

function is_set() {
  // http://kevin.vanzonneveld.net
  // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // +   improved by: FremyCompany
  // +   improved by: Onno Marsman
  // *     example 1: is_set( undefined, true);
  // *     returns 1: false
  // *     example 2: is_set( 'Kevin van Zonneveld' );
  // *     returns 2: true
  
  var a=arguments, l=a.length, i=0;
  
  if (l===0) {
      throw new Error('Empty is_set'); 
  }
  
  while (i!==l) {
      if (typeof(a[i])=='undefined' || a[i]===null) { 
          return false; 
      } else { 
          i++; 
      }
  }
  return true;
}
function explode(delimiter, string, limit) {
    // http://kevin.vanzonneveld.net
    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']
 
    var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2 ||
        typeof arguments[0] == 'undefined' ||
        typeof arguments[1] == 'undefined' ) {
        return null;
    }
 
    if ( delimiter === '' ||
        delimiter === false ||
        delimiter === null ) {
        return false;
    }
 
    if ( typeof delimiter == 'function' ||
        typeof delimiter == 'object' ||
        typeof string == 'function' ||
        typeof string == 'object' ) {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
};
/* jQuery plugin insert tag
 * Website: http://jn.orz.hm/programming/js/jquery/insert_tag.html
 *
 * usage:
 * $(function() {
 *    insertTag('#textarea-element-only', 'span');
 * });
 *    
 */
(function() {
    function getCursorPosition(o) {
        if ($.browser.msie) {
            o.focus();
            var range = document.selection.createRange();
            var dup = range.duplicate();
            dup.moveToElementText(o);
            dup.setEndPoint('EndToEnd', range);
            return {
                s: dup.text.length - range.text.length,
                e: dup.text.length - range.text.length + range.text.length
            }
        }
        else {
            return {
                s: o.selectionStart,
                e: o.selectionEnd
            }
        }
    }

    function insertTag(textareaId, tag, filter) {
        var o = $(textareaId).get()[0]; 
        var top = o.scrollTop;
        var val = o.value;
        var pos = getCursorPosition(o);
        var otag = '';
        var ctag = '';

        if (typeof(tag) == 'string') {
            otag = '<' + tag + '>'; ctag = '</' + tag + '>';
        }
        else {
            var len = tag.length - 1;
            for (var i = 0; i < tag.length; i++) {
                otag += '<' + tag[i] + '>';
                tag[len - i].match("([^ ]*)");
                ctag += '</' + RegExp.$1 + '>';
            }
        }
        if (filter == undefined) { filter = function(args) { return args; } }
        if (pos['s'] != pos['e']) {
            var co = filter(val.slice(pos['s'], pos['e']));
            o.value = val.slice(0, pos['s']) + otag + co + ctag + val.slice(pos['e']);
            o.scrollTop = top;
            if (!$.browser.msie) { o.setSelectionRange(pos['s'], pos['s']); }
        }
        else {
            o.value = val.slice(0, pos['s']) + otag + ctag + val.slice(pos['e']);
        }
    }

    jQuery.fn.insertTag = function(textareaId, tag, filter) {
        this.click(function() {
            insertTag(textareaId, tag, filter);
        });
    }
})(jQuery);;
/* jQuery plugin textselect
 * version: 0.9
 * tested on jQuery 1.3.2
 * author: Josef Moravec, josef.moravec@gmail.com
 * 
 * usage:
 * $(function() {
 *    $(document).bind('textselect', function(e) {
 *      Do stuff with e.text
 *    });    
 *   });
 *    
 */
(function($) {
$.event.special.textselect = {
  setup: function(data, namespaces) {
    $(this).data("textselected",false);
    $(this).bind('mouseup', $.event.special.textselect.handler);
  },
  teardown: function(data) {
    $(this).unbind('mouseup', $.event.special.textselect.handler);
  },
  handler: function(event) { 
    var text = $.event.special.textselect.getSelectedText().toString(); 
    if(text!='') {
      $(this).data("textselected",true);
      event.type = "textselect";
      event.text = text;
      $.event.handle.apply(this, arguments);
    }
  },
  getSelectedText: function() {
    var text = '';
    if (window.getSelection) {
      text = window.getSelection();
    } else if (document.getSelection) {
      text = document.getSelection();
    } else if (document.selection) {
      text = document.selection.createRange().text;
    }
    return text;
  }
}

$.event.special.textunselect = {
  setup: function(data, namespaces) {
    $(this).data("textselected",false);
    $(this).bind('mouseup', $.event.special.textunselect.handler);
    $(this).bind('keyup', $.event.special.textunselect.handlerKey)
  },
  teardown: function(data) {
    $(this).unbind('mouseup', $.event.special.textunselect.handler);
  },
  handler: function(event) {  
    if($(this).data("textselected")) {
      var text = $.event.special.textselect.getSelectedText().toString();
      if(text=='') {
        $(this).data("textselected",false);
        event.type = "textunselect";
        $.event.handle.apply(this, arguments);
      }
    }
  },
  handlerKey: function(event) {
    if($(this).data("textselected")) {
      var text = $.event.special.textselect.getSelectedText().toString();
      if((event.keyCode = 27) && (text=='')) { 
        $(this).data("textselected",false);
        event.type = "textunselect";
        $.event.handle.apply(this, arguments);
      }
    }
  }
}
})(jQuery);
;
(function ($) {
	// Captures right click
	$.extend($.fn, {		
		rightClick: function(handler) {
			$(this).each( function() {
				$(this).mousedown( function(e) {
					var evt = e;
					$(this).mouseup( function() {
						$(this).unbind('mouseup');
						if( evt.button == 2 ) {
							handler.call( $(this), evt );
							return false;
						} else {
							return true;
						}
					});
				});
				$(this)[0].oncontextmenu = function() {
					return false;
				}
			});
			return $(this);
		},		
		
		rightMouseDown: function(handler) {
			$(this).each( function() {
				$(this).mousedown( function(e) {
					if( e.button == 2 ) {
						handler.call( $(this), e );
						return false;
					} else {
						return true;
					}
				});
				$(this)[0].oncontextmenu = function() {
					return false;
				}
			});
			return $(this);
		},
		
		rightMouseUp: function(handler) {
			$(this).each( function() {
				$(this).mouseup( function(e) {
					if( e.button == 2 ) {
						handler.call( $(this), e );
						return false;
					} else {
						return true;
					}
				});
				$(this)[0].oncontextmenu = function() {
					return false;
				}
			});
			return $(this);
		},
		
		noContext: function() {
			$(this).each( function() {
				$(this)[0].oncontextmenu = function() {
					return false;
				}
			});
			return $(this);
		},

		noSelect: function() {
      $(this).each( function() {
        $(this)[0].unselectable = "on";
        $(this)[0].onselectstart = function() {
					return false;
				}
        $(this)[0].ondragstart = function() {
					return false;
				}
        $(this)[0].ondrag = function() {
					return false;
				}
        if ($(this)[0].style) {
          $(this)[0].MozUserSelect = "none";
          $(this)[0].WebkitUserSelect = "none";
          $(this)[0].userSelect = "none";
        }
      });
      return $(this);
		}
	});		
})(jQuery);;
// $Id$
(function ($) {
  Drupal.behaviors.kapitbisigThemeNoCopy = {
    attach: function (context, settings) {
      if (settings.kapitbisig_context.nocopy_access == false) {
        $(document).noContext();
        $.data(document.body, 'text_input_blurred', true);
        $('a, textarea, input, button, select').bind('focus', function(event) {
          if (!is_set(event.target)) {
            $.data(document.body, 'focused_element', event.srcElement);
          }
          else {
            $.data(document.body, 'focused_element', event.target);
          }
        });
        $('textarea, input').bind('focus', function(event) {
          $.data(document.body, 'text_input_blurred', false);
        });
        $('textarea, input').bind('blur', function(event) {
          $.data(document.body, 'text_input_blurred', true);
        });
        $(document).bind('keydown', function(event) {
          if (event.keyCode == 17) {
            $.data(document.body, 'start_protection', true);
          }
          // Capture CTRL+c
          if ($.data(document.body, 'text_input_blurred') && $.data(document.body, 'start_protection') && event.keyCode == 67) {
            remove_highlight_text();
          }
        });
        $(document).bind('keyup', function(event) {
          if (event.keyCode == 17) {
            $.data(document.body, 'start_protection', false);
          }
          // Capture CTRL+a
          if ($.data(document.body, 'text_input_blurred') && $.data(document.body, 'start_protection') && event.keyCode == 65) {
            remove_highlight_text();
          }
        });
        function remove_highlight_text() {
          var newFocus;
          var focusedElement;
          try {
            if (!$.browser.msie) {
              $('body:last-child').prepend('<a href="#" id="no-copy-focus-link">.</a>');
              $('#no-copy-focus-link').focus();
              $('#no-copy-focus-link').blur();
              $('#no-copy-focus-link').remove();
            }
            else {
              $('a, textarea, input, button, select').focus();
              $('a, textarea, input, button, select').blur();
            }
            focusedElement = $.data(document.body, 'focused_element');
            if (is_set(focusedElement)) {
              var tag = focusedElement.tagName.toLowerCase();
              if (focusedElement.id) {
                newFocus = tag + '#' + focusedElement.id;
              }
              else if (focusedElement.className) {
                newFocus = tag + '.' + focusedElement.className;
              }
              else {
                newFocus = tag;
              }
              $(newFocus).focus();
            } 
          }
          catch (e) {
            if (!$.browser.msie) {
              $('body:last-child').append('<a href="#" id="no-copy-focus-link"></a>');
              $('#no-copy-focus-link').focus();
              $('#no-copy-focus-link').blur();
              $('#no-copy-focus-link').remove();
            }
            else {
              $('a, textarea, input, button, select').focus();
              $('a, textarea, input, button, select').blur();
            }
          }
        }
      }
    }
  };  
})(jQuery);;
// $Id$
(function ($) {
  Drupal.behaviors.kapitbisigBlockAdsense = {
    attach: function (context, settings) {
      $.ajax({
        url:  '/philippines/block-adsense-json',
        type: 'POST',
        dataType: 'json',
        success: function(xhr) { 
          if (xhr.block_adsense) {
            $('.google-adsense-block').hide();
          }
        }
      });
    }
  };  
})(jQuery);;
jQuery.fn.extend({
	everyTime: function(interval, label, fn, times, belay) {
		return this.each(function() {
			jQuery.timer.add(this, interval, label, fn, times, belay);
		});
	},
	oneTime: function(interval, label, fn) {
		return this.each(function() {
			jQuery.timer.add(this, interval, label, fn, 1);
		});
	},
	stopTime: function(label, fn) {
		return this.each(function() {
			jQuery.timer.remove(this, label, fn);
		});
	}
});

jQuery.extend({
	timer: {
		guid: 1,
		global: {},
		regex: /^([0-9]+)\s*(.*s)?$/,
		powers: {
			// Yeah this is major overkill...
			'ms': 1,
			'cs': 10,
			'ds': 100,
			's': 1000,
			'das': 10000,
			'hs': 100000,
			'ks': 1000000
		},
		timeParse: function(value) {
			if (value == undefined || value == null)
				return null;
			var result = this.regex.exec(jQuery.trim(value.toString()));
			if (result[2]) {
				var num = parseInt(result[1], 10);
				var mult = this.powers[result[2]] || 1;
				return num * mult;
			} else {
				return value;
			}
		},
		add: function(element, interval, label, fn, times, belay) {
			var counter = 0;
			
			if (jQuery.isFunction(label)) {
				if (!times) 
					times = fn;
				fn = label;
				label = interval;
			}
			
			interval = jQuery.timer.timeParse(interval);

			if (typeof interval != 'number' || isNaN(interval) || interval <= 0)
				return;

			if (times && times.constructor != Number) {
				belay = !!times;
				times = 0;
			}
			
			times = times || 0;
			belay = belay || false;
			
			if (!element.$timers) 
				element.$timers = {};
			
			if (!element.$timers[label])
				element.$timers[label] = {};
			
			fn.$timerID = fn.$timerID || this.guid++;
			
			var handler = function() {
				if (belay && this.inProgress) 
					return;
				this.inProgress = true;
				if ((++counter > times && times !== 0) || fn.call(element, counter) === false)
					jQuery.timer.remove(element, label, fn);
				this.inProgress = false;
			};
			
			handler.$timerID = fn.$timerID;
			
			if (!element.$timers[label][fn.$timerID]) 
				element.$timers[label][fn.$timerID] = window.setInterval(handler,interval);
			
			if ( !this.global[label] )
				this.global[label] = [];
			this.global[label].push( element );
			
		},
		remove: function(element, label, fn) {
			var timers = element.$timers, ret;
			
			if ( timers ) {
				
				if (!label) {
					for ( label in timers )
						this.remove(element, label, fn);
				} else if ( timers[label] ) {
					if ( fn ) {
						if ( fn.$timerID ) {
							window.clearInterval(timers[label][fn.$timerID]);
							delete timers[label][fn.$timerID];
						}
					} else {
						for ( var fn in timers[label] ) {
							window.clearInterval(timers[label][fn]);
							delete timers[label][fn];
						}
					}
					
					for ( ret in timers[label] ) break;
					if ( !ret ) {
						ret = null;
						delete timers[label];
					}
				}
				
				for ( ret in timers ) break;
				if ( !ret ) 
					element.$timers = null;
			}
		}
	}
});

if (jQuery.browser.msie)
	jQuery(window).one("unload", function() {
		var global = jQuery.timer.global;
		for ( var label in global ) {
			var els = global[label], i = els.length;
			while ( --i )
				jQuery.timer.remove(els[i], label);
		}
	});


;
// $Id$
(function ($) {
  Drupal.behaviors.kapitbisigDateTime = {
    attach: function (context, settings) {
      var serverDateHtml;
      var serverDay;
      var serverDate;
      var serverMonth;
      var serverYear;
      var serverHour;
      var serverMinute;
      var serverSecond;
      var serverMeridiem;
      var startClock = false;
      $.ajax({
        url:  '/philippines/date-time-json',
        type: 'POST',
        dataType: 'json',
        success: function(xhr) { 
          serverDateHtml = xhr.date_html;
          serverDay   = xhr.day;
          serverDate  = xhr.date;
          serverMonth = xhr.month;
          serverYear = xhr.year;
          serverHour = Number(xhr.hour);
          serverMinute = Number(xhr.minutes); 
          serverSecond = Number(xhr.seconds);
          serverMeridiem = xhr.meridiem; 
          startClock = true; 
        }
      });
      if ($.browser.webkit || $.browser.mozilla) {
        $('#app-phil-date-time', context).before('<ul id="phil-clock"><li id="phil-second"></li><li id="phil-hour"></li><li id="phil-minute"></li><li id="phil-meridiem"></li></ul>');
        $('#app-phil-date-time', context).addClass('app-phil-calendar');
      }  
      
      $(document, context).everyTime(1000, function(i) {
        if (startClock) {	
          serverSecond++;
          if (serverSecond == 60) {
            serverSecond = 0;
            serverMinute++;
            if (serverMinute == 60) {
              serverMinute = 0;
              serverHour++;
              if (serverHour == 12) {
                $.ajax({
                  url:  '/philippines/date-time-json',
                  type: 'POST',
                  dataType: 'json',
                  beforeSend: function(xhr) { 
                    startClock = false; 
                  },
                  success: function(xhr) { 
                    serverDateHtml = xhr.date_html;
                    serverDay   = xhr.day;
                    serverDate  = xhr.date;
                    serverMonth = xhr.month;
                    serverYear = xhr.year;
                    serverHour = Number(xhr.hour);
                    serverMinute = Number(xhr.minutes); 
                    serverSecond = Number(xhr.seconds);
                    serverMeridiem = xhr.meridiem; 
                    startClock = true; 
                  }
                });						
              }
            }
          }			
          serverSec = serverSecond.toString();
          serverMin = serverMinute.toString();
          serverHr  = serverHour.toString();
          if (serverSec.length == 1) {
            serverSec = '0' + serverSec;
          }
          if (serverMin.length == 1) {
            serverMin = '0' + serverMin;
          }
          if (serverHr.length == 1) {
            serverHr = '0' + serverHr;
          }
          if ($.browser.webkit || $.browser.mozilla) {
            var sdegree = serverSec * 6;
            var srotate = "rotate(" + sdegree + "deg)";
            var mdegree = serverMin * 6;
            var mrotate = "rotate(" + mdegree + "deg)";
            var hdegree = serverHr * 30 + (serverMin / 2);
            var hrotate = "rotate(" + hdegree + "deg)";
            $('#phil-second', context).css({"-moz-transform" : srotate, "-webkit-transform" : srotate});
            $('#phil-minute', context).css({"-moz-transform" : mrotate, "-webkit-transform" : mrotate});
            $('#phil-hour', context).css({"-moz-transform" : hrotate, "-webkit-transform" : hrotate});
            $('#phil-meridiem', context).text(serverMeridiem);
            $('#app-phil-date-time', context).html('<li class="app-phil-date-time-header">' + serverMonth + ' ' + serverYear + '</li><li class="app-phil-date-time-body"><span class="app-phil-day">' + serverDay + '</span> <span class="app-phil-date">' + serverDate + '</span></li>');
          }
          else {
            $('#app-phil-date-time', context).html('<li class="app-phil-date-time-header">' + serverHr + ':' + serverMin + '.' + serverSec + ' ' + serverMeridiem + '</li>' + serverDateHtml);	
          }
        }
      });
    }
  };  
})(jQuery);;
// $Id$
(function ($) {
  var link_delay = false;
  var link_hover = false;
  var _this_link;
  $(document).ready( function() {
    // Replace form action with kapitbisig
    var pub_id = Drupal.settings.kapitbisig_context.cse_id;
    var form_action = $('#kapitbisig-find-form').attr('action');
    var timeout_val = 400;
    var timeout_id  = 0;
    try {
      if (form_action.match(/\/philippines\/find\/node/i) || form_action.match(/\/philippines\/find\/kapitbisig/i)) {    
        $('#kapitbisig-find-form').attr('action', '/philippines/find/kapitbisig').attr('method', 'GET').attr('id', 'cse-search-box');      
        $('#cse-search-box input[type=hidden]').remove();
        $('#edit-keys').attr('name', 'as_q');
        $('#cse-search-box input[type=submit]').attr('name', 'sa');
        $('#cse-search-box div.field-search-main').after('<input type="hidden" name="cx" value="partner-pub-' + pub_id + '" /><input type="hidden" name="cof" value="FORID:10" /><input type="hidden" name="ie" value="UTF-8" />');
        //$('<script type="text/javascript" src="http://www.google.com.ph/cse/brand?form=cse-search-box&amp;lang=en"></script>').insertAfter('#cse-search-box');      
        kapitbisig_search();
      }
    }
    catch (e) {
    }
    $('#main-search-menu a').bind('mouseenter', function(event) {
      var keys = escape(Drupal.checkPlain($('#edit-keys').attr('value')));
      var replacement = $(this).attr('href').replace(/\/philippines\/find\//i, '') + '/';
      replacement = replacement.replace(/node\/.*/i, 'kapitbisig/');  
      if (keys && ($(this).attr('href').match(/node\/.*/i) || $(this).attr('href').match(/kapitbisig\/.*/i))) {                  
        $(this).attr('href', '/philippines/find/' + replacement.replace(/\/.*/i, '?as_q=' + keys + '&sa=Search&cx=partner-pub-' + pub_id + '&cof=FORID:10&ie=UTF-8&siteurl=kapitbisig.com'));
      }
      else {
        $(this).attr('href', '/philippines/find/' + replacement.replace(/\/.*/i, '/' + keys));
      }
    });
    $('#main-search-menu > li > a').bind({
      mouseenter: function(event) {
        if (!link_delay) {
          link_delay = true;
          $('#main-search-menu ul').css('display', 'none');
          $(this).siblings('ul').css('display', 'block');
          clearTimeout(timeout_id);
        }
        link_hover = true;
        _this_link = this;
      },
      mouseleave: function(event) {
        link_hover = false;
        clearTimeout(timeout_id);
        timeout_id = setTimeout(main_search_menu_mouseleave, timeout_val);
      }
    });
    $('#main-search-menu ul').bind({
      mouseenter: function(event) {
        $('#main-search-menu ul').css('display', 'none');
        $(this).css('display', 'block');
        clearTimeout(timeout_id);
      },
      mouseleave: function(event) {
        clearTimeout(timeout_id);
        timeout_id = setTimeout(main_search_menu_mouseleave, timeout_val);
      }
    });
  });
  function main_search_menu_mouseleave() {
    if (!link_hover) {
      link_delay = false;
      $('#main-search-menu ul').css('display', 'none');
      $('#main-search-menu li.active-p1 ul').css('display', 'block');
    }
    else {
      $('#main-search-menu ul').css('display', 'none');
      $(_this_link).siblings('ul').css('display', 'block');
    }
  }
})(jQuery);

function kapitbisig_search() { 
  var f = document.getElementById('cse-search-box'); 
  if (!f) { 
    f = document.getElementById('searchbox_demo'); 
  } 
  if (f && f.as_q) { 
    var q = f.as_q; 
    var n = navigator; 
    var l = location; 
    var su = function () { 
      var u = document.createElement('input'); 
      var v = document.location.toString(); 
      var existingSiteurl = /(?:[?&]siteurl=)([^&#]*)/.exec(v);
      if (existingSiteurl) { 
        v = decodeURI(existingSiteurl[1]); 
      } 
      var delimIndex = v.indexOf('://'); 
      if (delimIndex >= 0) { 
        v = v.substring(delimIndex + '://'.length, v.length); 
      } 
      u.name = 'siteurl'; 
      u.value = v; 
      u.type = 'hidden'; 
      f.appendChild(u); 
    }; 
    if (n.appName == 'Microsoft Internet Explorer') { 
      var s = f.parentNode.childNodes; 
      for (var i = 0; i < s.length; i++) { 
        if (s[i].nodeName == 'SCRIPT' && s[i].attributes['src'] && s[i].attributes['src'].nodeValue == unescape('http:\x2F\x2Fwww.google.com.ph\x2Fcse\x2Fbrand?form=cse-search-box\x26amp\x3Blang=en')) { 
          su(); 
          break; 
        } 
      } 
    } 
    else { 
      su(); 
    } 
    if (n.platform == 'Win32') { 
      q.style.cssText = 'border: 1px solid #7e9db9; padding: 2px;'; 
    } 
    if (window.history.navigationMode) { 
      window.history.navigationMode = 'compatible'; 
    } 
    var b = function() { 
      if (q.value == '') { 
        q.style.background = '#FFFFFF url(http:\x2F\x2Fwww.google.com.ph\x2Fcse\x2Fintl\x2Fen\x2Fimages\x2Fgoogle_custom_search_watermark.gif) left no-repeat'; 
      } 
    }; 
    var f = function() { 
      q.style.background = '#ffffff'; 
    }; 
    q.onfocus = f; 
    q.onblur = b; 
    if (!/[&?]q=[^&]/.test(l.search)) { 
      b(); 
    } 
  } 
};
// $Id$

(function ($) {
  Drupal.behaviors.kapitbisigFindHighlightFind = {
    attach: function (context, settings) {
      var timeout_id; 
      var prev_term;
      $('#site-content').data('hold_textselect', false);
      $('#site-content').bind('textselect', function(e) {
        if (!$(this).data('hold_textselect')) {
          var content;     
          var term = jQuery.trim(e.text);
          term = term.replace(/[^A-Za-z0-9_\-' ]/g, '');
          var pattern = new RegExp(term, 'gm');      
          var tag     = e.target.tagName;
          clearTimeout(timeout_id);
          $('span.text__selected').unbind('mouseleave.kapitbisigFindHighlight');
          $('span.text__selected').unbind('mouseenter.kapitbisigFindHighlight');
          $('span.text__selected').replaceWith(prev_term);
          tag = tag.toLowerCase();
          if (tag != 'a' && tag != 'input' && tag != 'textarea' && term != '') {
            pattern = new RegExp('(>[^<>]*' + term + '[^<>]*<)', 'gm');
            var found_term = $(e.target).html().match(pattern);
            if (found_term != null) {
              found_term  = found_term[0];
              replacement = '><span class="text__selected">' + found_term.replace(/[<>]/g, '') + '</span><';
            }
            else {
              pattern = new RegExp('(' + term + ')', 'gm');
              found_term  = $(e.target).html().match(pattern);
              replacement = '<span class="text__selected">' + found_term + '</span>';
            }
            pattern = new RegExp(found_term, 'gm');
            $(e.target).html($(e.target).html().replace(pattern, replacement));
            prev_term = term;
            $('span.text__selected').bind('mouseenter.kapitbisigFindHighlight', function() {
              clearTimeout(timeout_id);
              $(this).append('<span class="target__icon"></span>');
              $(this).addClass('target__selected').bind('click.kapitbisigFindHighlight', function(event) {
                event.stopPropagation();
                $(this).unbind('click.kapitbisigFindHighlight');
                window.location.href = '/philippines/find/node/' + term;
              });
            }).bind('mouseleave.kapitbisigFindHighlight', function() {
              timeout_id = setTimeout(function() {
                $('span.text__selected').replaceWith(term);
              }, 500);
            });
          }
          else {
            $(this).data('hold_textselect', true);
          }
        }
        else {
          $(this).data('hold_textselect', false);
        }
      });
      
    }
  };
})(jQuery);;
// $Id$

(function ($) {
  Drupal.behaviors.philippineMap = {
    attach: function (context, settings) {
      var img_path        = settings.philippine_map.img_path;
      var css_enabled     = true;
      var prefix_selector = '#block-views-';
      var hot_region      = 'ncr';
      var prev_region     = 'ncr';
      var timeout_val     = 400;
      var timeout_id      = 0;
      
      // Detect if CSS is enabled
      $('#image-philippines-regions', context).attr('style', 'width: 301px;');      
      if ($('#image-philippines-regions', context).attr('width') == 300) {
        css_enabled = false;
      }
      $('#image-philippines-regions', context).removeAttr('style');
      if (css_enabled) {
        $(prefix_selector + 'armm', context).hide();
        $(prefix_selector + 'car', context).hide();
        $(prefix_selector + 'ncr', context).hide();
        $(prefix_selector + 'region1', context).hide();
        $(prefix_selector + 'region2', context).hide();
        $(prefix_selector + 'region3', context).hide();
        $(prefix_selector + 'region4a', context).hide();
        $(prefix_selector + 'region4b', context).hide();
        $(prefix_selector + 'region5', context).hide();
        $(prefix_selector + 'region6', context).hide();
        $(prefix_selector + 'region7', context).hide();
        $(prefix_selector + 'region8', context).hide();
        $(prefix_selector + 'region9', context).hide();
        $(prefix_selector + 'region10', context).hide();
        $(prefix_selector + 'region11', context).hide();
        $(prefix_selector + 'region12', context).hide();
        $(prefix_selector + 'region13', context).hide();
        $(prefix_selector + hot_region, context).show();
        $('#image-philippines-regions', context).wrap('<div class="image-philippines-map">');
        $('#image-philippines-regions', context).attr('src', img_path + 'transparent-map.png').addClass('image-philippines-base');
        // ARMM
        $('#map-philippines-armm', context).bind({
          mouseenter: function(event) {
            if (hot_region != 'armm') {
              hot_region  = 'armm';
              timeout_id  = setTimeout(philippine_map_check_mouseenter, timeout_val);
            } 
            $('#image-philippines-regions', context).addClass('image-philippines-armm').removeClass('image-philippines-base');
          },
          mouseleave: function(event) {
            hot_region = prev_region;
            clearTimeout(timeout_id);
            $('#image-philippines-regions', context).addClass('image-philippines-base').removeClass('image-philippines-armm');
          }
        });
        // CAR
        $('#map-philippines-car', context).bind({
          mouseenter: function(event) {
            if (hot_region != 'car') {
              hot_region  = 'car';
              timeout_id  = setTimeout(philippine_map_check_mouseenter, timeout_val);
            } 
            $('#image-philippines-regions', context).addClass('image-philippines-car').removeClass('image-philippines-base');
          },
          mouseleave: function(event) {
            hot_region = prev_region;
            clearTimeout(timeout_id);
            $('#image-philippines-regions', context).addClass('image-philippines-base').removeClass('image-philippines-car');
          }
        });
        // NCR
        $('#map-philippines-ncr', context).bind({
          mouseenter: function(event) {
            if (hot_region != 'ncr') {
              hot_region  = 'ncr';
              timeout_id  = setTimeout(philippine_map_check_mouseenter, timeout_val);
            } 
            $('#image-philippines-regions', context).addClass('image-philippines-ncr').removeClass('image-philippines-base');
          },
          mouseleave: function(event) {
            hot_region = prev_region;
            clearTimeout(timeout_id);
            $('#image-philippines-regions', context).addClass('image-philippines-base').removeClass('image-philippines-ncr');
          }
        });
        // Region I
        $('#map-philippines-region1', context).bind({
          mouseenter: function(event) {
            if (hot_region != 'region1') {
              hot_region  = 'region1';
              timeout_id  = setTimeout(philippine_map_check_mouseenter, timeout_val);
            }
            $('#image-philippines-regions', context).addClass('image-philippines-region1').removeClass('image-philippines-base');
          },
          mouseleave: function(event) {
            hot_region = prev_region;
            clearTimeout(timeout_id);
            $('#image-philippines-regions', context).addClass('image-philippines-base').removeClass('image-philippines-region1');
          }
        });
        // Region II
        $('#map-philippines-region2', context).bind({
          mouseenter: function(event) {
            if (hot_region != 'region2') {
              hot_region  = 'region2';
              timeout_id  = setTimeout(philippine_map_check_mouseenter, timeout_val);
            }        
            $('#image-philippines-regions', context).addClass('image-philippines-region2').removeClass('image-philippines-base');
          },
          mouseleave: function(event) {
            hot_region = prev_region;
            clearTimeout(timeout_id);
            $('#image-philippines-regions', context).addClass('image-philippines-base').removeClass('image-philippines-region2');
          }
        });
        // Region III
        $('#map-philippines-region3', context).bind({
          mouseenter: function(event) {
            if (hot_region != 'region3') {
              hot_region  = 'region3';
              timeout_id  = setTimeout(philippine_map_check_mouseenter, timeout_val);
            } 
            $('#image-philippines-regions', context).addClass('image-philippines-region3').removeClass('image-philippines-base');
          },
          mouseleave: function(event) {
            hot_region = prev_region;
            clearTimeout(timeout_id);
            $('#image-philippines-regions', context).addClass('image-philippines-base').removeClass('image-philippines-region3');
          }
        });
        // Region IV-A
        $('#map-philippines-region4a', context).bind({
          mouseenter: function(event) {
            if (hot_region != 'region4a') {
              hot_region  = 'region4a';
              timeout_id  = setTimeout(philippine_map_check_mouseenter, timeout_val);
            } 
            $('#image-philippines-regions', context).addClass('image-philippines-region4a').removeClass('image-philippines-base');
          },
          mouseleave: function(event) {
            hot_region = prev_region;
            clearTimeout(timeout_id);
            $('#image-philippines-regions', context).addClass('image-philippines-base').removeClass('image-philippines-region4a');
          }
        });
        // Region IV-B
        $('#map-philippines-region4b', context).bind({
          mouseenter: function(event) {
            if (hot_region != 'region4b') {
              hot_region  = 'region4b';
              timeout_id  = setTimeout(philippine_map_check_mouseenter, timeout_val);
            } 
            $('#image-philippines-regions', context).addClass('image-philippines-region4b').removeClass('image-philippines-base');
          },
          mouseleave: function(event) {
            hot_region = prev_region;
            clearTimeout(timeout_id);
            $('#image-philippines-regions', context).addClass('image-philippines-base').removeClass('image-philippines-region4b');
          }
        });
        // Region V
        $('#map-philippines-region5', context).bind({
          mouseenter: function(event) {
            if (hot_region != 'region5') {
              hot_region  = 'region5';
              timeout_id  = setTimeout(philippine_map_check_mouseenter, timeout_val);
            } 
            $('#image-philippines-regions', context).addClass('image-philippines-region5').removeClass('image-philippines-base');
          },
          mouseleave: function(event) {
            hot_region = prev_region;
            clearTimeout(timeout_id);
            $('#image-philippines-regions', context).addClass('image-philippines-base').removeClass('image-philippines-region5');
          }
        });
        // Region VI
        $('#map-philippines-region6', context).bind({
          mouseenter: function(event) {
            if (hot_region != 'region6') {
              hot_region  = 'region6';
              timeout_id  = setTimeout(philippine_map_check_mouseenter, timeout_val);
            } 
            $('#image-philippines-regions', context).addClass('image-philippines-region6').removeClass('image-philippines-base');
          },
          mouseleave: function(event) {
            hot_region = prev_region;
            clearTimeout(timeout_id);
            $('#image-philippines-regions', context).addClass('image-philippines-base').removeClass('image-philippines-region6');
          }
        });
        // Region VII
        $('#map-philippines-region7', context).bind({
          mouseenter: function(event) {
            if (hot_region != 'region7') {
              hot_region  = 'region7';
              timeout_id  = setTimeout(philippine_map_check_mouseenter, timeout_val);
            } 
            $('#image-philippines-regions', context).addClass('image-philippines-region7').removeClass('image-philippines-base');
          },
          mouseleave: function(event) {
            hot_region = prev_region;
            clearTimeout(timeout_id);
            $('#image-philippines-regions', context).addClass('image-philippines-base').removeClass('image-philippines-region7');
          }
        });
        // Region VIII
        $('#map-philippines-region8', context).bind({
          mouseenter: function(event) {
            if (hot_region != 'region8') {
              hot_region  = 'region8';
              timeout_id  = setTimeout(philippine_map_check_mouseenter, timeout_val);
            } 
            $('#image-philippines-regions', context).addClass('image-philippines-region8').removeClass('image-philippines-base');
          },
          mouseleave: function(event) {
            hot_region = prev_region;
            clearTimeout(timeout_id);
            $('#image-philippines-regions', context).addClass('image-philippines-base').removeClass('image-philippines-region8');
          }
        });
        // Region IX
        $('#map-philippines-region9', context).bind({
          mouseenter: function(event) {
            if (hot_region != 'region9') {
              hot_region  = 'region9';
              timeout_id  = setTimeout(philippine_map_check_mouseenter, timeout_val);
            } 
            $('#image-philippines-regions', context).addClass('image-philippines-region9').removeClass('image-philippines-base');
          },
          mouseleave: function(event) {
            hot_region = prev_region;
            clearTimeout(timeout_id);
            $('#image-philippines-regions', context).addClass('image-philippines-base').removeClass('image-philippines-region9');
          }
        });
        // Region X
        $('#map-philippines-region10', context).bind({
          mouseenter: function(event) {
            if (hot_region != 'region10') {
              hot_region  = 'region10';
              timeout_id  = setTimeout(philippine_map_check_mouseenter, timeout_val);
            } 
            $('#image-philippines-regions', context).addClass('image-philippines-region10').removeClass('image-philippines-base');
          },
          mouseleave: function(event) {
            hot_region = prev_region;
            clearTimeout(timeout_id);
            $('#image-philippines-regions', context).addClass('image-philippines-base').removeClass('image-philippines-region10');
          }
        });
        // Region XI
        $('#map-philippines-region11', context).bind({
          mouseenter: function(event) {
            if (hot_region != 'region11') {
              hot_region  = 'region11';
              timeout_id  = setTimeout(philippine_map_check_mouseenter, timeout_val);
            } 
            $('#image-philippines-regions', context).addClass('image-philippines-region11').removeClass('image-philippines-base');
          },
          mouseleave: function(event) {
            hot_region = prev_region;
            clearTimeout(timeout_id);
            $('#image-philippines-regions', context).addClass('image-philippines-base').removeClass('image-philippines-region11');
          }
        });
        // Region XII
        $('#map-philippines-region12', context).bind({
          mouseenter: function(event) {
            if (hot_region != 'region12') {
              hot_region  = 'region12';
              timeout_id  = setTimeout(philippine_map_check_mouseenter, timeout_val);
            } 
            $('#image-philippines-regions', context).addClass('image-philippines-region12').removeClass('image-philippines-base');
          },
          mouseleave: function(event) {
            hot_region = prev_region;
            clearTimeout(timeout_id);
            $('#image-philippines-regions', context).addClass('image-philippines-base').removeClass('image-philippines-region12');
          }
        });
        // Region XIII
        $('#map-philippines-region13', context).bind({
          mouseenter: function(event) {
            if (hot_region != 'region13') {
              hot_region  = 'region13';
              timeout_id  = setTimeout(philippine_map_check_mouseenter, timeout_val);
            } 
            $('#image-philippines-regions', context).addClass('image-philippines-region13').removeClass('image-philippines-base');
          },
          mouseleave: function(event) {
            hot_region = prev_region;
            clearTimeout(timeout_id);
            $('#image-philippines-regions', context).addClass('image-philippines-base').removeClass('image-philippines-region13');
          }
        });
      }
      function philippine_map_check_mouseenter() {
        $(prefix_selector + prev_region, context).hide();
        $(prefix_selector + hot_region, context).fadeIn();
        prev_region = hot_region;
      }    
    } 
  };

})(jQuery);;
(function ($) {

$(document).ready(function() {

  // Accepts a string; returns the string with regex metacharacters escaped. The returned string
  // can safely be used at any point within a regex to match the provided literal string. Escaped
  // characters are [ ] { } ( ) * + ? - . , \ ^ $ # and whitespace. The character | is excluded
  // in this function as it's used to separate the domains names.
  RegExp.escapeDomains = function(text) {
    return (text) ? text.replace(/[-[\]{}()*+?.,\\^$#\s]/g, "\\$&") : '';
  }

  // Attach onclick event to document only and catch clicks on all elements.
  $(document.body).click(function(event) {
    // Catch the closest surrounding link of a clicked element.
    $(event.target).closest("a,area").each(function() {

      var ga = Drupal.settings.googleanalytics;
      // Expression to check for absolute internal links.
      var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i");
      // Expression to check for special links like gotwo.module /go/* links.
      var isInternalSpecial = new RegExp("(\/go\/.*)$", "i");
      // Expression to check for download links.
      var isDownload = new RegExp("\\.(" + ga.trackDownloadExtensions + ")$", "i");
      // Expression to check for the sites cross domains.
      var isCrossDomain = new RegExp("^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\/.*(" + RegExp.escapeDomains(ga.trackCrossDomains) + ")", "i");

      // Is the clicked URL internal?
      if (isInternal.test(this.href)) {
        // Is download tracking activated and the file extension configured for download tracking?
        if (ga.trackDownload && isDownload.test(this.href)) {
          // Download link clicked.
          var extension = isDownload.exec(this.href);
          _gaq.push(["_trackEvent", "Downloads", extension[1].toUpperCase(), this.href.replace(isInternal, '')]);
        }
        else if (isInternalSpecial.test(this.href)) {
          // Keep the internal URL for Google Analytics website overlay intact.
          _gaq.push(["_trackPageview", this.href.replace(isInternal, '')]);
        }
      }
      else {
        if (ga.trackMailto && $(this).is("a[href^=mailto:],area[href^=mailto:]")) {
          // Mailto link clicked.
          _gaq.push(["_trackEvent", "Mails", "Click", this.href.substring(7)]);
        }
        else if (ga.trackOutbound && this.href) {
          if (ga.trackDomainMode == 2 && isCrossDomain.test(this.href)) {
            // Top-level cross domain clicked. document.location is handled by _link internally.
            _gaq.push(["_link", this.href]);
          }
          else if (ga.trackOutboundAsPageview) {
            // Track all external links as page views after URL cleanup.
            // Currently required, if click should be tracked as goal.
            _gaq.push(["_trackPageview", '/outbound/' + this.href.replace(/^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\//i, '').split('/').join('--')]);
          }
          else {
            // External link clicked.
            _gaq.push(["_trackEvent", "Outbound links", "Click", this.href]);
          }
        }
      }
    });
  });
});

})(jQuery);
;

