var version = "5.0";

function showVersionOption(){
	document.getElementById('usingVersion').style.visibility = 'visible';
	document.infoform.version.style.visibility = 'visible';
	document.close();
}

function hideVersionOption(){
	document.getElementById('usingVersion').style.visibility = 'hidden';
	document.infoform.version.style.visibility = 'hidden';
	document.close();
}

function toggleForm(){
	if (document.getElementById('infoform').style.display == 'none') {
		document.getElementById('infoform').style.display = 'block';
		document.getElementById('outsideformLink').style.display = 'none';
		document.getElementById('formtoggle').style.display = 'none';
	}else{
		document.getElementById('infoform').style.display = 'none';
		document.getElementById('outsideformLink').style.display = 'block';
	}
}

function removeSpaces (string) {
	return string.split(' ').join('%20');
}

function checkLogin() {
	var errors = false;
	var alertdata = "";
	
	var username = document.ftplogin.username.value;
	var password = document.ftplogin.password.value;
	
	if (username == password) {
		alertdata += "Please check your entry, the password should not be the same as the username...\n";
		errors = true;
	}
	if (username.length <= 3) {
		alertdata += "Username is too short.\n";
		errors = true;
	}
	if (password.length <= 3) {
		alertdata += "Password is too short.\n";
		errors = true;
	}
	
	if (errors) {
		alert("Your attention is needed!\n" + alertdata + "Thank you.");
		alertdata = "";
		return false;
	}else{
		return true;
	}
}

function update(){
	var commentLength = document.infoform.comments.value;
	commentLength = commentLength.length;
	if (commentLength > 255){
		document.getElementById("counter").style.color = "red";
		document.getElementById("counter").style.fontSize = "12px";
	}else{
		document.getElementById("counter").style.color = "#999";
		document.getElementById("counter").style.fontSize = "10px";
	}
	document.getElementById("counter").innerHTML = commentLength + "/255 characters";
}

function checkForm(){
	errors = false;
	alertdata = "";
	
	if (document.infoform.uses.checked == false && document.infoform.doesnotuse.checked == false){
		alertdata += "Please mark if you are a current Studio Suite user.\n";
		errors = true;
	}
	
	entered = document.infoform.firstname.value;
	if (entered.length <= 1){
		alertdata += "Please enter a first name.\n";
		errors = true;
	}
	
	entered = document.infoform.lastname.value;
	if (entered.length <= 1){
		alertdata += "Please enter a last name.\n";
		errors = true;
	}
	
	emailcheck = false;
	entered = document.infoform.email.value;
	atoffset = entered.indexOf('@',0);
	if (entered == null || entered == ""){
		alertdata += "Please enter an e-mail address.\n";
		emailcheck = true;
		errors = true;
	}
	if (atoffset == -1 && emailcheck == false){
		alertdata += "Please double-check your e-mail address.\n";
		emailcheck = true;
		errors = true;
	}
	if (atoffset == 0 || atoffset == entered.length-1 && emailcheck == false){
		alertdata += "Please double-check your e-mail address.\n";
		emailcheck = true;
		errors = true;
	}
	if (entered.indexOf('.',atoffset) == -1 && emailcheck == false){
		alertdata += "Please double-check your e-mail address.\n";
		emailcheck = true;
		errors = true;
	}
	if (entered.indexOf('.',atoffset) == (entered.length-1) && emailcheck == false){
		alertdata += "Please double-check your e-mail address.\n";
		emailcheck = true;
		errors = true;
	}
	
	entered = document.infoform.telephone.value;
	if (entered.length < 7) {
		alertdata += "Please enter a valid telephone number.\n";
		errors = true;
	}
	
	entered = document.infoform.country.value;
	if (entered.length < 3) {
		alertdata += "Please enter a valid country.\n";
		errors = true;
	}
	
	entered = document.infoform.howheard.value;
	if (entered == "Please Choose"){
		alertdata += "Please choose how you heard of us.\n";
		errors = true;
	}
	
	entered = document.infoform.comments.value;
	if (entered.length >= 1) {
		if (entered.indexOf("http") >= 0 || entered.indexOf("www") >= 0){
			alertdata += "Please do not include links in your comments, or at least not http/s or www.\n";
			errors = true;
		}
		if (entered.length > 255){
			alertdata += "Please keep your comments to 255 characters or below.\n";
			errors = true;
		}
	}
	
	if (errors){
		alert("Your attention is needed!\n" + alertdata + "Thank you!");
		alertdata = "";
		return false;
	}else{
		return true;
	}
}

