/*	ColorBox v1.3.6 - a full featured, light-weight, customizable lightbox based on jQuery 1.3 */
(function(c){function r(b,d){d=d==="x"?m.width():m.height();return typeof b==="string"?Math.round(b.match(/%/)?d/100*parseInt(b,10):parseInt(b,10)):b}function M(b){b=c.isFunction(b)?b.call(i):b;return a.photo||b.match(/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i)}function Y(){for(var b in a)if(c.isFunction(a[b])&&b.substring(0,2)!=="on")a[b]=a[b].call(i);a.rel=a.rel||i.rel;a.href=a.href||i.href;a.title=a.title||i.title}function Z(b){i=b;a=c.extend({},c(i).data(q));Y();if(a.rel&&a.rel!=="nofollow"){g= c(".cboxElement").filter(function(){return(c(this).data(q).rel||this.rel)===a.rel});j=g.index(i);if(j<0){g=g.add(i);j=g.length-1}}else{g=c(i);j=0}if(!B){C=B=n;N=i;N.blur();c(document).bind("keydown.cbox_close",function(d){if(d.keyCode===27){d.preventDefault();e.close()}}).bind("keydown.cbox_arrows",function(d){if(g.length>1)if(d.keyCode===37){d.preventDefault();D.click()}else if(d.keyCode===39){d.preventDefault();E.click()}});a.overlayClose&&s.css({cursor:"pointer"}).one("click",e.close);c.event.trigger(aa); a.onOpen&&a.onOpen.call(i);s.css({opacity:a.opacity}).show();a.w=r(a.initialWidth,"x");a.h=r(a.initialHeight,"y");e.position(0);O&&m.bind("resize.cboxie6 scroll.cboxie6",function(){s.css({width:m.width(),height:m.height(),top:m.scrollTop(),left:m.scrollLeft()})}).trigger("scroll.cboxie6")}P.add(D).add(E).add(t).add(Q).hide();R.html(a.close).show();e.slideshow();e.load()}var q="colorbox",F="hover",n=true,e,x=c.browser.msie&&!c.support.opacity,O=x&&c.browser.version<7,aa="cbox_open",H="cbox_load",S= "cbox_complete",T="resize.cbox_resize",s,k,u,p,U,V,W,X,g,m,l,I,J,K,Q,P,t,E,D,R,y,z,v,w,i,N,j,a,B,C,$={transition:"elastic",speed:350,width:false,height:false,innerWidth:false,innerHeight:false,initialWidth:"400",initialHeight:"400",maxWidth:false,maxHeight:false,scalePhotos:n,scrolling:n,inline:false,html:false,iframe:false,photo:false,href:false,title:false,rel:false,opacity:0.9,preloading:n,current:"image {current} of {total}",previous:"previous",next:"next",close:"close",open:false,overlayClose:n, slideshow:false,slideshowAuto:n,slideshowSpeed:2500,slideshowStart:"start slideshow",slideshowStop:"stop slideshow",onOpen:false,onLoad:false,onComplete:false,onCleanup:false,onClosed:false};e=c.fn.colorbox=function(b,d){var h=this;if(!h.length)if(h.selector===""){h=c("<a/>");b.open=n}else return this;h.each(function(){var f=c.extend({},c(this).data(q)?c(this).data(q):$,b);c(this).data(q,f).addClass("cboxElement");if(d)c(this).data(q).onComplete=d});b&&b.open&&Z(h);return this};e.init=function(){function b(d){return c('<div id="cbox'+ d+'"/>')}m=c(window);k=c('<div id="colorbox"/>');s=b("Overlay").hide();u=b("Wrapper");p=b("Content").append(l=b("LoadedContent").css({width:0,height:0}),J=b("LoadingOverlay"),K=b("LoadingGraphic"),Q=b("Title"),P=b("Current"),t=b("Slideshow"),E=b("Next"),D=b("Previous"),R=b("Close"));u.append(c("<div/>").append(b("TopLeft"),U=b("TopCenter"),b("TopRight")),c("<div/>").append(V=b("MiddleLeft"),p,W=b("MiddleRight")),c("<div/>").append(b("BottomLeft"),X=b("BottomCenter"),b("BottomRight"))).children().children().css({"float":"left"}); I=c("<div style='position:absolute; top:0; left:0; width:9999px; height:0;'/>");c("body").prepend(s,k.append(u,I));if(x){k.addClass("cboxIE");O&&s.css("position","absolute")}p.children().bind("mouseover mouseout",function(){c(this).toggleClass(F)}).addClass(F);y=U.height()+X.height()+p.outerHeight(n)-p.height();z=V.width()+W.width()+p.outerWidth(n)-p.width();v=l.outerHeight(n);w=l.outerWidth(n);k.css({"padding-bottom":y,"padding-right":z}).hide();E.click(e.next);D.click(e.prev);R.click(e.close);p.children().removeClass(F); c(".cboxElement").live("click",function(d){if(d.button!==0&&typeof d.button!=="undefined")return n;else{Z(this);return false}})};e.position=function(b,d){function h(A){U[0].style.width=X[0].style.width=p[0].style.width=A.style.width;K[0].style.height=J[0].style.height=p[0].style.height=V[0].style.height=W[0].style.height=A.style.height}var f=m.height();f=Math.max(f-a.h-v-y,0)/2+m.scrollTop();var o=Math.max(document.documentElement.clientWidth-a.w-w-z,0)/2+m.scrollLeft();b=k.width()===a.w+w&&k.height()=== a.h+v?0:b;u[0].style.width=u[0].style.height="9999px";k.dequeue().animate({width:a.w+w,height:a.h+v,top:f,left:o},{duration:b,complete:function(){h(this);C=false;u[0].style.width=a.w+w+z+"px";u[0].style.height=a.h+v+y+"px";d&&d()},step:function(){h(this)}})};e.resize=function(b){function d(){a.w=a.w||l.width();a.w=a.mw&&a.mw<a.w?a.mw:a.w;return a.w}function h(){a.h=a.h||l.height();a.h=a.mh&&a.mh<a.h?a.mh:a.h;return a.h}function f(G){e.position(G,function(){if(B){if(x){A&&l.fadeIn(100);k[0].style.removeAttribute("filter")}if(a.iframe)l.append("<iframe id='cboxIframe'"+ (a.scrolling?" ":"scrolling='no'")+" name='iframe_"+(new Date).getTime()+"' frameborder=0 src='"+a.href+"' "+(x?"allowtransparency='true'":"")+" />");l.show();Q.show().html(a.title);if(g.length>1){P.html(a.current.replace(/\{current\}/,j+1).replace(/\{total\}/,g.length)).show();E.html(a.next).show();D.html(a.previous).show();a.slideshow&&t.show()}J.hide();K.hide();c.event.trigger(S);a.onComplete&&a.onComplete.call(i);a.transition==="fade"&&k.fadeTo(L,1,function(){x&&k[0].style.removeAttribute("filter")}); m.bind(T,function(){e.position(0)})}})}if(B){var o,A,L=a.transition==="none"?0:a.speed;m.unbind(T);if(b){l.remove();l=c('<div id="cboxLoadedContent"/>').html(b);l.hide().appendTo(I).css({width:d(),overflow:a.scrolling?"auto":"hidden"}).css({height:h()}).prependTo(p);c("#cboxPhoto").css({cssFloat:"none"});O&&c("select:not(#colorbox select)").filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one("cbox_cleanup",function(){this.style.visibility="inherit"});a.transition=== "fade"&&k.fadeTo(L,0,function(){f(0)})||f(L);if(a.preloading&&g.length>1){b=j>0?g[j-1]:g[g.length-1];o=j<g.length-1?g[j+1]:g[0];o=c(o).data(q).href||o.href;b=c(b).data(q).href||b.href;M(o)&&c("<img />").attr("src",o);M(b)&&c("<img />").attr("src",b)}}else setTimeout(function(){var G=l.wrapInner("<div style='overflow:auto'></div>").children();a.h=G.height();l.css({height:a.h});G.replaceWith(G.children());e.position(L)},1)}};e.load=function(){var b,d,h,f=e.resize;C=n;i=g[j];a=c.extend({},c(i).data(q)); Y();c.event.trigger(H);a.onLoad&&a.onLoad.call(i);a.h=a.height?r(a.height,"y")-v-y:a.innerHeight?r(a.innerHeight,"y"):false;a.w=a.width?r(a.width,"x")-w-z:a.innerWidth?r(a.innerWidth,"x"):false;a.mw=a.w;a.mh=a.h;if(a.maxWidth){a.mw=r(a.maxWidth,"x")-w-z;a.mw=a.w&&a.w<a.mw?a.w:a.mw}if(a.maxHeight){a.mh=r(a.maxHeight,"y")-v-y;a.mh=a.h&&a.h<a.mh?a.h:a.mh}b=a.href;J.show();K.show();if(a.inline){c('<div id="cboxInlineTemp" />').hide().insertBefore(c(b)[0]).bind(H+" cbox_cleanup",function(){c(this).replaceWith(l.children())}); f(c(b))}else if(a.iframe)f(" ");else if(a.html)f(a.html);else if(M(b)){d=new Image;d.onload=function(){var o;d.onload=null;d.id="cboxPhoto";c(d).css({margin:"auto",border:"none",display:"block",cssFloat:"left"});if(a.scalePhotos){h=function(){d.height-=d.height*o;d.width-=d.width*o};if(a.mw&&d.width>a.mw){o=(d.width-a.mw)/d.width;h()}if(a.mh&&d.height>a.mh){o=(d.height-a.mh)/d.height;h()}}if(a.h)d.style.marginTop=Math.max(a.h-d.height,0)/2+"px";f(d);g.length>1&&c(d).css({cursor:"pointer"}).click(e.next); if(x)d.style.msInterpolationMode="bicubic"};d.src=b}else c("<div />").appendTo(I).load(b,function(o,A){A==="success"?f(this):f(c("<p>Request unsuccessful.</p>"))})};e.next=function(){if(!C){j=j<g.length-1?j+1:0;e.load()}};e.prev=function(){if(!C){j=j>0?j-1:g.length-1;e.load()}};e.slideshow=function(){function b(){t.text(a.slideshowStop).bind(S,function(){h=setTimeout(e.next,a.slideshowSpeed)}).bind(H,function(){clearTimeout(h)}).one("click",function(){d();c(this).removeClass(F)});k.removeClass(f+ "off").addClass(f+"on")}var d,h,f="cboxSlideshow_";t.bind("cbox_closed",function(){t.unbind();clearTimeout(h);k.removeClass(f+"off "+f+"on")});d=function(){clearTimeout(h);t.text(a.slideshowStart).unbind(S+" "+H).one("click",function(){b();h=setTimeout(e.next,a.slideshowSpeed);c(this).removeClass(F)});k.removeClass(f+"on").addClass(f+"off")};if(a.slideshow&&g.length>1)a.slideshowAuto?b():d()};e.close=function(){c.event.trigger("cbox_cleanup");a.onCleanup&&a.onCleanup.call(i);B=false;c(document).unbind("keydown.cbox_close keydown.cbox_arrows"); m.unbind(T+" resize.cboxie6 scroll.cboxie6");s.css({cursor:"auto"}).fadeOut("fast");k.stop(n,false).fadeOut("fast",function(){c("#colorbox iframe").attr("src","about:blank");l.remove();k.css({opacity:1});try{N.focus()}catch(b){}c.event.trigger("cbox_closed");a.onClosed&&a.onClosed.call(i)})};e.element=function(){return c(i)};e.settings=$;c(e.init)})(jQuery);///////SCROLLER///////


