//when hovering the menu tabs
function tabhover(tabindex){
	document.getElementById("tab" + tabindex).style.backgroundImage="url(data/images/tab1.png)";
}

//when unhovering the menu tabs
function taboff(tabindex){
	document.getElementById("tab" + tabindex).style.backgroundImage="url(data/images/tab0.png)";
}

//linking to paypal - creates an HTML form with preset paypal atributes and submits it
function buyProduct(productID){

	var form = document.createElement("form");
    form.setAttribute("method", "post");
    form.setAttribute("action", "https://www.paypal.com/cgi-bin/webscr");

        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", "cmd");
        hiddenField.setAttribute("value", "_s-xclick");
		form.appendChild(hiddenField);
		
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", "hosted_button_id");
        hiddenField.setAttribute("value", productID);
		form.appendChild(hiddenField);

    document.body.appendChild(form);
    form.submit();
}

//linking to an external link
function redirect(linkaddress){
	window.location = linkaddress;
}

//left side content on all pages except homepage
function leftTextContents(contentIndex){
	document.getElementById("leftTextTitle").innerHTML = Titles[contentIndex];
	document.getElementById("contentframe").contentWindow.document.getElementById("leftTextContent").innerHTML = Contents[contentIndex].replace(/\|code\|/gi, "");
}

//closing the video window for all pages that have video preview
function closeVideo(){
	document.getElementById("videoWindow").innerHTML = "";
}

//code generators
function imageGenerator(codeObject, imageList){
	var address = new String;
	address = window.location.href;
	var splitter = new Array();
	splitter = address.split("CMS");
	document.getElementById(codeObject).value = "|code|<img src='" + splitter[0] + "contents/images/" + document.getElementById(imageList).value + "' alt='" + document.getElementById(imageList).value + "' />|code|";
}

function hyperlinkGenerator(linkObject, textObject, codeObject){
	document.getElementById(codeObject).value = "|code|<a href='" + document.getElementById(linkObject).value + "' target='_blank'>" + document.getElementById(textObject).value + "</a>|code|";
}

function productGenerator(productIDObject, textObject, codeObject){
	document.getElementById(codeObject).value = "|code|<span onclick='buyProduct(" + document.getElementById(productIDObject).value + ")' style='cursor:pointer; color:#E6E6E6;'><b>" + document.getElementById(textObject).value + "</b></span>|code|";
}

function selectAll(selectableObject){
	document.getElementById(selectableObject).focus();
    document.getElementById(selectableObject).select();
}

function sendmail(){
	document.getElementById("mailform").submit();
}
