// Pops open a new window with no toolbars or menus.
function pop(file,wide,high) {
	window.open(file,'popup','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=yes,copyhistory=no,width='+wide+',height='+high);
}

// Activates the contact form - helps fight form spammers
function activate(brillig) {
	document.getElementById('config').name = "config";
	document.getElementById('config').value = brillig;
}

// Activates Flash components, sets up dropdown menus and established external links.
function setup() {

	var URLs = window.location + '';
	var paramHeight;
	var paramPath;
	
	if (URLs.search(/about/)!==-1) { paramHeight = '170'; paramPath = 'aboutConfig'; }
	else if (URLs.search(/who-why/)!==-1) { paramHeight = '170'; paramPath = 'whowhyConfig'; }
	else if (URLs.search(/affiliate/)!==-1) { paramHeight = '170'; paramPath = 'partnersConfig'; }
	else if (URLs.search(/testimonials/)!==-1) { paramHeight = '170'; paramPath = 'testimonialConfig'; }
	else if (URLs.search(/web-hosting/)!==-1) { paramHeight = '170'; paramPath = 'webhostingConfig'; }
	else if (URLs.search(/shared-hosting/)!==-1) { paramHeight = '170'; paramPath = 'sharedConfig'; }
	else if (URLs.search(/reseller-hosting/)!==-1) { paramHeight = '170'; paramPath = 'resellerConfig'; }
	else if (URLs.search(/vps-hosting/)!==-1) { paramHeight = '170'; paramPath = 'vpsConfig'; }
	else if (URLs.search(/dedicated-servers/)!==-1) { paramHeight = '170'; paramPath = 'choosedcConfig'; }
	else if (URLs.search(/atlanta1/)!==-1) { paramHeight = '170'; paramPath = 'atlantaConfig'; }
	else if (URLs.search(/chicago1/)!==-1) { paramHeight = '170'; paramPath = 'chicagoConfig'; }
	else if (URLs.search(/florida/)!==-1) { paramHeight = '170'; paramPath = 'jaxConfig'; }
	else if (URLs.search(/softlayer/)!==-1) { paramHeight = '170'; paramPath = 'softlayerConfig'; }
	else if (URLs.search(/peer1/)!==-1) { paramHeight = '170'; paramPath = 'peer1Config'; }
	else if (URLs.search(/full-management/)!==-1) { paramHeight = '170'; paramPath = 'fullmanagementConfig'; }
	else if (URLs.search(/vault/)!==-1) { paramHeight = '170'; paramPath = 'vaultConfig'; }
	else if (URLs.search(/network/)!==-1) { paramHeight = '170'; paramPath = 'networkConfig'; }
	else if (URLs.search(/netmap/)!==-1) { paramHeight = '170'; paramPath = 'netmapConfig'; }
	else if (URLs.search(/support/)!==-1) { paramHeight = '170'; paramPath = 'supportConfig'; }
	else if (URLs.search(/contact-us/)!==-1) { paramHeight = '170'; paramPath = 'contactusConfig'; }
	else if (URLs.search(/contact-success/)!==-1) { paramHeight = '170'; paramPath = 'contactusConfig'; }
	else if (URLs.search(/sitemap/)!==-1) { paramHeight = '170'; paramPath = 'sitemapConfig'; }
	else { paramHeight = '200'; paramPath = 'mainheaderConfig'; }

	if (document.getElementById('special')) document.getElementById('special').innerHTML =  '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="336" height="220"><param name="movie" value="special.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="FlashVars" value="XMLfile=xml/specialConfig.xml" /><embed src="special.swf" FlashVars="XMLfile=xml/specialConfig.xml" width="336" height="220" wmode="transparent" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" bgcolor="#000000"></embed></object>';

	if (document.getElementById('main')) document.getElementById('main').innerHTML =  '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" height="' + paramHeight + '" width="775"><param name="movie" value="main-3.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="FlashVars" value="XMLfile=xml/' + paramPath + '.xml" /><embed src="main-3.swf" flashvars="XMLfile=xml/' + paramPath + '.xml" wmode="transparent" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" bgcolor="#000000" height="' + paramHeight + '" width="775"></embed></object>';

	var code;
	code =	'	<div class="hidden" id="submenu1">\n';
	code +=	'		<a href="/who-why.htm">Who and Why</a>\n';
	code +=	'		<a href="http://forums.ayksolutions.com/forumdisplay.php?f=16">News</a>\n';
	code +=	'		<a href="/affiliate.htm">Partners</a>\n';
	code +=	'		<a href="/testimonials.htm">Testimonials</a>\n';
	code +=	'	</div>\n';
	code +=	'	<div class="hidden" id="submenu2">\n';
	code +=	'		<a href="/shared-hosting.htm">Shared Hosting</a>\n';
	code +=	'		<a href="/reseller-hosting.htm">Reseller Hosting</a>\n';
	code +=	'		<a href="/vps-hosting.htm">VPS Hosting</a>\n';
	code +=	'		<a href="/dedicated-servers.htm">Dedicated Servers</a>\n';
	code +=	'		<a href="/cloud.htm">Cloud Hosting</a>\n';
	code +=	'		<a href="/full-management.htm">Full Management</a>\n';
	code +=	'		<a href="/vault.htm">Vault Data Protection</a>\n';
	code +=	'	</div>\n';
	code +=	'	<div class="hidden" id="submenu3">\n';
	code +=	'		<a href="/netmap.htm">Network Map</a>\n';
	code +=	'		<a href="/speed-test.htm?DC=" onclick="pop(\'/speed-test.htm?DC=\',\'600\',\'450\'); return false;">Speed Test</a>\n';
	code +=	'	</div>\n';
	code +=	'	<div class="hidden" id="submenu4">\n';
	code +=	'		<a rel="external" href="https://myayk.ayksolutions.com/">myAYK</a>\n';
	code +=	'		<a href="http://forums.ayksolutions.com/forumdisplay.php?f=18">Knowledge Base</a>\n';
	code +=	'		<a href="http://messenger.providesupport.com/messenger/ayksolutions.html" onclick="pop(\'http://messenger.providesupport.com/messenger/ayksolutions.html\',\'500\',\'460\'); return false;">Live Sales Chat</a>\n';
	code +=	'		<a href="http://forums.ayksolutions.com/forumdisplay.php?f=19">Downloads</a>\n';
	code +=	'		<a href="http://forums.ayksolutions.com/">Forums</a>\n';
	code +=	'	</div>';
	document.getElementById('submenus').innerHTML = code;
	
	// This function hides all dropdown menus by default
	var els = document.getElementsByTagName('*');
	for (var i=0;i<els.length;i++) {
		if (els[i].className == 'hidden') { kill(els[i].id,0); }
		if (els[i].className == 'hidden2') { els[i].style.display = 'none'; }
	}
	
	// This function activates table tabs if they are present within a page
	if (document.getElementById('switcher')) {
		document.getElementById('switcher').style.display = 'block';
		document.getElementById('switched').style.height = document.getElementById('switched').offsetHeight + 'px';
	}
	
	// This function prepared external links to open in a new window
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank";
	}
}
function setup2(foo) {
	var els = document.getElementsByTagName('*');
	for (var i=0;i<els.length;i++) {
		if (els[i].className == 'hidden' && els[i].id !== foo) { kill(els[i].id,300); }
	}
}
function toggle(id,duration,step_duration){
	var el = document.getElementById(id);
	if (!el || !el.style) return;
	if (duration === undefined) duration = 500;
	if (!step_duration) step_duration = 10;
	var steps = Math.max(Math.ceil(duration/step_duration),1);
	if (el.offsetHeight == 0) { //show it
		morph_height(el,0,el.naturalHeight,duration,steps,0);
	} else { //hide it
		// el.naturalHeight = el.naturalHeight || el.offsetHeight;
		// el.style.overflow = 'hidden';
		// morph_height(el,el.offsetHeight,0,duration,steps,0);
	}
}
function kill(id,duration,step_duration){
	var el = document.getElementById(id);
	if (!el || !el.style) return;
	if (duration === undefined) duration = 500;
	if (!step_duration) step_duration = 10;
	var steps = Math.max(Math.ceil(duration/step_duration),1);
	if (el.offsetHeight !== 0) {
		el.naturalHeight = el.naturalHeight || el.offsetHeight;
		el.style.overflow = 'hidden';
		morph_height(el,el.offsetHeight,0,duration,steps,0);
	}
}
function morph_height(el,from,to,duration,steps,step) {
	var x = step/steps;
	var y = Math.sin((x-0.5)*Math.PI);
	var z = (y+1)*0.5;
	var h = from + (to-from)*z;
	if (step == steps) h = to;
	el.style.height = h+'px';
	if (h == to) return;
	var t = duration/steps;
	if (el.style.height === '0px') el.style.marginTop = '0';
	setTimeout(function(){morph_height(el,from,to,duration,steps,step+1)},t);
}

function switcheroo(foo,bar) {
	var divs = new Array();
	divs = document.getElementsByTagName('div');
	var lis = new Array();
	lis = document.getElementsByTagName('li');
	
	if (foo === 'All') { 
		for (i=0 ; i<divs.length ; i++) { 
			if (divs[i].className === 'switch') divs[i].style.display = 'block'; 
		}
	} else {
		for (i=0 ; i<divs.length ; i++) {
			if (divs[i].className === 'switch') divs[i].style.display = 'none'; 
		}
		document.getElementById(foo).style.display = 'block';
	}
	
	for (i=0 ; i<lis.length ; i++) {
		if (lis[i].className === 'sw') {
			lis[i].style.background = '#EEE';
			lis[i].style.color = '#666';
		}
		document.getElementById(bar).style.background = '#666';
		document.getElementById(bar).style.color = '#EEE';
	}
}

// These two function show and hide pricing popup windows
function popOut(foo) {
	document.getElementById(foo).style.display = 'block';
}
function hideIn(foo) {
	document.getElementById(foo).style.display = 'none';
}