/*************************************************************
  TAB JAVASCRIPT
**************************************************************/
/*
$(document).ready(function(){
	$('ul.tabNav a').click(function() {
    var cur_img = $(this).children().first('img');
    var active_src = $(cur_img).attr("src");
    if ($(cur_img).attr("class") != 'active_img')
    {
      var src = $(cur_img).attr("src").replace(".gif", "_over.gif");
      $(cur_img).attr("src", src);
      $(this).children().first('img').addClass('active_img');
    
      var curChildIndex = $(this).parent().prevAll().length + 1;
      $(this).parent().parent().children('.currentTab').removeClass('currentTab');
      $(this).parent().addClass('currentTab');
      $(this).parent().parent().next('.tabContainer').children('.currentTab').hide(0,function() {
        $(this).removeClass('currentTab');
        $(this).parent().children('div:nth-child('+curChildIndex+')').show(0,function() {
          $(this).addClass('currentTab');
        });
        var prev_image = $(this).first('img');
        alert($(this).attr('src'));
        //$(this).children().children().first('img').removeClass('active_img');
        //alert($(this).children().children().first('img').attr("src"));
        //var inactive_src = $(this).children().children().first('img').attr("src").replace("_over.gif", ".gif");
        //$(this).children().children().first('img').attr("src", inactive_src);
      });
    }
		return false;
	});
}); */

