// general functions
function addLoadEvent(func) {	
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function switchStyleSheet() {
//	var objHiRes = document.getElementById('ctl00_cssHiRes');
//	var objMac = document.getElementById('ctl00_cssMac');
//  var isMac = navigator.userAgent.indexOf("Mac") != -1
    
//    if (isMac){
//        objMac.disabled = false;}
//    else{
//        objMac.disabled = true;}	
//    		
//	if(getWindowWidth() <= 1024){
//		objHiRes.disabled = true;}
//	else{
//		objHiRes.disabled = false;}
}

function getWindowWidth() {
	var winW = window.screen.width;
	
	if (window.innerWidth)
		winW = window.innerWidth;
	else {
		if(document.documentElement.offsetWidth)
			winW = document.documentElement.offsetWidth;
		else if (document.body.offsetWidth)
			winW = document.body.offsetWidth;
		}
		return winW;
}

function getElementByClass(classname){ 
     var messages=new Array();
     var inc=0; 
     var alltags=document.all? document.all : document.getElementsByTagName("*"); 

     for (i=0; i<alltags.length; i++){
        if (alltags[i].className.match(classname)){ 
         messages[inc++]=alltags[i]; 
         }
     }
     if(messages != null){return messages;}
     else {return null;}
} 

function openPopup(url)
{
    var	newwindow=window.open(url,'product','height=350,width=400,status=no,toolbar=no');
	if (window.focus) {newwindow.focus()}
	return false;
}

// cookie functions
function setCookie(name,value,days,path,domain,secure) {
  var expires, date;
  if (typeof days == "number") {
    date = new Date();
    date.setTime( date.getTime() + (days*24*60*60*1000) );
		expires = date.toGMTString();
  }
  document.cookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function getCookie(name) {
  var nameq = name + "=";
  var c_ar = document.cookie.split(';');
  for (var i=0; i<c_ar.length; i++) {
    var c = c_ar[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameq) == 0) return unescape( c.substring(nameq.length, c.length) );
  }
  return null;
}

function deleteCookie(name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


function doSelectPostCode() {
    var elementRadio = document.getElementById('ctl00_cphContent_rbNearestPostCode');

    if (elementRadio!=null){
        elementRadio.checked = true;
    }
}

function doSelectArea() {
    var elementRadio = document.getElementById('ctl00_cphContent_rbArea');

    if (elementRadio!=null){
        elementRadio.checked = true;
    }
}

//error handling
function ValidateTandCs(source, args){
    if (document.getElementById("ctl00_cphContent_chkTerms").checked)
        args.IsValid = true;
    else
        args.IsValid = false; 
} 

function applyShowHide(id){
    var elementsLongdesc = document.getElementById(id);
    if (elementsLongdesc!=null){
        if (elementsLongdesc.className == 'display-hide'){
            elementsLongdesc.className = 'display-show'; }
        else {elementsLongdesc.className = 'display-hide'; }
    }
    return false;
}

// load and attach events
switchStyleSheet();
window.onresize = switchStyleSheet;


