// JavaScript Document

//shortcut
var $t = function(id) {
  return document.getElementById(id);
};

function OpenWindow(nURL,nWidth,nHeight) {
	
	//opens a popup window	
	nURL = nURL + '?domainname=' + document.form1.domainname.value;
	window.open (nURL,"myPopup","location=0,status=0,resizable=1,menubar=0,scrollbars=1,width=" + nWidth + ",height=" + nHeight);
	
}


function GetNewsStory() {

//retrieves the current news story
	//if (window.location.href== 'http://www.teclan.com/internetsalesprogramme/teclan_internet_sales_program.html'){
	//	document.write("<h4 style='font-size:12px; font-weight:bold; margin:0px; padding:0px;'>Yahoo update May 2008</h4>Yahoo updates again....! Read more <a href='http://www.teclan.com/articles/marketing/yahoo_update_may2008.html'>here</a>");
	//}
	//else
	//{
		//document.write("<h4 style='font-size:12px; font-weight:bold; margin:0px; padding:0px;'>teclan awarded &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Investors in People</h4>Read more about this prestigious award here <a href='http://www.teclan.com/articles/teclan/teclan_IiP_award.html'>here</a>");
	//}
	document.write("<h4 style='font-size:12px; font-weight:bold; margin:0px; padding:0px;'>PCI DSS Roadmap</h4>Are you aware that your business is required to be compliant? <br/>Read more <a href='http://www.teclan.com/articles/legislation/pci_roadmap.html'>here</a>");

}

//Toggles tabs (hosting section)

function toggleTab(tabID) {
  var theTab = $t('levels' + tabID);
  var theOtherTab = $t('levels' + (tabID == 0 ? 1 : 0));
  if (theTab && theOtherTab) {
    theOtherTab.style.left = "-3000px";
	theTab.style.left = "0px";
  }
  var titleBar = $t('level-title');
  if (titleBar) {
    var links = titleBar.getElementsByTagName("A");
	if (links[tabID]) {
	  links[tabID].id = "sel";
	}
	if (links[tabID == 0 ? 1 : 0]) {
	  links[tabID == 0 ? 1 : 0].id = "";
	}
  }
}

//Toggles tabs (Actinic section)

function toggleActTab(tabID) {
  var tabTitles = $t('actinic-titles');
  var tabContent = $t('actinic-content');
  if (tabTitles && tabContent) {
	var tabLinks = tabTitles.getElementsByTagName("A");
    for (var i = 0; i < tabLinks.length; i++) {
	  tabLinks[i].id = (i == tabID ? "sel" : "");
	  $t('act' + (i+1)).style.display = (i == tabID ? "block" : "none");
	}
  }
}

//Toggles tabs (teclan ecommerce section)

function toggleEconTab(tabID) {
  var tabTitles = $t('teclan_ecommerce');
  var tabContent = $t('actinic-content');
  if (tabTitles && tabContent) {
	var tabLinks = tabTitles.getElementsByTagName("A");
    for (var i = 0; i < tabLinks.length; i++) {
	  tabLinks[i].id = (i == tabID ? "sel" : "");
	  $t('act' + (i+1)).style.display = (i == tabID ? "block" : "none");
	}
  }
}

//Toggles tabs (Actinic section - Upgrades)

function toggleActTab2(tabID) {
  var tabTitles = $t('actinic-titles-upgrade');
  var tabContent = $t('actinic-content');
  if (tabTitles && tabContent) {
	var tabLinks = tabTitles.getElementsByTagName("A");
    for (var i = 0; i < tabLinks.length; i++) {
	  tabLinks[i].id = (i == tabID ? "sel" : "");
	  $t('act' + (i+1)).style.display = (i == tabID ? "block" : "none");
	}
  }
}

//Whoosh functions	

function WhooshDiv(id, speed) {
   if (!document.getElementById || !document.getElementsByTagName) return false;
   this.div = document.getElementById(id);
   this.subdivs = this.div.getElementsByTagName("div");
   this.remember = true;
   this.speed = speed;
}

WhooshDiv.prototype.init = function() {
   var mainInstance = this;
   for (var i = 0; i < this.subdivs.length; i++) {
      this.subdivs[i].getElementsByTagName("span")[0].onclick = function() {
	     mainInstance.toggle(this.parentNode);
      };
   }
   
   if (this.remember) {
      var regex = new RegExp("whooshdiv_" + encodeURIComponent(this.div.id) + "=([01]+)");
	  var match = regex.exec(document.cookie);
	  if (match) {
	     var states = match[1].split("");
		 for (var i = 0; i < states.length; i++) {
			this.subdivs[i].className = (states[i] == 0 ? "collapsed" : "");
		 }
	  }
   }
};