/*************************************************************
  TAB JAVASCRIPT ENDS
**************************************************************/

navHover = function() {
	var lis = document.getElementById("navmenu-h").getElementsByTagName("LI");
	for (var i=0; i<lis.length; i++) {
		lis[i].onmouseover=function() {
			this.className+=" iehover";
		}
		lis[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", navHover);


function update(e, dd)
{
	for (j=1; j < dd.length; j++)
	{
		dd[j][0] = true;
	}

	for (j=1; j < dd[0].length; j++)
	{
		for (i=1; i < dd.length; i++)
		{
			current = dd[i][j].split("|");
			value = current[0];
			choice = current[0];
			if (current.length == 2) choice = current[1];
			if (value != document[dd[0][0]][dd[0][j]][document[dd[0][0]][dd[0][j]].selectedIndex].value) dd[i][0] = false;
		}
		if (e == document[dd[0][0]][dd[0][j]])
		{
			dropdown(j+1,dd);
			for (k=j+2; k < dd[0].length; k++)
			{
				document[dd[0][0]][dd[0][k]].length = 0;
			}
			break;
		}
	}
}

function dropdown(item,dd)
{
	var pre1 = "";
	var j = 1;
	document[dd[0][0]][dd[0][item]].options.length = 0;
	document[dd[0][0]][dd[0][item]].options[0] = new Option('- Select Model -');
	document[dd[0][0]][dd[0][item]].options[0].selected = true;
	for (i=1; i < dd.length; i++)
	{
		if (dd[i][0] || item == 1)
		{
			current = dd[i][item].split("|");
			value = current[0];
			choice = current[0];
			if (current.length == 2) choice = current[1];
			if (value != pre1)
			{
				var op = new Option(choice, value);
				document[dd[0][0]][dd[0][item]].options[j] = op;
				j++;
				pre1 = value;
			}
		}
	}
}

function imgToggle(img)
{
  //alert('long_Desc = '+ img.longdesc);
  if (img.longdesc != "on" && img.className != 'active_img')
  {
    if(-1 != img.src.indexOf('_over'))
    {
      if (-1 != img.src.indexOf('.gif'))
        img.src = img.src.replace(/\_over.gif/, ".gif");
      if (-1 != img.src.indexOf('_over.jpg'))
        img.src = img.src.replace(/\_over.jpg/, ".jpg");
      if (-1 != img.src.indexOf('_over.png'))
        img.src = img.src.replace(/\_over.png/, ".png");
      if (-1 != img.src.indexOf('_over.jpeg'))
        img.src = img.src.replace(/\_over.jpeg/, ".jpeg");
    }
    else if (img.className != 'active_img')
    {
      if (-1 != img.src.indexOf('.gif'))
        img.src = img.src.replace(/\.gif/, "_over.gif");
      if (-1 != img.src.indexOf('.jpg'))
        img.src = img.src.replace(/\.jpg/, "_over.jpg");
      if (-1 != img.src.indexOf('.png'))
        img.src = img.src.replace(/\.png/, "_over.png");
      if (-1 != img.src.indexOf('.jpeg'))
        img.src = img.src.replace(/\.jpeg/, "_over.jpeg");
    }
  }
}

function seton(img)
	{ img.src = img.src.replace(/\.gif/, "_clicked.gif"); }

function setoff(img)
	{ img.src = img.src.replace(/\_clicked.gif/, ".gif"); }


function sendMail()
{
  var $inputs = $('#email_form :input');

  var values = '';
  $inputs.each(function() {
    var input_val = $(this).val();
    if (!input_val) input_val = 'empty';
      values += input_val + '/';
  });
  //alert ('http://www.cell-c.co.za//includes/sendArticle/' + values);
  $.fn.colorbox({href:'http://www.cell-c.co.za//includes/sendArticle/' + values});
  return false;
  //$.fn.colorbox.close();
}


/*******

Gmaps JS.

********/


  function add_input(item, title)
  {
    if (item.value == "")
    {
      item.value = title;
    }
  }

  function clear_input(item, title)
  {
    if (item.value == title)
    {
      item.value = "";
    }
  }


  function add_input1(item, title, span_id)
  {
    if (item.value == "")
    {
			if (title == 'Choose Password' || title == 'Old Password' || title == 'Confirm Password' || title == 'Enter Password') item.type = 'text';
      item.value = title;
    }
    //$(span_id).html('');
  }

  function clear_input1(item, title, span_id)
  {
    if (item.value == title)
    {
      item.value = "";
    }
		if (title == 'Which publication do you write for') title = 'Publication';
		if (title == 'Choose Password' || title == 'Old Password' || title == 'Confirm Password' || title == 'Enter Password') item.type = 'password';
    //$(span_id).html("<span> &lt;&lt; " + title + "</span>");
  }


  $(document).ready(function(){
    $("a[rel='press_photos']").colorbox();
    $("#tagcload_b").colorbox({width:"50%", inline:true, href:"#tagcloud_popup"});
    $("#tagcload_b1").colorbox({width:"50%", inline:true, href:"#tagcloud_popup"});
    $("#tagcload_b2").colorbox({width:"50%", inline:true, href:"#tagcloud_popup"});
    $("#tagcload_b3").colorbox({width:"50%", inline:true, href:"#tagcloud_popup"});
    $("#tagcload_b4").colorbox({width:"50%", inline:true, href:"#tagcloud_popup"});
    $("#tagcload_b5").colorbox({width:"50%", inline:true, href:"#tagcloud_popup"});
    $("#tagcload_b6").colorbox({width:"50%", inline:true, href:"#tagcloud_popup"});
    $("#tagcload_b7").colorbox({width:"50%", inline:true, href:"#tagcloud_popup"});
    $("#extra_terms").colorbox({width:"50%"});

		$('div.top li a').click(function() {
			setCookie('cellc_menu_type', 'top_menu');
		});
		$('div.bot_menu_bars a').click(function() {
			setCookie('cellc_menu_type', 'sitemap_menu');
		});
		$('div.bot_menu_bars_last a').click(function() {
			setCookie('cellc_menu_type', 'sitemap_menu');
		});
		$('div.sm_bg div a').click(function() {
			setCookie('cellc_menu_type', 'social_media_menu');
		});
  });



//==============================================
//== Ajax Function call to post form
//==============================================
function updateDiv(elementID, strURL, formID) {
  var url = "http://www.cell-c.co.za/" + strURL;
  var pars = $(formID).serialize();
  //alert (pars);
  $.ajax({
    type: "POST",
    url: url,
    data: pars,
    success: function(data){
      $(elementID).html(data);
    }
  });
}

function updateDevices (elementID, elementID2, strURL, formID) {
  var url = "http://www.cell-c.co.za/" + strURL;

  var pars = $(formID).serialize();
  //alert (pars);
  $.ajax({
    type: "POST",
    url: url,
    data: pars,
    success: function(data){
      var update = data.split('|');
      $(elementID).html(update[0]);
      //alert(update[0]);
      $(elementID2).html(update[1]);
    }
  });
}

function getitEmail (elementID, strURL, formID) {
  var url = "http://www.cell-c.co.za/" + strURL;
  var pars = $(formID).serialize();

  $.ajax({
    type: "POST",
    url: url,
    data: pars,
    success: function(data){
      $(elementID).html(data);
      $('#dealForm').hide();
    }
  });
}

function reportError(request) {
  alert('Sorry. There was an error.');
}

function checkEmail(str) {
  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)
  if (str.indexOf(at)==-1){
    return false;
  }
  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
    return false;
  }
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
    return false;
  }
  if (str.indexOf(at,(lat+1))!=-1){
    return false;
  }
  if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
    return false;
  }
  if (str.indexOf(dot,(lat+2))==-1){
    return false;
  }
  if (str.indexOf(" ")!=-1){
    return false;
  }
  return true;
}

