//---------------------------
// SomethingDark.eu
//---------------------------

//---------------------------
// Popups
function popup (obj, iW, iH) {
	var winW = iW;
	var winH = iH;
	var winName = '_blank';
	var winL = (screen.width - winW) / 2;
	var winT = ((screen.height - winH) / 2) - 50;
	window.open(obj.href, winName, 'location=no, toolbar=no, status=no, directories=no, scrollbars=yes, menubar=no, resizable=no, left=' + winL + ', top=' + winT +', width=' + winW + ', height=' + winH);
}

//---------------------------
// Menu Off
function offMenu (obj) {
	document.getElementById(obj).style.display = 'none';
}

//---------------------------
// Menu Swap
function swapMenu (obj) {
	//check if hidden and show or opposite
	if (document.getElementById(obj).style.display == 'block') {
		document.getElementById(obj).style.display = 'none';
	} else {
		document.getElementById(obj).style.display = 'block';
	}
}

//---------------------------
// Mailing list validation
function validateSignup(oForm) {
	var bValid = true;

	if (oForm.signupName.value == '') {
		alert('Please enter your name.');
		return false;
	}
	if (oForm.signupEmail.value == '' || validateEmail(oForm.signupEmail) == false) {
		alert('Please enter a valid email address to join our mailing list.');
		return false;
	}

	return true;
}

//---------------------------
// Checkout list validation
function validateCheckoutDownloads(oForm) {
	var bValid = true;

	if (oForm.fullName.value == '') {
		alert('Please enter your name.');
		return false;
	}
	if (oForm.email.value == '' || validateEmail(oForm.email) == false) {
		alert('Please enter your email address, we need this to send you your articles.');
		return false;
	}
	if (oForm.email.value != oForm.confirm.value) {
		alert('Your email address and confirmation do not match, please make sure we\'ve got the correct address.');
		return false;
	}
	if (oForm.country.options[oForm.country.selectedIndex].text == 'Please Select') {
		alert('Please select your country.');
		return false;
	}
	return true;
}

//---------------------------
// Email validation
function validateEmail(field) {
	with (field) {
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2) { return false; }
		else { return true; }
	}
}

//---------------------------
// image refresh
function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

// Mouse rollover control
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_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//---------------------------
// GreyOut page
function grayOut(vis, options) {
// grayOut(true,{'opacity':'25'});

var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';

    // Calculate the centre minus the dimnentions
	var popupWidth = 350;
	var popupHeight = 200;
	if (window.innerWidth) {
		screenWidth=window.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		screenWidth=document.documentElement.clientWidth;
	} else if (document.body) {
		screenWidth=document.body.clientWidth;
	}
	if (window.innerHeight) {
		screenHeight=window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		screenHeight=document.documentElement.clientHeight;
	} else if (document.body) {
		screenHeight=document.body.clientHeight;
	}
	var x = (screenWidth / 2) - (popupWidth / 2);
	var y = (screenHeight / 2) - (popupHeight / 2);   

	// display the disclaimer
  var disc=document.getElementById('disclaimerScreenObject');
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top=y+'px';                           // In the top
        tnode.style.left=x+'px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='disclaimerScreenObject';                   // Name it so we can find it later
        tnode.setAttribute('class', 'disclaimer'); 
		tnode.innerHTML = '<form action="" method=""post"">';
		tnode.innerHTML += '<h3>WARNING</h3>';
		tnode.innerHTML += '<p>By accessing this website you confirm that you are of legal age in the jurisdiction in which you reside and are not offended by any adult material that it may contain.</p>';
		tnode.innerHTML += '<p>Continuing further means you accept this disclaimer and the SomethingDark terms & conditions.</p>';
//		tnode.innerHTML += '<input type="button" name="choice" value="I AGREE" onclick="location.replace(\'?disclaimer=agreed\');"/>';
		tnode.innerHTML += '<input type="button" name="choice" value="I AGREE" onclick="document.getElementById(\'disclaimerScreenObject\').style.display=\'none\'; document.getElementById(\'darkenScreenObject\').style.display=\'none\'; clearDisclaimer();"/>';
		tnode.innerHTML += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		tnode.innerHTML += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		tnode.innerHTML += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		tnode.innerHTML += '<input type="button" name="choice" value="NO THANKS" onclick="location.replace(\'http://www.google.co.uk\');"/>';
		tnode.innerHTML += '</form>';
    tbody.appendChild(tnode);                            // Add it to the web page
    disc=document.getElementById('disclaimerScreenObject');  // Get the object.
	disc.style.zIndex=zindex;        
//    disc.style.backgroundColor='red';  
    disc.style.width=popupWidth+'px';
    disc.style.height=popupHeight+'px';
    disc.style.display='block';	

  } else {
     dark.style.display='none';
  }
}

//---------------------------
// Slider
var timerUp, timerDown, step=5;
function scrollDivRightS(iStep) {
	document.getElementById("slider").scrollLeft += step;
	timerDown=setTimeout(scrollDivRightS,20);
}
function scrollDivRightF(iStep) {
	document.getElementById("slider").scrollLeft += step*4;
	timerDown=setTimeout(scrollDivRightF,20);
}
function scrollDivLeftS(iStep) {
	document.getElementById("slider").scrollLeft -= step;
	timerUp=setTimeout(scrollDivLeftS,20);
}
function scrollDivLeftF(iStep) {
	document.getElementById("slider").scrollLeft -= step*4;
	timerUp=setTimeout(scrollDivLeftF,20);
}
function scrollDivStart() {
	document.getElementById("slider").scrollLeft = 1;
}
function scrollDivEnd(iEnd) {
	document.getElementById("slider").scrollLeft = iEnd;
}

//---------------------------
// Remove Disclaimer
function clearDisclaimer() {
	var xmlhttp;    

	if (window.XMLHttpRequest) {
		// Normal
		xmlhttp = new XMLHttpRequest();
	} else {
		// IE6
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","_disclaimer.asp",true);
	xmlhttp.send();
}
