var skipVal_AddToCart = "";
var diaH = 0;
var diaW = 0;
var optList = "";
var listintVal = 0;
/* --------------------------------------------------------------------------------------- */
/*  Set Cookie Expiry and Name   */
var expDays = 30;
var exp = new Date(); 
/*
Expiry Format -
60 * 1000 = 60 second
60* (60 * 1000) = 60 mins which is 1 hour
24* (60* (60 * 1000)) = 1 day which is 24 hours
31* 24* (60* (60 * 1000)) = 31 days 
*/
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
var cookieName          = "csCart";
/* --------------------------------------------------------------------------------------- */


var MousePosX = 0;
var MousePosY = 0;

function checkS(e){
    MousePosX = mouseX(e);
    MousePosY = mouseY(e);
}
function mouseX(evt) {
if (evt.pageX) return evt.pageX;
else if (evt.clientX)
   return evt.clientX + (document.documentElement.scrollLeft ?
   document.documentElement.scrollLeft :
   document.body.scrollLeft);
else return null;
}
function mouseY(evt) {
if (evt.pageY) return evt.pageY;
else if (evt.clientY)
   return evt.clientY + (document.documentElement.scrollTop ?
   document.documentElement.scrollTop :
   document.body.scrollTop);
else return null;
}

try {
var urlPath = document.location.href;
var sslURL = urlPath.substring(0,5).toLowerCase();
var urlPath2 = urlPath.substring(4);
$(document).ready(function() {
  if(sslURL=="https") {
  } else {
  window.location = "https"+ urlPath2;
  }
});
} catch(err) {}
function searchFld_handler(OPT) {
  var element = document.getElementById("fldSearch");
  var getText = element.value;
  switch(OPT) {
    case 1:  // On Focus
      if(getText == "Enter keyword") {element.value = "";} else {element.select();}
      element.style.color = "#FFF";
      break;
    case 2: // lost Focus
      if(getText == "") {element.style.color = "#AAA"; element.value = "Enter keyword";}
      break;
  }
}
function addItemToCart(prodCode, itemDescription, itemWeight, itemQTY, itemPrice) {
  if(skipVal_AddToCart == false) {
    skipVal_AddToCart = true;
    showDiv('addToCart');
    var element = document.getElementById("addToCart");
    if (navigator.appName == 'Microsoft Internet Explorer') {
      element.style.posTop = MousePosY - 120;
      element.style.posLeft = MousePosX - 104;
    } else {
      element.style.top = MousePosY - 120 + "px";
      element.style.left = MousePosX - 104 + "px";
    }
    setTimeout("hideDiv('addToCart');skipVal_AddToCart = false",2000);
    var orgVal   = GetCookie(cookieName);
    var orgPrice = parseFloat(GetCookie("cartTotal"));
    var orgItemPrice = parseFloat(itemPrice);
    var totalPrice = 0.00;
    if(orgPrice) {
      totalPrice = orgPrice+orgItemPrice;
    } else {
      totalPrice =  orgItemPrice;
    } 
    totalPrice = CurrencyFormatted(totalPrice);
    SetCookie ("cartTotal", totalPrice,exp);
    setLabelText("priceTotal", totalPrice); 
    if(orgVal) {
      s = orgVal;
    } else {
	  s = "~"; 
    }
    t = ":";
    sLen = s.length;
    b = "";
    for(c=0;c<sLen;c++) {
	  if(s.substring(c,c+1) == t) {b++;}
    }
    var itemNumVal = b / 3;
    itemNumVal = Math.round(itemNumVal) + 1;
    var dataFail            = 0;
    if(cookieName=="")      {alert("ERROR 124: Please contact site administrator"); dataFail=1;}
    if(itemDescription=="") {alert("ERROR 125: Please contact site administrator"); dataFail=1;}
    if(itemQTY=="")         {alert("ERROR 126: Please contact site administrator"); dataFail=1;}
    if(itemPrice=="")       {alert("ERROR 127: Please contact site administrator"); dataFail=1;}
    if(dataFail==0) {
	  var cartItemsVal = "";
	  if (orgVal) {
	    cartItemsVal = orgVal+":"+prodCode+" ~ "+itemDescription+" ~ "+itemWeight+" ~ :"+itemPrice+":"+itemQTY;
      } else {
	    cartItemsVal = prodCode+" ~ "+itemDescription+" ~ "+itemWeight+" ~ :"+itemPrice+":"+itemQTY;
	  }
	  SetCookie (cookieName, cartItemsVal,exp);
	  setLabelText("cartTotal", itemNumVal + " Items");
    }
  } 
}
function emptyCart() {
  if (confirm("Are you sure you want to empty you cart!")) {
     DeleteCookie(cookieName);
     DeleteCookie("cartTotal");
     setLabelText("cartTotal", "0 Items");
     setLabelText("priceTotal", "0.00");
  }
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}
function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}
function setNumOnly(e) {
  if (navigator.appName == 'Microsoft Internet Explorer') {
    if(event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;
  } else {
    var key = e.which; 
    if(key == 8) {} else {
      if(key < 45 || key > 57) {return false;} else {return true;}
    }
  }
}
function roundTo(numVal,rndVal) {
  if(numVal) {} else {numVal = 0}
  if(rndVal) {} else {rndVal = 2}
  var result = numVal.toFixed(rndVal);
  return result;
}
function showDiv(ID) {
	document.getElementById(ID).style.visibility = "visible";
}
function hideDiv(ID) {
	document.getElementById(ID).style.visibility = "hidden";
}
function GetCookie (name) {  
  var arg = name + "=";  
  var alen = arg.length;  
  var clen = document.cookie.length;  
  var i = 0;  
  while (i < clen) {
  var j = i + alen;    
  if (document.cookie.substring(i, j) == arg)      
    return getCookieVal (j);    
  i = document.cookie.indexOf(" ", i) + 1;    
  if (i == 0) break;   
 }  
 return null;
}
function SetCookie (name, value) {  
  var argv = SetCookie.arguments;  
  var argc = SetCookie.arguments.length;  
  var expires = (argc > 2) ? argv[2] : null;  
  var path = (argc > 3) ? argv[3] : null;  
  var domain = (argc > 4) ? argv[4] : null;  
  var secure = (argc > 5) ? argv[5] : false;  
  document.cookie = name + "=" + escape (value) + 
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
    ((path == null) ? "" : ("; path=" + path)) +  
    ((domain == null) ? "" : ("; domain=" + domain)) +    
    ((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {  
  var exp = new Date();  
  exp.setTime (exp.getTime() - 1);   
  var cval = GetCookie (name);  
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
function getCookieVal(offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
function setLabelText(ID, Text)
{
  document.getElementById(ID).innerHTML = Text;
}
function clearLabelText(ID) {
  setLabelText(ID, "");
}
function setFocus(ID) {
  document.getElementById(ID).focus(); 
}
function submitPage(frmID) {
  document.getElementById(frmID).submit();
}
function loadURL(newURL) { 
  window.location = newURL;
}
function showDiv(ID) {
	document.getElementById(ID).style.visibility = "visible";
}
function hideDiv(ID) {
	document.getElementById(ID).style.visibility = "hidden";
}
function show_DiaWin1(PosX,PosY,Dia) {
  var element = document.getElementById("diaWin1");
  if (navigator.appName == 'Microsoft Internet Explorer') {
    element.style.posTop = MousePosY - PosY;
    element.style.posLeft = MousePosX - PosX;
  } else {
    element.style.top = MousePosY - PosY + "px";
    element.style.left = MousePosX - PosX + "px";
  }
  setLabelText("diaWin1HTML", Dia);
  element.style.visibility = "visible";
}
function hide_DiaWin1(URL) {
  if(URL) {
    window.location = URL;
  } else {
    setLabelText("diaWin1HTML", "");
    hideDiv("diaWin1"); 
    hideDiv("winLock"); 
  }
}

$(document).ready(function() {
    var cssObjGray = {
      'background-color' : '#333333'
    };
    var cssObjNone = {
      'background-color' : ''
    };
	$('.MenuItemHome').hover(function() {$("#ServMenu").stop(false, true).slideUp('fast');$("#servMenuItem").css(cssObjNone);});
    $('.MenuItemAcc').hover(function() {$("#ProdMenu").stop(false, true).slideUp('fast');$("#prodMenuItem").css(cssObjNone);});
	
	$('.dropDownMenuSer').hover(
        function() {
           $("#ServMenu").stop(false, true).slideDown();
           $("#ProdMenu").stop(false, true).slideUp('fast');       
		   $("#servMenuItem").css(cssObjGray);       
		   $("#prodMenuItem").css(cssObjNone);       
        }
    );
    $('#ServMenu').mouseleave(
        function() {
           $("#ServMenu").stop(false, true).slideUp('fast');       
		   $("#servMenuItem").css(cssObjNone);       
		}  
    );
    $('.dropDownMenuProd').hover(
        function() {
           $("#ProdMenu").stop(false, true).slideDown();
           $("#ServMenu").stop(false, true).slideUp('fast');       
		   $("#prodMenuItem").css(cssObjGray);
		   $("#servMenuItem").css(cssObjNone);       
        }
    );
    $('#ProdMenu').mouseleave(
        function() {
           $("#ProdMenu").stop(false, true).slideUp('fast');       
		   $("#prodMenuItem").css(cssObjNone);       
		}  
    );
    $("#mainMenuBar").mouseleave(
        function() {
           $("#ServMenu").stop(false, true).slideUp('fast');       
           $("#ProdMenu").stop(false, true).slideUp('fast');
		   $("#servMenuItem").css(cssObjNone);       
		   $("#prodMenuItem").css(cssObjNone);       
		}  
    );
});

function menuBar(ID,state) {
 // $("#"+ID).slideToggle("slow");
  if(state == "1") {
    $("#"+ID).show(0);
	
  } else {
    $("#"+ID).hide(0);
  }
}
function showMenuList(ID, Hi) {
  $("#"+ID).stop(false, true).slideDown();
  listintVal=0;
}
function showLargeImg(Img) {
  var el = document.getElementById("dispImageDiv");
  el.style.visibility = "visible";
  document.getElementById("ProdImg").src = "/prodImages/" + Img;
  el.style.left = MousePosX + "px"; 
  el.style.top = MousePosY - 150 + "px"; 
}

function hideLargeImg() {
  var el = document.getElementById("dispImageDiv");
  el.style.visibility = "hidden";
}
function sleep(naptime){
  naptime = naptime * 1000;
  var sleeping = true;
  var now = new Date();
  var alarm;
  var startingMSeconds = now.getTime();
  alert("starting nap at timestamp: " + startingMSeconds + "\nWill sleep for: " + naptime + " ms");
  while(sleeping){
    alarm = new Date();
    alarmMSeconds = alarm.getTime();
    if(alarmMSeconds - startingMSeconds > naptime){ sleeping = false; }
  }        
  alert("Wakeup!");
}

/*function showMenuList(ID, Hi) {
  if(listintVal == 0) { document.getElementById(ID).style.visibility = "visible";}
  document.getElementById(ID).style.height = listintVal + "px";
  if(listintVal >= Hi) {
    listintVal=0; 
  } else {
    setTimeout("showMenuList('" + ID + "', '" + Hi + "')" ,1);   
    listintVal = listintVal + 20;
  }
}
*/

function centerWin(WinID) {
  if (navigator.appName == 'Microsoft Internet Explorer') {
    var pageW = document.body.clientWidth / 2; 
    var pageH = document.body.clientHeight / 2; 
	document.getElementById(WinID).style.posTop = 400 - diaH / 2;
    document.getElementById(WinID).style.posLeft = pageW - diaW / 2;
  } else {
    var pageW = window.innerWidth  / 2; 
    var pageH = window.innerHeight / 2; 
    document.getElementById(WinID).style.top = pageH - diaH / 2 + "px"; 
	document.getElementById(WinID).style.left = pageW - diaW / 2 + "px";
  }
}
function centerWinScreen(WinID) {
  if (navigator.appName == 'Microsoft Internet Explorer') {
    var pageW = screen.width / 2; 
    var pageH = screen.height / 2; 
    var diaH = document.getElementById(WinID).style.pixelHeight / 2;
    var diaW = document.getElementById(WinID).style.pixelWidth / 2;
	document.getElementById(WinID).style.posTop = pageH - diaH;
    document.getElementById(WinID).style.posLeft = pageW - diaW;
  } else {
    var pageW = screen.width  / 2; 
    var pageH = tempY; 
    var diaHeight = document.getElementById(WinID).style.height;
	var diaWidth = document.getElementById(WinID).style.width;
	diaHeight = remove(diaHeight, "px");
	diaWidth = remove(diaWidth, "px");
	document.getElementById(WinID).style.top = pageH - diaHeight / 2;  
	document.getElementById(WinID).style.left = pageW - diaWidth / 2;
  }
}

function sysMsg(HTML) {
  lockWin();
  showDiv("diaWin1");
  setLabelText("diaWin1HTML", HTML);
  centerWin("diaWin1");
}

function remove(s, t) {
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + remove(s.substring(i + t.length), t);
  return r;
}
function lockWin() {
  var docDims = getPageSizeWithScroll();
  var docVals =docDims.split(":"); 
  var _docWidth  = docVals[0];
  var _docHeight = docVals[1];
  if (navigator.appName == 'Microsoft Internet Explorer') {
    document.getElementById("winLock").style.pixelHeight = _docHeight;
    document.getElementById("winLock").style.pixelWidth = _docWidth;
  } else {
    document.getElementById("winLock").style.height = _docHeight + "px";
    document.getElementById("winLock").style.width = _docWidth + "px";
  }
  document.getElementById('winLock').style.visibility="visible";
}

function getPageSizeWithScroll(){
  if (window.innerHeight && window.scrollMaxY) { // Firefox
    yWithScroll = window.innerHeight + window.scrollMaxY;
    xWithScroll = window.innerWidth + window.scrollMaxX;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
    yWithScroll = document.body.scrollHeight;
    xWithScroll = document.body.scrollWidth;
  } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    yWithScroll = document.body.offsetHeight;
    xWithScroll = document.body.offsetWidth;
  }
  arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
  //alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll ); 
  return PageSizeWithScroll = xWithScroll+":"+ yWithScroll;  //arrayPageSizeWithScroll; 
} 

function specBlock(Arg1, Arg2, colour, f) {
if(colour == 1) {
 var c="#EEEEEE";
} else {
 var c="#FFFFFF";
}
if(f == 1) {
  var l = "ltG";
} else {
  var l = "";
}
var docHtml =       "<table width='100%' cellpadding='3' cellspacing='0' border='0'>";
docHtml = docHtml + "<tr bgcolor='" + c + "'>";
docHtml = docHtml + "  <td width='25%' valign='top' align='right' class='llG lbG " + l + "'><b>" + Arg1 + ":</b></td>";
docHtml = docHtml + "  <td align='left' valign='top' class='llG lbG lrG " + l + "'>" + Arg2 + "</td>";
docHtml = docHtml + "</tr>";
docHtml = docHtml + "</table>";
document.write(docHtml);
}
function formatText(el,tagstart,tagend) {
  if (el.setSelectionRange) {
    el.value = el.value.substring(0,el.selectionStart) + tagstart + el.value.substring(el.selectionStart,el.selectionEnd) + tagend + el.value.substring(el.selectionEnd,el.value.length)
  } else {
    // IE code here...
  }
}
function pick_adSM() {
 var randomnumber=Math.floor(Math.random()*3)
 switch (randomnumber) {
  case 0:
   img = 'images/adSm_hosting.png';
   url = 'services.php?viewID=12'; 
   break;
  case 1:
   img = 'images/adSm_CompRep.png';
   url = 'services.php?viewID=1'; 
   break;
  case 2:
   img = 'images/adSm_WebDev.png';
   url = 'services.php?viewID=11'; 
   break;
  default: 
   img = 'images/adSm_WebDev.png';
   url = 'services.php?viewID=11'; 
}
 document.getElementById("adSmDisp").src = img;
 document.getElementById("adSMDiv2").href = url;
 setTimeout("pick_adSM()",5000);
}