function isPhoneNumber(num)
{
  var clnNumber = '';
  var allowNumber = '0123456789';
  var i;
  //alert (num);
  for (i = 0; i < num.length; i++)
  {
    // Check that current character is number.
    var c = num.charAt(i);
    if (allowNumber.indexOf(c) == -1) return false; //!= -1) clnNumber += c;
  }
  /*
  if (clnNumber.length < 10 || clnNumber.length > 14)
  {
    //alert ('is not a number');
    return false;
  } */
  //alert ('is a number');
  return true;
}

function loadContent(elementID, url)
{
  $.ajax({
    type: "GET",
    url: url,
    success: function(data){
      $(elementID).html(data);
    }
  });


}

function getContent(elementID, strURL, realURL, ratingURL) {
  current_content_url = realURL;
  current_rating_url = ratingURL;
  loadContent(elementID, strURL);
//	loadContent('.rating_line', '/services/get_rater/'+ratingURL);

}

/*
* WS: Added for Storelocator Form.
*/


function populateDD(elementID, data)
{
  resetDD('#stores');
  for (i = 0; i < data.length; i++)
  {
    appendDD('#stores', data[i].name, data[i].id);
  }

}


function resetDD(elementID)
{

  $(elementID).html("");
}


function appendDD(elementID, nText, nValue)
{
  $("<option value='"+nValue+"'>"+nText+"</option>").appendTo(elementID);
}

