// JavaScript Document
var planname = "";
var url = '';

function showOrderBlock(plan) {
	document.getElementById('orderblock').style.display = 'block';
	//alert(document.getElementById('optone').options.selectedIndex);
	//alert (document.getElementById('optone').options[2].selected);

	document.getElementById('optone').selectedIndex = 0;	
//	document.getElementById('optone').options[2].selected = true;
//Windows OS Selection
	var selbox =  document.getElementById('optone');
	var temp   =  selbox.options[selbox.options.selectedIndex].value;
	
	//setSelectedIndex(document.getElementById('optone'), 'OS Selection');
	if(temp != 'Windows OS Selection') {
	   document.getElementById('controlblock').style.display = 'none';
	}
	document.getElementById('orderbutton').style.display = 'none';
	planname = plan;
}

function showSecondDropdown(chosen) {
	var selbox = document.myform.opttwo;
	selbox.options.length = 0;
	if (chosen == "OS Selection") {
	  document.getElementById('controlblock').style.display = 'none';
	  document.getElementById('orderbutton').style.display = 'none';
	}
	else {
		document.getElementById('controlblock').style.display = 'block';
		if (chosen == "CentOS 5") {
		  selbox.options[selbox.options.length] = new Option('Select Control Panel','x');	
		  selbox.options[selbox.options.length] = new Option('Plesk 30 Domains FREE','Plesk 30 Domains FREE');
		  selbox.options[selbox.options.length] = new Option('No Control Panel','No Control Panel');
		}
		if (chosen == "Fedora 8") {
		  selbox.options[selbox.options.length] = new Option('Select Control Panel','x');
		  selbox.options[selbox.options.length] = new Option('Plesk 30 Domains FREE','Plesk 30 Domains FREE');
		  selbox.options[selbox.options.length] = new Option('No Control Panel','No Control Panel');
		}
		if (chosen == "Ubuntu 8.04") {
		  selbox.options[selbox.options.length] = new Option('Select Control Panel','x');
		  selbox.options[selbox.options.length] = new Option('Plesk 30 Domains FREE','Plesk 30 Domains FREE');
		  selbox.options[selbox.options.length] = new Option('No Control Panel','No Control Panel');
		}
		if (chosen == "Ubuntu 10.04") {
		  selbox.options[selbox.options.length] = new Option('Select Control Panel','x');
		  selbox.options[selbox.options.length] = new Option('No Control Panel - Plesk not supported on Ubuntu 10.04','No Control Panel - Plesk not supported on Ubuntu 10.04');
		}
		if (chosen == "Debian 5") {
		  selbox.options[selbox.options.length] = new Option('Select Control Panel','x');	
		  selbox.options[selbox.options.length] = new Option('Plesk 30 Domains FREE','Plesk 30 Domains FREE');
		  selbox.options[selbox.options.length] = new Option('No Control Panel','No Control Panel');
		}
		
		document.getElementById('controlblock').style.display = 'block';
		document.getElementById('orderbutton').style.display = 'none';
	}
	
}

function showOrderButton(chosen) {  
	selbox = document.getElementById('optone');
	getURL(planname, selbox.options[selbox.options.selectedIndex].innerHTML, chosen);
	if(chosen == 'x') {
		alert("In");
		document.getElementById('orderbutton').style.display = 'none';
	}	
	else {
		document.getElementById('orderbutton').style.display = 'block';				
	}
}

function showWindowsOrderButton(chosen) { 
	selbox = document.getElementById('optone');
	getURL(planname, chosen, '');
	if(chosen == 'x') {
		document.getElementById('orderbutton').style.display = 'none';
	}
	else {
		document.getElementById('orderbutton').style.display = 'block';				
	}
}
function getElementsByClassName(className, tag, elm){
	var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}

function addClassName(elm, className){
    var currentClass = elm.className;
    if(!new RegExp(("(^|\\s)" + className + "(\\s|$)"), "i").test(currentClass)){
        elm.className = currentClass + ((currentClass.length > 0)? " " : "") + className;
    }
    return elm.className;
}

function removeClassName(elm, className){
    var classToRemove = new RegExp(("(^|\\s)" + className + "(\\s|$)"), "i");
    elm.className = elm.className.replace(classToRemove, "").replace(/^\s+|\s+$/g, "");
    return elm.className;
}

function activateThisColumn(column) {
	var div = document.getElementById(column);
	var divbtn = document.getElementById(column+"btn");
	if(column != 'choiceA') {
		var div1 = document.getElementById('choiceA');
		var divbtn1 = document.getElementById('choiceAbtn');
		removeClassName(divbtn1, 'vps-linux_select_active');
		removeClassName(div1, 'vps-linux_vpsplans_col_active');
		addClassName(div1, 'vps-linux_vpsplans_col');
	}
	if(column != 'choiceB') {
		var div2 = document.getElementById('choiceB');
		var divbtn1 = document.getElementById('choiceBbtn');
		removeClassName(divbtn1, 'vps-linux_select_active');
		removeClassName(div2, 'vps-linux_vpsplans_col_active');
		addClassName(div2, 'vps-linux_vpsplans_col');
	}
	if(column != 'choiceC') {
		var div3 = document.getElementById('choiceC');
		var divbtn1 = document.getElementById('choiceCbtn');
		removeClassName(divbtn1, 'vps-linux_select_active');
		removeClassName(div3, 'vps-linux_vpsplans_col_active');
		addClassName(div3, 'vps-linux_vpsplans_col');
	}
	if(column != 'choiceD') {
		var div4 = document.getElementById('choiceD');	
		var divbtn1 = document.getElementById('choiceDbtn');
		removeClassName(divbtn1, 'vps-linux_select_active2');
		removeClassName(div4, 'vps-linux_vpsplans_col_active');
		addClassName(div4, 'vps-linux_vpsplans_col');
	}
	removeClassName(div, 'vps-linux_vpsplans_col');
	addClassName(div, 'vps-linux_vpsplans_col_active');
	if(column=='choiceD') addClassName(divbtn, 'vps-linux_select_active2');
	else addClassName(divbtn, 'vps-linux_select_active');
}

function activateThisColumnOld(column) {
	var table = document.getElementById('pricetable');
	
	// first, remove the 'on' class from all other th's
	var ths = table.getElementsByTagName('th');
	for (var g=0; g<ths.length; g++) {
		removeClassName(ths[g], 'on');
	}
	// then, remove the 'on' class from all other td's
	var tds = table.getElementsByTagName('td');
	for (var m=0; m<tds.length; m++) {
		removeClassName(tds[m], 'on');
	}
	
	// now, add the class 'on' to the selected th
	var newths = getElementsByClassName(column, 'th', table);
	for (var h=0; h<newths.length; h++) {
		addClassName(newths[h], 'on');
	}
	// and finally, add the class 'on' to the selected td
	var newtds = getElementsByClassName(column, 'td', table);
	for (var i=0; i<newtds.length; i++) {
		addClassName(newtds[i], 'on');
	}
}