// JavaScript Document

var websiteUrl = "http://www.kissthecook.co.uk/";

Effects = {};



Effects.fade = function(id, opacStart, opacEnd, duration, callback)

{

	Effects.changeOpacity(0, id);

	var speed = Math.round(duration/100);

	var timer = 0;



	if(opacStart > opacEnd)

	{

		for(var i=opacStart; i>=opacEnd; i--)

		{

			setTimeout("Effects.changeOpacity("+ i +", '"+ id +"', "+ opacEnd +", '"+ callback +")", (timer*speed));

			timer++;

		}

	}

	else if(opacStart < opacEnd)

	{

		for(var i=opacStart; i<=opacEnd; i++)

		{

			setTimeout("Effects.changeOpacity("+ i +", '"+ id +"', "+ opacEnd +", '"+ callback +"')", (timer*speed));

			timer++;

		}

	}

}



Effects.changeOpacity = function(opacity, id, endPoint, callback)

{



	var _style = document.getElementById(id).style;

    _style.opacity = (opacity / 100);

    _style.MozOpacity = (opacity / 100);

    _style.KhtmlOpacity = (opacity / 100);

    _style.filter = "alpha(opacity=" + opacity + ")";

	

	if(opacity == endPoint && callback != null)

	{

		eval(callback);

	}

}



Effects.onFaded = function()

{

	// Add callback code here

}



function canAjax(){

  var ro;

  var browser = navigator.appName;

  if(browser == 'Microsoft Internet Explorer'){

    ro = new ActiveXObject("Microsoft.XMLHTTP");

  }else{

    ro = new XMLHttpRequest();

  }

  return ro;

}



function deleteItem(id){

  if(confirm('Are you sure you want to delete\nthis item from your basket?')){

		var myAjax = new Ajax('basket.php?action=delete&ajax=1&id='+id, {method: 'get', update: $('container')}).request();

	}

}



function page(prodUrl){

	var myAjax = new Ajax(prodUrl, {method: 'get', update: $('container')}).request();

}



function popImg(prodUrl){

	var image = window.open(prodUrl, 'imgpop', 'scrollbars=no, menubars=no, statusbar=no');

	image.focus();

}

function newWin(){

  winwin = window.open(websiteUrl + 'savebasket.php', 'basketSave', 'width=250,height=130,scrollbars=no,resizable=no,menubars=no');

  winwin.focus();

}

function basketMe(id){

	window.open(websiteUrl + 'viewbasket.php?id=' + id, 'basketWindow', '');

}

function reduceQty(id){

	if(document.getElementById('basket'+id)){

		aElements = new Array('basket'+id, 'subtotal'+id);

		var updateStr = '<img vspace="1" src="images/icon_wait.gif" alt="Working" width="14" height="14" align="texttop" />';

		for(i=0;i<aElements.length;i++) {

			document.getElementById(aElements[i]).innerHTML = updateStr;

		}

	}

	var myAjax = new Ajax(websiteUrl + 'basket.php?action=reduce&ajax=1&id='+id, {method: 'get', update: $('container')}).request();

}



function increaseQty(id){

	if(document.getElementById('basket'+id)){

		aElements = new Array('basket'+id, 'subtotal'+id);

		var updateStr = '<img vspace="1" src="images/icon_wait.gif" alt="Working" width="14" height="14" align="texttop" />';

		for(i=0;i<aElements.length;i++) {

			document.getElementById(aElements[i]).innerHTML = updateStr;

		}

	}

	var myAjax = new Ajax(websiteUrl + 'basket.php?action=increase&ajax=1&id='+id, {method: 'get', update: $('container')}).request();

}

function upperCase(what){

  what.value = what.value.toUpperCase().replace(/([^0-9A-Z ])/g,"");

}



function numberOnly(what){

  what.value = what.value.replace(/([^0-9])/g,"");

}

function updateMyBasket(){

  var myAjax = new Ajax(websiteUrl + 'basket.php?updatebasket=1', {method: 'get', update: $('container')}).request();

}

function getPrice(location, did){

var xmlhttp=false; //Clear our fetching variable

        try {

                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…

        } catch (e) {

                try {

                        xmlhttp = new

                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object

            } catch (E) {

                xmlhttp = false;

                        }

        }

        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {

                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest

        }

        var file = 'calcprice.php?location='; //This is the path to the file we just finished making *

    xmlhttp.open('GET', file + location + '&did=' + did, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **

    xmlhttp.onreadystatechange=function() {

        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data

                var content = xmlhttp.responseText; //The content data which has been retrieved ***

                if( content ){ //Make sure there is something in the content variable

                      document.getElementById(did).innerHTML = content; //Change the inner content of your div to the newly retrieved content ****

                }

        }

        }

        xmlhttp.send(null) //Nullify the XMLHttpRequest

return;

}