function getStores(province)
{

  var url = "http://www.cell-c.co.za/about/storelist_json/" + province;

  $.getJSON(url, function (store_data) {
    populateDD('#stores', store_data);

  });

}

function lb_show(lb_id)
{
  $(lb_id).show();
}

function lb_hide(lb_id)
{
  $(lb_id).hide();
}

function av_toggle(status, id)
{
  av2_id = '#av_open_' + id;
  av1_id = '#av_block_' + id;
  if (status == 'open')
  {

    $(av1_id).show();
    $(av2_id).hide();
  }
  else
  {
    $(av1_id).hide();
    $(av2_id).show();
  }
}

function add_seo_hit (strURL, hit_type) {
  var url = "http://www.cell-c.co.za/includes/add_seo_hit";
  var pars = 'url=' + strURL + '&hit_type=' + hit_type;

  $.ajax({
    type: "POST",
    url: url,
    data: pars,
    success: function(data){
      //alert(data);
      //do nothing
    }
  });
}


function add_share_hit (strURL, title, hit_type) {
  var url = "http://www.cell-c.co.za/includes/add_share_hit";
  var pars = 'url=' + strURL + '&title=' + title + '&hit_type=' + hit_type;

  $.ajax({
    type: "POST",
    url: url,
    data: pars,
    success: function(data){
      //alert(data);
      //do nothing
    }
  });
}