function showOptions(chosen) {
	switch (chosen) {
		case 'Blog/Forum':
			document.getElementById('whatsite').style.display = "block";
			document.getElementById('magazinechoices').style.display = "none";
			document.getElementById('whoReferred').style.display = "none";
			document.getElementById('howheardother').style.display = "none";
			document.getElementById('tradeshow').style.display = "none";
			break;
		case "Internet Search":
			document.getElementById('whatsite').style.display = "block";
			document.getElementById('magazinechoices').style.display = "none";
			document.getElementById('whoReferred').style.display = "none";
			document.getElementById('howheardother').style.display = "none";
			document.getElementById('tradeshow').style.display = "none";
			break;
		case 'Magazine':
			document.getElementById('whatsite').style.display = "none";
			document.getElementById('magazinechoices').style.display = "block";
			document.getElementById('whoReferred').style.display = "none";
			document.getElementById('howheardother').style.display = "none";
			document.getElementById('tradeshow').style.display = "none";
			break;
		case 'Referral':
			document.getElementById('whatsite').style.display = "none";
			document.getElementById('magazinechoices').style.display = "none";
			document.getElementById('whoReferred').style.display = "block";
			document.getElementById('howheardother').style.display = "none";
			document.getElementById('tradeshow').style.display = "none";
			break;
		case 'Other':
			document.getElementById('whatsite').style.display = "none";
			document.getElementById('magazinechoices').style.display = "none";
			document.getElementById('whoReferred').style.display = "none";
			document.getElementById('howheardother').style.display = "block";
			document.getElementById('tradeshow').style.display = "none";
			break;
		case 'Tradeshow':
			document.getElementById('whatsite').style.display = "none";
			document.getElementById('magazinechoices').style.display = "none";
			document.getElementById('whoReferred').style.display = "none";
			document.getElementById('howheardother').style.display = "none";
			document.getElementById('tradeshow').style.display = "block";
			break;
		default:
			break;
	}
}

function getVersion(){
	version = prompt("Which version?");
	if (version == null){
		document.infoform.version.value = "None entered or not a current user.";
	}else{
		document.infoform.version.value = version;
	}
	return version;
}

function version(){
	return version;
}
function makeVidLink(area,w,h){
	var extension = area.substring(area.length-3,area.length);
	var data = "<a href=";
	data += "Javascript:newVideo('"+area+"','"+w+"','"+h+"')";
	switch (area){
		case "products":
			data += ">New Product Description/Comparison Chart and Support Program Details</a>";
			break;
		case "supportProg":
			data += ">Support Program Details</a>";
			break;
	}
	switch (extension){
		case "mov":
			data += "><img src='images/mov.jpg' border='0' alt='mov' /></a>";
			break;
		case "mp4":
			data += "><img src='images/flv.jpg' border='0' alt='flv' /></a>";
			break;
	}
	document.write(data);
	document.close();
}
function makeLink(area){
	data = "<a href=";
	if(runningIE() ){
		if (area == "docIMG") {
			data += setIElink('products');
			data += setIEtarget();
		}else{
			data += setIElink(area);
			data += setIEtarget();
		}
	}else{
		if (area == "docIMG") {
			data += "Javascript:popUpChart('products')";
		}else{
			data += "Javascript:popUpChart('"+area+"')";
		}
	}
	switch (area){
		case "products":
			data += "><b>Click here</b> for New Product Description/Comparison Chart and Support Program Details</a>";
			break;
		case "supportProg":
			data += ">Support Program Details</a>";
			break;
		case "docIMG":
			data += "><img src='../images/document.png' alt='Doc icon' width='32px' border='0' /></a>";
			break;
		default:
			data += ">Link syntax error. Area is currently ";
			data += area;
			data += "</a>";
			break;
	}
	document.write(data);
	document.close();
}

function popUpVideo(area,dimensions){
	pagelink = "";
	pgtitle = "";
	switch (area){
		case "products":
			pagelink = "./pages/ss9versioncomp.html";
			pgtitle = "Studio Suite 9 Versions";
			dimensions = "width=750,height=656,resizable=yes,scrollbars=yes";
			break;
		case "supportProg":
			pagelink = "./docs/SS9SupportProgram.pdf";
			pgtitle = "Studio Suite 9 Support Program";
			break;
		default:
			pagelink = area;
			pgtitle = area;
			break;
	}
	newwindow = window.open(pagelink,pgtitle,dimensions);
	if (window.focus) {
		newwindow.focus();
	}
}

function popUpChart(area){
	pagelink = "";
	pgtitle = "";
	dimensions = "";
	switch (area){
		case "products":
			pagelink = "./pages/ss9versioncomp.html";
			pgtitle = "Studio Suite 9 Versions";
			dimensions = "width=750,height=656,resizable=yes,scrollbars=yes";
			break;
		case "supportProg":
			pagelink = "./docs/SS9SupportProgram.pdf";
			pgtitle = "Studio Suite 9 Support Program";
			break;
		default:
			pagelink = area;
			pgtitle = area;
			dimensions = "width=800,height=600";
			break;
	}
	newwindow = window.open(pagelink,pgtitle,dimensions);
	if (window.focus) {
		newwindow.focus();
	}
}


function runningIE(){
	theNav = navigator.userAgent;
	if(theNav.indexOf('MSIE') >= 0){
		return true;
	}else{
		return false;
	}
}

function setIElink(area){
	newlink = "";
	switch (area){
		case "products":
			newlink = "./pages/ss9versioncomp.html";
			break;
		case "supportProg":
			newlink = "./docs/SS9SupportProgram.pdf";
			break;
		default:
			newlink = "./pages/" + area + ".html";
			break;
	}
		
	return(newlink);
}

function setIEtarget(){
	targetlink = " target='_blank'";
	return(targetlink);
}

function checkTarget(){
	if(runningIE() ){
		return("_blank");
	}else{
		return;
	}
}