WhooshDiv.prototype.toggle = function(subdiv) {
	if (subdiv.className == "collapsed") this.expand(subdiv);
	else this.collapse(subdiv);
};

WhooshDiv.prototype.expand = function(subdiv) {
	var fullHeight = subdiv.getElementsByTagName("span")[0].offsetHeight;
	var divs = subdiv.getElementsByTagName("p");
	for (var i = 0; i < divs.length; i++) {
	   fullHeight += divs[i].offsetHeight;
	}
	var moveBy = Math.round(this.speed * divs.length);

	var mainInstance = this;

	var intId = setInterval(function() {
		var curHeight = subdiv.offsetHeight;
		var newHeight = curHeight + moveBy;
		if (newHeight < fullHeight) subdiv.style.height = newHeight + "px";
		else {
		   clearInterval(intId);
		   subdiv.style.height = "";
		   subdiv.className = "";
		   mainInstance.memorize();
		}
	}, 30);
};

WhooshDiv.prototype.collapse = function(subdiv) {
	var minHeight = subdiv.getElementsByTagName("span")[0].offsetHeight;
	var moveBy = Math.round(this.speed * subdiv.getElementsByTagName("p").length);
	var mainInstance = this;

	var intId = setInterval(function() {
		var curHeight = subdiv.offsetHeight;
		var newHeight = curHeight - moveBy;
		if (newHeight > minHeight)
			subdiv.style.height = newHeight + "px";
		else {
			clearInterval(intId);
			subdiv.style.height = "";
			subdiv.className = "collapsed";
			mainInstance.memorize();
		}
	}, 30);
};

WhooshDiv.prototype.memorize = function() {
   if (this.remember) {
      var states = new Array();
	  for (var i = 0; i < this.subdivs.length; i++) {
	     states.push(this.subdivs[i].className == "collapsed" ? 0 : 1);
	  }
	  var d = new Date();
	  d.setTime(d.getTime() + (30 * 24 * 60 * 60 * 1000));
	  document.cookie = "whooshdiv_" + encodeURIComponent(this.div.id) + "=" + states.join("") + "; expires=" + d.toGMTString() + "; path=/";
   }
};



function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
};

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
};

function checkForm(obj) {
   if (obj == null) return false;
   var msg = "";
   var elems = obj.childNodes;
   for (var i = 0; i < elems.length; i++) {
	  if (elems[i].type == "text" && !elems[i].value) {
	      msg += "\n'" + elems[i].name + "' must be supplied.";
	  }
   }
   if (msg != "") {
      window.alert("The following items must be fixed before the form can be submitted.\n" + msg + "\n");
	  return false;
   }
   return true;

}

function getRandomBanner() {
	var theBanners = new Array()
	theBanners[0] = '<br /><a href="acatalog/Actinic_Themes.html"><img src="../images/main-image-190309.jpg" alt="The World\'s largest choice of Actinic themes and templates"  title="The World\'s largest choice of Actinic themes and templates" width="526" border="0" height="260" /></a>';
	theBanners[1] = '<br/><a href="acatalog/Actinic_Themes.html"><img src="../images/banners/actinic_themes.jpg" alt="Actinic themes and templates" border="0"/></a>';
	theBanners[2] = '<h1 class="headline">TASK for Actinic</h1><a href="http://www.teclan.com/acatalog/Task_Actinic.html"><img src="../images/banners/task.jpg" alt="TASK for Actinic" border="0"/></a>';
	theBanners[3] = '<h1 class="headline">Ecommerce and Actinic hosting specialists</h1><a href="http://www.teclan.com/acatalog/Actinic_Serviced_Hosting.html"><img alt="Ecommerce hosting" src="../images/banners/hosting.jpg" border="0"/></a>';
	theBanners[4] = '<h1 class="headline">Search Engine Optimization(SEO) with teclan\'s Internet Sales Programme (ISP)</h1><a href="http://www.teclan.com/internetsalesprogramme/teclan_internet_sales_program.html"><img height="163" width="535" border="0" alt="Search Engine Optimisation" src="../images/banners/isp_banner.jpg"/></a>';
	
	var b = Math.round(Math.random()*(theBanners.length-1));
	$t("banner_theme").innerHTML = theBanners[b];
		
}


var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id) {	
  // cancel close timer
  mcancelclosetime();

  // close old layer
  mclose();

  // get new layer and show it
  ddmenuitem = document.getElementById('m' + id);
  if (ddmenuitem) {
	if (id >= 5) {
	  ddmenuitem.style.left = '0px';
	}
    ddmenuitem.style.display = 'block';
  }
}