/*
* Manage Social Media.
*/

function sm_switch(selected_sm, this_obj)
{

    switch (selected_sm)
    {
        case 'facebook':
        {
            // load content in iframe.
            if (window.fb_feed.location.href != 'http://www.cell-c.co.za/tools/fb_feed')
            {
                window.fb_feed.location.href='http://www.cell-c.co.za/tools/fb_feed';
            }

            SH('sm_block', 'block');
            SH('sm_facebook', 'block');
            SH('sm_twitter', 'none');
            SH('sm_mxit', 'none');
            SH('sm_email', 'none');
            SH('sm_contact', 'none');
            SH('sm_faq', 'none');
            SH('sm_flickr', 'none');
            SH('sm_closetab', 'block');
            SH('sm_opentab', 'none');
            setactive_off(this_obj);
            setactive(this_obj);

            break;
        }

        case 'twitter':
        {

            // load content in iframe.
            if (window.twitter_feed.location.href != 'http://www.cell-c.co.za/tools/twitter_feed')
            {
                window.twitter_feed.location.href='http://www.cell-c.co.za/tools/twitter_feed';
            }

            SH('sm_block', 'block');
            SH('sm_twitter', 'block');
            SH('sm_facebook', 'none');
            SH('sm_mxit', 'none');
            SH('sm_email', 'none');
            SH('sm_contact', 'none');
            SH('sm_faq', 'none');
            SH('sm_flickr', 'none');
            SH('sm_closetab', 'block');
            SH('sm_opentab', 'none');
            setactive_off(this_obj);
            setactive(this_obj);


            break;
        }


        case 'flickr':
        {
            // load content in iframe.
            if (window.flickr_feed.location.href != 'http://www.cell-c.co.za/tools/flick_feed')
            {
                window.flickr_feed.location.href='http://www.cell-c.co.za/tools/flick_feed';
            }

            SH('sm_block', 'block');
            SH('sm_flickr', 'block');
            SH('sm_twitter', 'none');
            SH('sm_facebook', 'none');
            SH('sm_mxit', 'none');
            SH('sm_email', 'none');
            SH('sm_contact', 'none');
            SH('sm_faq', 'none');
            SH('sm_closetab', 'block');
            SH('sm_opentab', 'none');
            setactive_off(this_obj);
            setactive(this_obj);

            break;
        }


    }


}


/*
    Shortcut functions for jQuery Cookie Plugin.
*/

    function setCookie(name, val)
    {
        var cookieOptions = {expires: 7, path: '/'};
        // set
        $.cookie(name, val, cookieOptions);
    }

    function getCookie(name, val)
    {
        return $.cookie(name);
    }

