// <![CDATA[
/*
* Copyright: 2005 - 2007 SI Works Internet Solutions
* If you have come across this page, its cause you are snooping through code, and are generally a developer as such
* If you would like to use some of the code on this page, please simply email support@siworks.co.za and ask permission
* it would be much appreciated, as we have worked very hard on these func.tions() and scri.pts()
* 
* Note: All functions below are to make sure that we are sticking to standards and are mainly
* for visual effects and loading events and handlers.
*
* General functions to use accross all sites and use for loading events
* @page common.functions.js
* @version 2.3.3
* @author Greg Shiers, Jarratt Ingram (SI Works Internet)
* @copyright: SI Works Internet Solutions 2005 - 2007
*/
/*
* Function to get the value of a cookie
* @usage GetCookie ( name )
* @param name
* @version 1.5
*/
function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
/*
* Function to set a new Cookie
* @usage setCookie ( name, value, expires, path, domain, secure )
* @param name
* @param value
* @param expires
* @param path
* @param domain
* @param secure
* @version 1.0
*/
function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}
/*
* Function to check all checkboxes within a table
* @usage selectCookie ( name , path , domain )
* @param name
* @param path
* @param domain
* @version 1.2
*/
function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) {
		document.cookie = name + '=' +
		( ( path ) ? ';path=' + path : '') +
		( ( domain ) ? ';domain=' + domain : '' ) +
		';expires=Thu, 01-Jan-1970 00:00:01 GMT';
	}
}
/*
* Function to open a new window
* @usage openWindow(name, url, width, height, scroll )
* @param (name, url, width, height, scroll ) name: window name, url: page to be opened, width: window width, height: window height, scroll: window scroll
* @version 1.0
*/
function openWindow ( name , url , width , height , scroll ) {
	// Set Variables to position screen in the middle of the page
	var left = (screen.width) ? (screen.width-width)/2 : 0;
	var top = (screen.height) ? (screen.height-height)/2 : 0;

	// Open the new window
	// Set all to 0 except status cuase we need to show this for usability
	window.open(url,name,'left='+left+',top='+top+',toolbar=0,location=0,directories=0,status=1, menubar=0,scrollbars='+scroll+',resizable=0,width='+width+',height='+height);
}
/*
* Function to count characters on a text field
* @usage countText ( field, countfield, maxlimit )
* @param ( field, countfield, maxlimit ) field: textarea that we are counting, countfield: field that updates with the true left characters, maxlimit: max characters
* @version 1.5
*/
function countText ( field, countfield, maxlimit ) {
	if ( document.getElementById && document.createTextNode ){
		// Lets set come variables
		var fld = document.getElementById( field );
		var count = document.getElementById ( countfield );
		// if too long...trim it!
		( fld.value.length > maxlimit ) ? fld.value = fld.value.substring( 0, maxlimit ) : count.value = ( maxlimit - fld.value.length )
	}
}
/*
* Opens a rel="external" in a new window, to validate in XHTML strict
* This code was found on http://www.sitepoint.com/article/standards-compliant-world in order to be able to validate a page with 
* opening a new link in a new window without target="_blank"
* @usage externalLinks ( externalLinks );
* @version 1.0
* @author www.sitepoint.com
*/
function externalLinks(){
	if (!document.getElementsByTagName) return; // Check for DOM / Browser compatability
	var anchors = document.getElementsByTagName("a"); // Set var, which will narrow down all the a elements in the document
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "external")
		anchor.target = "_blank";
	}
}

function show_tabs(el,lnk) {

	// Lets set some variables, get all the "a" elements within "Tabs" div
	var total = $('tabs').getElementsByTagName('a').length;
	var snum = total;
	var anum = total;
	
	// set the dyunamic objects.
	var obj = $("tab" + snum);
	var aobj = $("link" + anum);

	while (obj && aobj) {	
		// Change the display of the div to none or block;
		// if the object is displaying as none, then change it to display block, and set
		// the others to display as none
		if (obj.id == el){
			obj.appear({ duration: 1.0 });
			$('tabs').scrollTo();
		}
		else {
			obj.setStyle({display: "none"})
		}
		// Change the class in the link element
		// Make sure that the class name is not active, if is it
		// Active, then change it to "tab", and all the rest to "tab"
		if (aobj.id == lnk){
			aobj.addClassName("active")
		}
		else {
			aobj.removeClassName("active");
		}
		aobj = $("link" + anum--);
		obj = $("tab" + snum--); 	
	}
}

Event.observe (window, "load", function() {
	externalLinks();
	
	/*
	* When the page loads we are going to fetch the Weather from
	** Ajax page, which will conrol the dispaly and read the information from a cache
	*/
	if($('weather_feed_N4')) { 
		$('weather_feed_N4').update("Fetching Weather...");
	}
	if($('weather_feed_N1')) {
		$('weather_feed_N1').update("Fetching Weather...");
	}
	if($('weather_feed_all')) { 
		$('weather_feed_all').update("Fetching Weather...");
	}
	/*
	* set a timeout of 1 second after the page loads before the ajax is fired
	* just try to give the page a little time to load all the other functions
	* before we fire the ajax off, some browsers are a little tricky
	*/
	setTimeout(function() {
		try {
			/*
			* We fetch the weather feeds via Ajax 
			*/
			new Ajax.Request ('/ajax.php?menu=weatherN4', {
				method : 'get',
				onSuccess : function ( transport ) {
					$('weather_feed_N4').update(transport.responseText);
				},
				onFailure : function ( ) { 	
					$('weather_feed_N4').update('Sorry feed unavailable');
				}
			});
			/*
			* We fetch the weather feeds via Ajax 
			*/
			new Ajax.Request ('/ajax.php?menu=weatherN1', {
				method : 'get',
				onSuccess : function ( transport ) {
					$('weather_feed_N1').update(transport.responseText);
				},
				onFailure : function ( ) { 	
					$('weather_feed_N1').update('Sorry feed unavailable');
				}
			});
			/*
			* We fetch the weather feeds via Ajax 
			*/
			new Ajax.Request ('/ajax.php?menu=weatherall', {
				method : 'get',
				onSuccess : function ( transport ) {
					$('weather_feed_all').update(transport.responseText);
				},
				onFailure : function ( ) { 	
					$('weather_feed_all').update('Sorry feed unavailable');
				}
			});
		}
		catch ( error ) {
			return false;
		}	
}, 1000 );
})
/**
* Suckerfish menu loader
* @param 
* @version 
* @returns 
* @type 
* @author Greg Shiers
*/
if($('nav')){
	sfHover = function() {
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
if (window.attachEvent) window.attachEvent("onload", sfHover);
}
 function showhide (element) {
 	if ($(element).getStyle('display') == 'none') {
		$(element).blindDown({duration: 0.3});
	}
	else {
		$(element).blindUp({duration: 0.3});
	} 
 }

 
 function navigateTourism () {
 	if ($('select_type_tourism').selectedIndex == 0) {
		return false;
	}
	else {
		location.href = '/index.php?menu=tourism&submenu=section&option='+$('select_type_tourism').value;
	}
 }
  function navigateTourismSubmenus () {
 	if ($('select_type_tourism').selectedIndex == 0) {
		return false;
	}
	else {
		location.href = '/index.php?menu=tourism&submenu=cat&option='+$('select_type_tourism').value;
	}
 }
function alertit () {
	 if($('select_type_tourism')) {
	 	var values = location.href.split('option=')[1];
		$('select_type_tourism').selectedIndex = values; 
	 }
}
Event.observe(window,'load',function () {
	alertit();
})
// ]]>