// close showed layer
function mclose() {
  if (ddmenuitem) ddmenuitem.style.display = 'none';
}

// go close timer
function mclosetime() {
  closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime() {
  if (closetimer) {
    window.clearTimeout(closetimer);
	closetimer = null;
  }
}


function replaceimage(aDiv,id, bg,resetDiv, mlink) {
	if (aDiv) {
		if (resetDiv == 1){
			//reset all divs
			resetFragDivs();
			document.getElementById('mainimage').src=id;
			aDiv.style.backgroundImage = "url(" + bg + ")";
			document.getElementById('mainimagelink').href=mlink;
		}
		else {
			aDiv.style.backgroundImage = "url(images/hp-frag-bg.jpg)";
		}
		
	}
}

function resetFragDivs() {
	document.getElementById('group1frag').style.backgroundImage = "url(images/hp-frag-bg.jpg)";
	document.getElementById('group2frag').style.backgroundImage = "url(images/hp-frag-bg.jpg)";
	document.getElementById('group3frag').style.backgroundImage = "url(images/hp-frag-bg.jpg)";
}

/* Tool tip Javascript - used on ecommerce hosting page */

// position of the tooltip relative to the mouse in pixel //
var offsetx = 12;
var offsety =  8;

function newelement(newid)
{ 
    if(document.createElement)
    { 
        var el = document.createElement('div'); 
        el.id = newid;     
        with(el.style)
        { 
            display = 'none';
            position = 'absolute';
        } 
        el.innerHTML = '&nbsp;'; 
        document.body.appendChild(el); 
    } 
} 
var ie5 = (document.getElementById && document.all); 
var ns6 = (document.getElementById && !document.all); 
var ua = navigator.userAgent.toLowerCase();
var isapple = (ua.indexOf('applewebkit') != -1 ? 1 : 0);
function getmouseposition(e)
{
    if(document.getElementById)
    {
        var iebody=(document.compatMode && 
        	document.compatMode != 'BackCompat') ? 
        		document.documentElement : document.body;
        pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
        pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
        mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
        mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;

        var lixlpixel_tooltip = document.getElementById('tooltip');
        lixlpixel_tooltip.style.left = (mousex+pagex+offsetx) + 'px';
        lixlpixel_tooltip.style.top = (mousey+pagey+offsety) + 'px';
    }
}
function tooltip(tip)
{
    if(!document.getElementById('tooltip')) newelement('tooltip');
    var lixlpixel_tooltip = document.getElementById('tooltip');
    lixlpixel_tooltip.innerHTML = tip;
    lixlpixel_tooltip.style.display = 'block';
    document.onmousemove = getmouseposition;
}
function exit()
{
    document.getElementById('tooltip').style.display = 'none';
}

//
//
//
//
// Fuction used on design gallery page - Jquery Slider 
//
//
//
//

window.onerror=function(desc,page,line,chr){
/* alert('JavaScript error occurred! \n'
  +'\nError description: \t'+desc
  +'\nPage address:      \t'+page
  +'\nLine number:       \t'+line
 );*/
}

$(function(){
 $('a').focus(function(){this.blur();});
 SI.Files.stylizeAll();
 slider.init();

 $('input.text-default').each(function(){
  $(this).attr('default',$(this).val());
 }).focus(function(){
  if($(this).val()==$(this).attr('default'))
   $(this).val('');
 }).blur(function(){
  if($(this).val()=='')
   $(this).val($(this).attr('default'));
 });

 $('input.text,textarea.text').focus(function(){
  $(this).addClass('textfocus');
 }).blur(function(){
  $(this).removeClass('textfocus');
 });

 var popopenobj=0,popopenaobj=null;
 $('a.popup').click(function(){
  var pid=$(this).attr('rel').split('|')[0],_os=parseInt($(this).attr('rel').split('|')[1]);
  var pobj=$('#'+pid);
  if(!pobj.length)
   return false;
  if(typeof popopenobj=='object' && popopenobj.attr('id')!=pid){
   popopenobj.hide(50);
   $(popopenaobj).parent().removeClass(popopenobj.attr('id').split('-')[1]+'-open');
   popopenobj=null;
  }
  return false;
 });
 $('p.images img').click(function(){
  var newbg=$(this).attr('src').split('bg/bg')[1].split('-thumb')[0];
  $(document.body).css('backgroundImage','url('+_siteRoot+'images/bg/bg'+newbg+'.jpg)');
 
  $(this).parent().find('img').removeClass('on');
  $(this).addClass('on');
  return false;
 });
 $(window).load(function(){
  $.each(css_ims,function(){(new Image()).src=_siteRoot+'css/images/'+this;});
  $.each(css_cims,function(){
   var css_im=this;
   $.each(['blue','purple','pink','red','grey','green','yellow','orange'],function(){
    (new Image()).src=_siteRoot+'css/'+this+'/'+css_im;
   });
  });
 }); 
 $('div.sc-large div.img:has(div.tml)').each(function(){
  $('div.tml',this).hide();
  $(this).append('<a href="#" class="tml_open">&nbsp;</a>').find('a').css({
   left:parseInt($(this).offset().left)+864,top:parseInt($(this).offset().top)+1
  }).click(function(){
   $(this).siblings('div.tml').slideToggle();
   return false;
  }).focus(function(){this.blur();}); 
 });
});
var slider={
 num:-1,
 cur:0,
 cr:[],
 al:null,
 at:10*1000,
 ar:true,
 init:function(){
  if(!slider.data || !slider.data.length)
   return false;

  var d=slider.data;
  slider.num=d.length;
  var pos=Math.floor(Math.random()*1);//slider.num);
  for(var i=0;i<slider.num;i++){
   $('#'+d[i].id).css({left:((i-pos)*1000)});
   $('#slide-nav').append('<a id="slide-link-'+i+'" href="#" onclick="slider.slide('+i+');return false;" onfocus="this.blur();">'+(i+1)+'</a>');
  }

  $('img,div#slide-controls',$('div#slide-holder')).fadeIn();
  slider.text(d[pos]);
  slider.on(pos);
  slider.cur=pos;
  window.setTimeout('slider.auto();',slider.at);
 },
 auto:function(){
  if(!slider.ar)
   return false;

  var next=slider.cur+1;
  if(next>=slider.num) next=0;
  slider.slide(next);
 },
 slide:function(pos){
  if(pos<0 || pos>=slider.num || pos==slider.cur)
   return;

  window.clearTimeout(slider.al);
  slider.al=window.setTimeout('slider.auto();',slider.at);

  var d=slider.data;
  for(var i=0;i<slider.num;i++)
   $('#'+d[i].id).stop().animate({left:((i-pos)*1000)},1000,'swing');
  
  slider.on(pos);
  slider.text(d[pos]);
  slider.cur=pos;
 },
 on:function(pos){
  $('#slide-nav a').removeClass('on');
  $('#slide-nav a#slide-link-'+pos).addClass('on');
 },
 text:function(di){
  slider.cr['a']=di.client;
  slider.cr['b']=di.desc;
  slider.ticker('#slide-client span',di.client,0,'a');
  //slider.ticker('#slide-desc',di.desc,0,'b');
  //replaced to sip ticker
   $('#slide-desc').html(di.desc);
 },
 ticker:function(el,text,pos,unique){
  if(slider.cr[unique]!=text)
   return false;

  ctext=text.substring(0,pos)+(pos%2?'-':'_');
  $(el).html(ctext);

  if(pos==text.length)
   $(el).html(text);
  else
   window.setTimeout('slider.ticker("'+el+'","'+text+'",'+(pos+1)+',"'+unique+'");',30);
 }
};
// STYLING FILE INPUTS 1.0 | Shaun Inman <http://www.shauninman.com/> | 2007-09-07
if(!window.SI){var SI={};};
SI.Files={
 htmlClass:'SI-FILES-STYLIZED',
 fileClass:'file',
 wrapClass:'cabinet',
 
 fini:false,
 able:false,
 init:function(){
  this.fini=true;
 },
 stylize:function(elem){
  if(!this.fini){this.init();};
  if(!this.able){return;};
  
  elem.parentNode.file=elem;
  elem.parentNode.onmousemove=function(e){
   if(typeof e=='undefined') e=window.event;
   if(typeof e.pageY=='undefined' &&  typeof e.clientX=='number' && document.documentElement){
    e.pageX=e.clientX+document.documentElement.scrollLeft;
    e.pageY=e.clientY+document.documentElement.scrollTop;
   };
   var ox=oy=0;
   var elem=this;
   if(elem.offsetParent){
    ox=elem.offsetLeft;
    oy=elem.offsetTop;
    while(elem=elem.offsetParent){
     ox+=elem.offsetLeft;
     oy+=elem.offsetTop;
    };
   };
  };
 },
 stylizeAll:function(){
  if(!this.fini){this.init();};
  if(!this.able){return;};
 }
};