/****************************************************
/*                JS RATING STARTS                  *
 ****************************************************

/*
   Behaviour v1.1 by Ben Nolan, June 2005. Based largely on the work
   of Simon Willison (see comments by Simon below).

   Description:

   	Uses css selectors to apply javascript behaviours to enable
   	unobtrusive javascript in html documents.

   Usage:

	var myrules = {
		'b.someclass' : function(element){
			element.onclick = function(){
				alert(this.innerHTML);
			}
		},
		'#someid u' : function(element){
			element.onmouseover = function(){
				this.innerHTML = "BLAH!";
			}
		}
	};

	Behaviour.register(myrules);

	// Call Behaviour.apply() to re-apply the rules (if you
	// update the dom, etc).

   License:

   	This file is entirely BSD licensed.

   More information:

   	http://ripcord.co.nz/behaviour/

*/

var Behaviour = {
	list : new Array,

	register : function(sheet){
		Behaviour.list.push(sheet);
	},

	start : function(){
		Behaviour.addLoadEvent(function(){
			Behaviour.apply();
		});
	},

	apply : function(){
		for (h=0;sheet=Behaviour.list[h];h++){
			for (selector in sheet){
				list = document.getElementsBySelector(selector);

				if (!list){
					continue;
				}

				for (i=0;element=list[i];i++){
					sheet[selector](element);
				}
			}
		}
	},

	addLoadEvent : function(func){
		var oldonload = window.onload;

		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				oldonload();
				func();
			}
		}
	}
}

Behaviour.start();

/*
   The following code is Copyright (C) Simon Willison 2004.

   document.getElementsBySelector(selector)
   - returns an array of element objects from the current document
     matching the CSS selector. Selectors can contain element names,
     class names and ids and can be nested. For example:

       elements = document.getElementsBySelect('div#main p a.external')

     Will return an array of all 'a' elements with 'external' in their
     class attribute that are contained inside 'p' elements that are
     contained inside the 'div' element which has id="main"

   New in version 0.4: Support for CSS2 and CSS3 attribute selectors:
   See http://www.w3.org/TR/css3-selectors/#attribute-selectors

   Version 0.4 - Simon Willison, March 25th 2003
   -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows
   -- Opera 7 fails
*/

function getAllChildren(e) {
  // Returns all children of element. Workaround required for IE5/Windows. Ugh.
  return e.all ? e.all : e.getElementsByTagName('*');
}

