/**
	functions.js
	
	This javascript file contains a lot of "worker" functions for the various pages etc such as selecting play types for preview streams and image protecting the
	various artist assets
	
	VERSION:	1.1
	AUTHOR:	ANDREW FISHER

**/
function playsounds (mp3, wma) {
// this function has different options depending on what is set by the client.

    // pseudo code;
    // if the client has the cookie set then the preference will appear in
    // var playPreference = "MP3|WMA|NONE" so none is if none is set.


    // work out the available sizes
    var w,h;
    if (self.innerHeight) // all except Explorer
    {
	   w = self.innerWidth;
	   h = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
	   // Explorer 6 Strict Mode
    {
	   w = document.documentElement.clientWidth;
	   h = document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers
    {
	   w = document.body.clientWidth;
	   h = document.body.clientHeight;
    }

    var sy;
    if (self.pageYOffset) // all except Explorer
    {
	   sy = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop)
	   // Explorer 6 Strict
    {
	   sy = document.documentElement.scrollTop;
    }
    else if (document.body) // all other Explorers
    {
	   sy = document.body.scrollTop;
    }

    // check the values passed in
    if (wma =='' && mp3=='') {

        //window.alert("we made it into the close down fxn");
        // we are still in select mode so we will just pick them up from the form;
        wma = document.getElementById("sp_wma").value;
        mp3 = document.getElementById("sp_mp3").value;
        // close down this selector as well.
        document.getElementById("player").style.visibility = "hidden";
    }


    //alert("we are here");
    //alert(playPreference);

    switch (playPreference) {
        case "NONE":

            // now we open up the selector:
            var theselector = document.getElementById("player");
            theselector.style.visibility = "visible";

	if (isIE) {

		theselector.style.top = h*0.4+sy;
		theselector.style.left = w*0.1;
	}
	if (isOther) {
		//window.alert(h*0.4+sy);
		theselector.style.top = (h*0.4+sy) + "px";
		theselector.style.left = (w*0.1) + "px";
	}

            document.getElementById("sp_wma").value = wma;
            document.getElementById("sp_mp3").value = mp3;


            break;

        case "mp3":
            //alert(mp3);

	// kill any & symbols
	mp3 = mp3.replace(/&/g,"_ampersand_");

            window.location.href="/misc/preview.php?type=mp3&f=" + mp3;

            break;

        case "wma":
            //alert(wma);

	wma = wma.replace(/&/g,"_ampersand_");
            window.location.href="/misc/preview.php?type=wma&f=" + wma;

            break;
    }

}

function closePrefs () {
// this function closes the prefs window.
	document.getElementById("player").style.visibility = "hidden";
}

function sp_change (objname, file) {

	if (isIE) {
		document.all[objname].src = file;
	}

	if (isOther) {
		elem = document.getElementById(objname);
		elem.src = file;
	}
}

function checkform (theform) {

    var err = false;
    var msg = "The following problems exist\n\n";

    if (theform.elements["email"].value == "") {
        err = true;
        msg += "* Email is a required\n";
    }

    if (theform.elements["password1"].value == "" ) {
        err = true;
        msg += "* You must supply a password\n";
    }

    if (theform.elements["password1"].value != theform.elements["password2"].value) {
        err=true;
        msg += "* Passwords do not match\n";
    }

    if (theform.elements["fname"].value == "") {
        err=true;
        msg += "* First name is a required\n";
    }

    if (theform.elements["sname"].value == "") {
        err=true;
        msg += "* Surname is a required\n";
    }

    if (theform.elements["address1"].value == "") {
        err=true;
        msg += "* Address is required\n";
    }

    if (theform.elements["city"].value == "") {
        err=true;
        msg += "* city is required\n";
    }

    if (theform.elements["postcode"].value == "") {
        err=true;
        msg += "* postcode is required\n";
    }

    msg += "\nPlease check and submit again";

    if (err) {

        alert(msg);
        return (false);
    }
    return (true);

}

function sp_GetTshirtAddLink(thecode) {
// this function takes as it's parameter a value for the tshirt ID code
// that wants to be bought, it then does a page update using this code.

    // first get the item.
    var theselect = document.getElementById(thecode);
    //window.alert (theselect.selectedIndex);


    // now get the code assigned to the item.
    theprodcode = theselect.options[theselect.selectedIndex].value;

    if (theprodcode == "#") {
        // we haven't selected a size;
        window.alert("Please select a size from the drop down list " +
            "in order to buy this item.");
    } else {

        theLink = thisPage + "?add=" + theprodcode;

        //window.alert(theLink);
        location.href= theLink;
    }


}


function setPreference(preftype) {

    // this function sets the preference type;

    playPreference = preftype;

}

function sp_search() {

	location.href = "http://www.google.com/search?hl=en&q=site%3Awww.suspect-packages.com+" + document.getElementById("search").value;
}

function sp_list(thetype) {

    var thelink = "/cgi-bin/subscribe.pl?subscribe=" + thetype;
    thelink += "&email=" + document.getElementById("listemail").value;

    //window.alert(thelink);
    location.href= thelink;

}

function sp_LaunchPlayer() {

// this function launches the radio station player.

	var oWin = window.open("/radio/radio.php", "radiowin", "directories=no,menubar=no,resizable=no,scrollbars=no,status=now,toolbar=no,width=424,height=300");

	if (oWin == null || typeof(oWin)=="undefined") {

		window.alert("Please allow popups from suspect-packages.com in order to launch the radio station");
	}

}

/** THIS NEXT SECTION OF CODE IMPLEMENTS A BASIC RIGHT-CLICK IMAGE PROTECTION SCHEME - IT USES SOME CODE FROM QUIRKSMODE.COM 
WHICH IS DESIGNED FOR THIS PURPOSE. IT WON'T DEFEAT THE VIEW SOURCE OPTION AS NOTHING WILL STOP A HARDENED PERSON FROM 
PICKING STUFF UP [LIKE ME!] BUT IT WILL GO SOMEWAY TO DETERRING NEWBIES AND INFORM PEOPLE OF THE COPYRIGHT STATUS OF THE PICS **/

var specialcase = ((navigator.userAgent.indexOf('Mac') != -1) || document.all)
var flag = 0;
var msg = "We've spent time and money scanning these images, if you teef them we'll find you and crack your domepiece in half!!";
var x,y,x1,y1,copyAttempt;

function img_init()
{
	if (!(document.getElementById || document.all || document.layers)) return;
	if (specialcase && document.layers)
	{
		document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = special;
	}
	for (i=0;i<document.images.length;i++)
	{
		if (document.images[i].className.indexOf("prot") >= 0) {
			document.images[i].onmousedown = img_checkIt;
			document.images[i].onmouseup = function() {return false};
			if (specialcase)
			{
				document.images[i].onmousemove = img_special;
				document.images[i].onclick = img_clearIt;
			}
		}
	}
}

function img_checkIt(e)
{
	copyAttempt = 0;
	if (window.Event)
	{
		x = e.screenX;
		y = e.screenY;
		theButt = (e.which == 3);
	}
	else
	{
		x = window.event.clientX;
		y = window.event.clientY;
		theButt = (window.event.button == 2);
	}
	if (theButt)
	{
		copyAttempt = 1;
		flag = 0;
		alert(msg);
		return false; // NN4 only
	}
	if (specialcase) flag = 1;
	return false;
}

function img_special(e)
{
	theObj = '';
	if (window.Event)
	{
		x1 = e.screenX;
		y1 = e.screenY;
		if (e.target.parentNode) theObj = e.target.parentNode.tagName;
	}
	else
	{
		x1 = window.event.clientX;
		y1 = window.event.clientY;
		theObj = window.event.srcElement.parentElement.tagName;
	}
	var isLink = (theObj == 'A');
	if (flag && (!isLink || ((Math.abs(x-x1) > 10) || (Math.abs(y-y1) > 10))))
	{
		copyAttempt = 1;
		flag = 0;
		alert(msg);
		return false;
	}
}

function img_clearIt()
{
	flag = 0;
	if (copyAttempt)
	{
		copyAttempt = 0;
		return false;
	}
}



var isIE = false;
var isOther = false;

if (document.all) {
	isIE = true;
} else {
	isOther = true;
}

//window.alert("IE: " + isIE + " - Other: " + isOther);