document.getElementsBySelector = function(selector) {
  // Attempt to fail gracefully in lesser browsers
  if (!document.getElementsByTagName) {
    return new Array();
  }
  // Split selector in to tokens
  var tokens = selector.split(' ');
  var currentContext = new Array(document);
  for (var i = 0; i < tokens.length; i++) {
    token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;
    if (token.indexOf('#') > -1) {
      // Token is an ID selector
      var bits = token.split('#');
      var tagName = bits[0];
      var id = bits[1];
      var element = document.getElementById(id);
      if (tagName && element.nodeName.toLowerCase() != tagName) {
        // tag with that ID not found, return false
        return new Array();
      }
      // Set currentContext to contain just this element
      currentContext = new Array(element);
      continue; // Skip to next token
    }
    if (token.indexOf('.') > -1) {
      // Token contains a class selector
      var bits = token.split('.');
      var tagName = bits[0];
      var className = bits[1];
      if (!tagName) {
        tagName = '*';
      }
      // Get elements matching tag, filter them for class selector
      var found = new Array;
      var foundCount = 0;
      for (var h = 0; h < currentContext.length; h++) {
        var elements;
        if (tagName == '*') {
            elements = getAllChildren(currentContext[h]);
        } else {
            elements = currentContext[h].getElementsByTagName(tagName);
        }
        for (var j = 0; j < elements.length; j++) {
          found[foundCount++] = elements[j];
        }
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      for (var k = 0; k < found.length; k++) {
        if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
          currentContext[currentContextIndex++] = found[k];
        }
      }
      continue; // Skip to next token
    }
    // Code to deal with attribute selectors
    if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
      var tagName = RegExp.$1;
      var attrName = RegExp.$2;
      var attrOperator = RegExp.$3;
      var attrValue = RegExp.$4;
      if (!tagName) {
        tagName = '*';
      }
      // Grab all of the tagName elements within current context
      var found = new Array;
      var foundCount = 0;
      for (var h = 0; h < currentContext.length; h++) {
        var elements;
        if (tagName == '*') {
            elements = getAllChildren(currentContext[h]);
        } else {
            elements = currentContext[h].getElementsByTagName(tagName);
        }
        for (var j = 0; j < elements.length; j++) {
          found[foundCount++] = elements[j];
        }
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      var checkFunction; // This function will be used to filter the elements
      switch (attrOperator) {
        case '=': // Equality
          checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
          break;
        case '~': // Match one of space seperated words
          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
          break;
        case '|': // Match start with value followed by optional hyphen
          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
          break;
        case '^': // Match starts with value
          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
          break;
        case '$': // Match ends with value - fails with "Warning" in Opera 7
          checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
          break;
        case '*': // Match ends with value
          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
          break;
        default :
          // Just test for existence of attribute
          checkFunction = function(e) { return e.getAttribute(attrName); };
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      for (var k = 0; k < found.length; k++) {
        if (checkFunction(found[k])) {
          currentContext[currentContextIndex++] = found[k];
        }
      }
      // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
      continue; // Skip to next token
    }

    if (!currentContext[0]){
    	return;
    }

    // If we get here, token is JUST an element (not a class or ID selector)
    tagName = token;
    var found = new Array;
    var foundCount = 0;
    for (var h = 0; h < currentContext.length; h++) {
      var elements = currentContext[h].getElementsByTagName(tagName);
      for (var j = 0; j < elements.length; j++) {
        found[foundCount++] = elements[j];
      }
    }
    currentContext = found;
  }
  return currentContext;
}

/* That revolting regular expression explained
/^(\w+)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/
  \---/  \---/\-------------/    \-------/
    |      |         |               |
    |      |         |           The value
    |      |    ~,|,^,$,* or =
    |   Attribute
   Tag
*/


/****************************************************
/*                JS RATING ENDS                    *
 ****************************************************/
 /****************************************************
 *                JS RATING STARTS                  *
 ****************************************************

/*
Page:           rating.js
Created:        Aug 2006
Last Mod:       Mar 11 2007
Handles actions and requests for rating bars.
---------------------------------------------------------
ryan masuga, masugadesign.com
ryan@masugadesign.com
Licensed under a Creative Commons Attribution 3.0 License.
http://creativecommons.org/licenses/by/3.0/
See readme.txt for full credit details.
--------------------------------------------------------- */

var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
	  try {
	  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
	 } catch (e) {
	  try {
	    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	  } catch (E) {
	   xmlhttp=false
	  }
	 }
	@else
	 xmlhttp=false
	@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  try {
    xmlhttp = new XMLHttpRequest();
  } catch (e) {
    xmlhttp=false
  }
}
function myXMLHttpRequest() {
  var xmlhttplocal;
  try {
    xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
  } catch (e) {
    try {
      xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
    } catch (E) {
      xmlhttplocal=false;
    }
  }

  if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
    try {
      var xmlhttplocal = new XMLHttpRequest();
    } catch (e) {
      var xmlhttplocal=false;
      alert('couldn\'t create xmlhttp object');
    }
  }
  return(xmlhttplocal);
}

function sndReq(vote,id_num) {
  //var theUL = document.getElementById('unit_ul'+id_num); // the UL
  //alert ('unit_ul'+id_num);
  //alert('http://www.cell-c.co.za/rating/ajax/'+vote+'/'+id_num);
  xmlhttp.open('get', 'http://www.cell-c.co.za/rating/ajax/'+vote+'/'+id_num);
  xmlhttp.onreadystatechange = handleResponse;
  xmlhttp.send(null);
}

function handleResponse() {
  if(xmlhttp.readyState == 4){
    if (xmlhttp.status == 200){

      var response = xmlhttp.responseText;
      //alert(response);
      var update = new Array();

      if(response.indexOf('|') != -1) {
        update = response.split('|');
        changeText(update[0], update[1]);
      }
    }
  }
}

function changeText( div2show, text ) {
    var viewer = document.getElementById(div2show);

    viewer.innerHTML = text;
    viewer.className = 'ave_bg';
}

/* =============================================================== */
var ratingAction = {
  'a.rater' : function(element){
    element.onclick = function(){
      var parameterString = this.href; //.replace(/.*\?(.*)/, "$1");
      var parameterTokens = parameterString.split("/"); 
      var theratingID = parameterTokens[6]; //current_rating_url;
      var theVote = parameterTokens[5];

      //for testing
      //alert('sndReq('+theVote+','+theratingID+')'); return false;
      // 2,tab_content__page_1,127.0.0.1,5
      sndReq(theVote,theratingID);
      return false;
    }
  }

};
Behaviour.register(ratingAction);

/****************************************************
 *                JS RATING ENDS                    *
 ****************************************************/


/****************************************************
 *                SHARING START                      *
 ****************************************************/




 /****************************************************
 *                SHARING ENDS                    *
 ****************************************************/