var amountchange = new Array();
 amountchange["FIR"] = 50;
 amountchange["SEC"] = 100;
 amountchange["THE"] = 150;
 amountchange["FOU"] = 200;
 amountchange["FIF"] = 250;
 amountchange["SIX"] = 300;
 amountchange["SEV"] = 350;
 amountchange["EIG"] = 400;
 amountchange["NIN"] = 450;
 amountchange["TEN"] = 500;

var neigber=new Array();
neigber["FIR"]="SEC";
neigber["SEC"]="THE";
neigber["THE"]="FOU";
neigber["FOU"]="FIF";
neigber["FIF"]="SIX";
neigber["SIX"]="SEV";
neigber["SEV"]="EIG";
neigber["EIG"]="NIN";
neigber["NIN"]="TEN";
neigber["TEN"]="TEN";

var mediaprices = new Array();
var casesprices = new Array();
var insertsprices = new Array();
var storageprices = new Array();

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
		window.onload = func;
	else
	{
		window.onload = function()
		{
			if (oldonload) oldonload();
			func();
		}
	}
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain )
{
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

// this function gets the cookie, if it exists
function Get_Cookie( name )
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function checkEmail(str) {
///// function for validating email address
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)

		if (str.indexOf(at)==-1){
		    return false
		} else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		    return false
		} else 	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		} else  if (str.indexOf(at,(lat+1))!=-1){
		    return false
		} else 	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   return false
		} else  if (str.indexOf(dot,(lat+2))==-1){
		    return false
		} else if (str.indexOf(" ")!=-1){
		     return false
		} else {
 		 	return true
 		}
}

function getFlashMovieObject(movieName)
{
	if (document.embeds && document.embeds[movieName])
		return document.embeds[movieName];
	if (window.document[movieName])
		return window.document[movieName];
	if (navigator.appName.indexOf("Microsoft Internet")==1)
		return document.getElementById(movieName);
}

function checkMultipleEmail(emails, split_char)
{
	emails_array = emails.split(split_char);
	checkStatus = true;
	for (e in emails_array)
	{
		if (trim(emails_array[e]) != "" && !checkEmail(trim(emails_array[e])))
			checkStatus =false;
	}
	return checkStatus;
}

function checkML(emailValue)
{
	if(!checkEmail(emailValue))
	{
		alert (_tpl_emailNotValid);
		document.joinML.focus();
		return false;
	} else {
		var url = "xmlJoinML.php?joinML_email="+emailValue+"&eng="+eng;
		var xml = LoadXML(url);
		if(xml != null)
		{
			var message = xml.getElementsByTagName('rsp')[0].firstChild.data;
			alert(message);
			var response = xml.getElementsByTagName('rsp_stat')[0].firstChild.data;
			if (response)
				document.joinML.reset();
			else
				document.joinML.focus();
		}
		return false;
	}
}

function getHTTPObject()
{
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	try { return new XMLHttpRequest(); } catch(e) {}
	alert("XMLHttpRequest not supported");
	return null;
 }

function LoadHTML(url)
{

	var xmlHttp = getHTTPObject();
	xmlHttp.open("GET",url, false);
	xmlHttp.onreadystatechange = function()
	{
		   if (xmlHttp.readyState != 4)  { return; }
		   var serverResponse = xmlHttp.responseText;

	}
	xmlHttp.send(null);
	return xmlHttp.responseText;
}
function LoadXML(url)
{
	var xmlHttp = getHTTPObject();
	xmlHttp.open("GET",url, false);
	xmlHttp.onreadystatechange = function()
	{
		   if (xmlHttp.readyState != 4)  { return; }
		   var serverResponse = xmlHttp.responseText;
	};
	xmlHttp.send(null);
	return xmlHttp.responseXML.documentElement;
}

function PostXML(url,params)
{
	xmlHttp = false;
	// branch for native XMLHttpRequest object
	if(window.XMLHttpRequest && !(window.ActiveXObject))
	{
		try {
			xmlHttp = new XMLHttpRequest();
		} catch(e) {
			xmlHttp = false;
		}
		// branch for IE/Windows ActiveX version
	} else if(window.ActiveXObject)
	{
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				xmlHttp = false;
			}
		}
	}

	if (xmlHttp)
	{
		xmlHttp.open( "POST", url, false );
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		return xmlHttp.responseXML.documentElement;
	}
}

// bulid string with the form values, fobj the form object, valFunc is validate function
function getFormValues(fobj)
{
   var str = "";
   var valueArr = null;
   var val = "";
   var cmd = "";

   for(var i = 0;i < fobj.elements.length;i++)
   {
       switch(fobj.elements[i].type)
       {
      	case "text":
           case "hidden":
           case "textarea":
           	str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
           break;

           case "radio":
           case "checkbox":
               if(fobj.elements[i].checked)
               		str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
           break;

           case "select-one":
                str += fobj.elements[i].name + "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
           break;
       }
   }

   str = str.substr(0,(str.length - 1));
   return str;
}

// validate is got the validate function, if false then skip the validation
function submitAjaxForm(f,url)
{
   var str = getFormValues(f);
   xmlReq = postAjaxForm(url ,str);

 }

 function postAjaxForm(url,str)
{
   var doc = null
   if (typeof window.ActiveXObject != 'undefined' )
   {
       doc = new ActiveXObject("Microsoft.XMLHTTP");

   }
   else
   {
       doc = new XMLHttpRequest();
       doc.onload = displayState;
   }

   doc.open( "POST", url, true );
   doc.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   doc.send(str);
   return doc.responseXML.documentElement;
}

function showMessage(message, elementID)
{
	document.getElementById(elementID).innerText=message;
}

function clearMessage(elementID)
{
	document.getElementById(elementID).innerText="";
}


function IsNumeric(sText)
{
   var ValidChars = "0123456789.-, ";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;
 }

function trim(strText) {
/// TRIM STRING FUNCTION
    // this will get rid of leading spaces
    while (strText.substring(0,1) == ' ')
        strText = strText.substring(1, strText.length);
    // this will get rid of trailing spaces
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);
   return strText;
}

function escapeString(sString)
{
// DETECT WHAT TO PUT STRING IN FOR HTML FORM ( ' OR " ) DEPANDING ON STRING CONTENTS
	if (sString.indexOf("'") == -1)
		valSep = "'";
	else
		valSep = '"';
	return valSep+sString+valSep;
}

function replaceSubstring(inputString, fromString, toString) {
 // GOES THROUGH THE INPUTSTRING AND REPLACES EVERY OCCURRENCE OF FROMSTRING WITH TOSTRING
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
}

function popupWin(popUrl, width, height)
{
	if (!navigator.appName.indexOf("Microsoft")) width+=20;
	height+=5;
	topVar=((screen.height / 2)-(height/2));
	leftVar=((screen.width / 2)-(width/2));
	window.open(popUrl, "PopUp", "height="+height+", width="+width+", top="+topVar+", left="+leftVar+", scrollbars=yes, status=no, location=no, resize=yes, menubar=no, titlebar=no, toolbar=no");
}

function switchElementDisplay(elementID){
// SWITCH SELECTED ELEMENT DISPLAY: NONE/INLINE
	if (document.getElementById(elementID).style.display=="none")
		document.getElementById(elementID).style.display="inline";
	else
		document.getElementById(elementID).style.display="none";
}

/*
cSlider - class uses script.acoulo.us to make a transition effect on price
Author: Liran Oz
Date: 26.5.2008
*/
function cSlider(_price, _text, _loading, _priceDelta) {
	var price = _price;
	var text = _text;
	var loading = _loading;
	var priceDelta = (_priceDelta) ? _priceDelta : 50;
	var timeOut = 20;
	var transSpeed = 0.5;
	var priceObj = document.getElementById(_price);
	var textObj = document.getElementById(_text);
	var loadingObj = document.getElementById(loading);
	var lastUpdated = null;
	var defualtLoading = 'images/loading_trans.gif';


	var curItem = 0;
	var prices = new Array();
	var captions = new Array();
	var cycling = false;
	var firstDisplay = true;

	if (!priceObj || !textObj)			//must exist!
		return null;

	//set the price object to -delta top position (relative)
	setPriceOpacity(0);
	priceObj.style.position = "relative";
	priceObj.style.top = '-' + priceDelta + 'px';


	//make parent overflow hidden
	priceObj.parentNode.style.overflow = "hidden";

	this.addPrice = function(newPrice, newCaption)
	{
		if (curItem < prices.length-1) {		//short update occured, And not cycling last one
			prices[prices.length-1] = newPrice;
			captions[captions.length-1] = newCaption;
		}
		else {
			prices[prices.length] = newPrice;
			captions[captions.length] = newCaption;
		}

		if (!cycling) {
			cycling = true;
			if (firstDisplay) {
				showPrice();
				firstDisplay = false;

			}
			else
				hidePrice();
		}
	}

	function showPrice()
	{
		//set price text
		priceObj.innerHTML = prices[curItem];
		textObj.innerHTML = captions[curItem];


		//initiate script.acoulo.us parallel effect
		new Effect.Parallel([
			  new Effect.Move(price, { sync: true, x: 0, y: priceDelta, mode: 'relative' }),
			  new Effect.Opacity(price, { sync: true, from: 0, to: 1 })
			  //new Effect.Scale(text, 100, {scaleFrom: 0, scaleMode: { originalHeight: 10, originalWidth: 250, mode: 'absolute' } })

			], {
			  duration: transSpeed,
			  delay: 0.5,
		      afterFinish: function(effect) {
		        	priceObj.style.top = 0;
		        	priceObj.style.left = 0;
		        	//hide loading background
		        	loadingObj.style.backgroundImage = '';

		        	//show text
		        	textObj.style.display = "block";
		        	//is there a new price in queue?
		        	curItem++;
		        	if (curItem < prices.length) {
		        		//hide this one
		        		hidePrice();
		        	}
		        	else {
		        		//clear array
						prices = new Array();
						captions = new Array();
						curItem = 0;
						cycling = false;
		        	}

		        }}
		);


	}

	function hidePrice()
	{
		new Effect.Parallel([
			  new Effect.Move(price, { sync: true, x: 0, y: priceDelta, mode: 'relative' }),
			  new Effect.Opacity(price, { sync: true, from: 1, to: 0 })
			], {
			  duration: transSpeed,
			  delay: 0.5,
		      afterFinish: function(effect) {
		        	priceObj.style.top = '-' + priceDelta + 'px';		//back to original position
		        	priceObj.style.left = 0;
		        	//hide text
					textObj.style.display = "none";
		        	//show loading background
		        	loadingObj.style.backgroundImage = 'url('+defualtLoading+')';

		        	if (curItem < prices.length) {		//show again?
		        		showPrice();
		        	}
		        }}
		);
	}

	//style properties from http://snipplr.com/view/707/setopacity/
	function setPriceOpacity(op)
	{
		setStyleById(price, "filter", "alpha(opacity="+op+")");
		setStyleById(price, "opacity", op/100);
		setStyleById(price, "-moz-opacity", op/100);
	}



}

var slider = null;

function calcprice()
{
	//instantiate a new object if not exist already
	if (slider == null) {
		slider = new cSlider('actualprice', 'price_title', 'price_loading', 30);
	}

	var htmlp = '';
	var top="";
	var curprice = document.getElementById("actualprice");	//div of price
	var catp=document.getElementById("Hcopies");
	var curencyp=catp.value;

	if(curencyp=="TENtop") {
		curencyp="TEN";
		top="TENtop";
	}
	else {
		top=curencyp;
	}
	
	var storage=document.getElementById("storagemedia");
	var cases=document.getElementById("casesmedia");
	var surfacetype=document.getElementById("surfacecolor");
	if(storage.value!="none") 
	{
		var unitprice=mediaprices[curencyp]+casesprices[cases.value][curencyp]+storageprices[storage.value][curencyp];
		if(!surfacetype.checked) {
			unitprice=unitprice-surfacediscount;
		}
	}
	else
	{
		var insertes=document.getElementById("insertcases");
		
		var dup=document.getElementById("dupy");
	
		if(insertes.value!="none") {
			var unitprice=mediaprices[curencyp]+casesprices[cases.value][curencyp]+insertsprices[insertes.value][curencyp];
		}
		else
		{
			var unitprice=mediaprices[curencyp]+casesprices[cases.value][curencyp];
		}
	
		if(!surfacetype.checked) {
			unitprice=unitprice-surfacediscount;
		}
	
		if(!dup.checked) {
			unitprice=unitprice-dupdiscount;
		}
	}
	if(maindiscount!='0')
	{
		unitprice=unitprice-((unitprice*maindiscount)/100);
	}
	var fullprice = (unitprice*amountchange[top]);
	var rofullprice = (Math.round(fullprice * 100) / 100);
	unitprice=(Math.round(unitprice * 100) / 100);
	if(ratecurancy==1) {
		var tolltiptext='\"'+amountchange[top]+" "+pagetypetitle+" for "+currency_UK+rofullprice+"<br/> Each "+pagetypetitle+" for "+currency_UK+unitprice+'\"'; 
		htmlp="<span  class='number'><a href='javascript:void(0)' onclick='changecoin()' class='money'>"+currency_UK+"</a>"+rofullprice+"</span><span class='get'> Each "+pagetypetitle+" for "+currency_UK+unitprice+"</span>";
		//onmouseover='showToolTip(event,"+tolltiptext+");return false' onmouseout='hideToolTip();'
	}
	else {
		var convertedprice=rofullprice*ratecurancy;
		rofullprice = (Math.round(convertedprice * 100) / 100);
		var convertedunitprice=unitprice*ratecurancy;
		unitprice=(Math.round(convertedunitprice * 100) / 100);
		var tolltiptext='\"'+amountchange[top]+" "+pagetypetitle+" for "+currency_EU+rofullprice+"<br/> Each "+pagetypetitle+" for "+currency_EU+unitprice+'\"';
		htmlp="<span  class='number'><a href='javascript:void(0)' onclick='changecoin()' class='money'>"+currency_EU+"</a>"+(rofullprice)+"</span><span class='get'> Each "+pagetypetitle+" for "+currency_EU+unitprice+"</span>";
		// onmouseover='showToolTip(event,"+tolltiptext+");return false' onmouseout='hideToolTip();'
	}
	
	/*var animag = new YAHOO.util.Motion('actualprice', { points: { to: [590,  370] } }, 0.5, YAHOO.util.Easing.easeOut);
	animag.animate();*/


	var priceDesc = nextcategoryprice();

	slider.addPrice(htmlp, priceDesc);

	return false;
}

function nextcategoryprice()
{
	var top="";

	var curprice = document.getElementById("pricegen");	//div of price
	var catp=document.getElementById("Hcopies");
	var curencyp=neigber[catp.value];
	if(curencyp=="TENtop") {
		curencyp="TEN";
		top="TENtop";
	}
	else {
		top=curencyp;
	}
	var cases=document.getElementById("casesmedia");
	var storage=document.getElementById("storagemedia");
	var surfacetype=document.getElementById("surfacecolor");
	 if(storage.value!="none") {
		var unitprice=mediaprices[curencyp]+casesprices[cases.value][curencyp]+storageprices[storage.value][curencyp];
		if(!surfacetype.checked) {
			unitprice=unitprice-surfacediscount;
		}
	 }
	else
	{
		var insertes=document.getElementById("insertcases");
		
		var dup=document.getElementById("dupy");
		if(insertes.value!="none") {
			var unitprice=mediaprices[curencyp]+casesprices[cases.value][curencyp]+insertsprices[insertes.value][curencyp];
		}
		else {
			var unitprice=mediaprices[curencyp]+casesprices[cases.value][curencyp];
		}
		if(!surfacetype.checked) {
			unitprice=unitprice-dupdiscount;
		}
		if(!dup.checked) {
			unitprice=unitprice-surfacediscount;
		}
	}
	var fullprice = (unitprice*amountchange[top]);
	var rofullprice = (Math.round(fullprice * 100) / 100);
	var sendtop='\"'+top+'\"';

	if(ratecurancy==1) {
// var catPrice  = "<span class='get bold'>Get <a href='javascript:void(0)' onclick='return changeamount("+amountchange[top]+","+sendtop+")' class='quantity bold'>"+amountchange[top]+"</a> "+productType+" for "+currency_UK+""+rofullprice+"</span>";
		var catPrice  = "<span class='get bold'>Final price includes delivery</span>";
	}
	else {
		var convertedprice=rofullprice*ratecurancy;
		rofullprice = (Math.round(convertedprice * 100) / 100);
		var catPrice  = "<span class='get bold'>Final price includes delivery</span>";
// var catPrice  = "<span class='get bold'>Get <a href='javascript:void(0)' onclick='return changeamount("+amountchange[top]+","+sendtop+")' class='quantity bold'>"+amountchange[top]+"</a> "+productType+" for "+currency_EU+""+rofullprice+"</span>";
	}

	return catPrice;
}

function changecoin()
{
	if(ratecurancy==1)
	{
		ratecurancy=ratetoeuro;
	}
	else
	{
		ratecurancy=1;
	}
	calcprice();

}
function changeamount(amount,curanncy)
{
	var amountsd = document.getElementById("Hcopies");//select id
	amountsd.value=curanncy;
	calcprice();
}

function changepics(caseid)
{
	var curcase=caseid.value;
	container = document.getElementById("casespics");
	for (i=0; i<container.childNodes.length; i++)
	{
		cElement = container.childNodes[i];
		var myOldString=cElement.src;
		if(myOldString)
		{
			cElement.src = myOldString.replace("reg","");
		}

	}
	var curpic = document.getElementById(curcase);
	var cursrc=curpic.src;
	var newsrc=cursrc.replace("icon","iconreg");
	curpic.src=newsrc;


	return false;
}

function changeinsertpics(insertid)
{
	var curinsert=insertid.value;

	container = document.getElementById("insertpics");
	for (i=0; i<container.childNodes.length; i++)
	{
		cElement = container.childNodes[i];
			var myOldString=cElement.src;

			if(myOldString)
			{
				cElement.src = myOldString.replace("reg","");
			}

	}
	var curpic = document.getElementById(curinsert);
	var cursrc=curpic.src;
	var newsrc=cursrc.replace("icon","iconreg");
	curpic.src=newsrc;
	calcprice();
	return false;
}

function changeandcalc(caseid)
{
	changepics(caseid);//change case pics
	
	var storage=document.getElementById("storagemedia");
	if(storage.value=="none") {
			//change inserts select items
			var insertsd = document.getElementById("insertsdiv");
			//change the div acoording to the page
			var url = "ajax_functions.php?action=changeinserts&caseid="+caseid.value;
			var xml = LoadHTML(url);
			if(xml != null)
			{
				insertsd.innerHTML=xml;
			}
			//change pics acorrding to selected case
			var insertpictd = document.getElementById("insertpics");
			//change the div acoording to the page
			var url = "ajax_functions.php?action=changeinsertspics&caseid="+caseid.value;
			var xml = LoadHTML(url);
			if(xml != null)
			{
				insertpictd.innerHTML=xml;
			}
	
	}
	
	calcprice();

	return false;
}

function changeinsert(insertid)
{
	var insertsd = document.getElementById("insertcases");//select id
	insertsd.value=insertid;
	container = document.getElementById("insertpics");
	for (i=0; i<container.childNodes.length; i++)
	{
		cElement = container.childNodes[i];
			var myOldString=cElement.src;

			if(myOldString)
			{
				cElement.src = myOldString.replace("reg","");
			}

	}
	var curpic = document.getElementById(insertid);
	var cursrc=curpic.src;
	var newsrc=cursrc.replace("icon","iconreg");
	curpic.src=newsrc;
	calcprice();
	return false;
}

function changecase(caseid)
{

	var casesd = document.getElementById("casesmedia");//select id
	casesd.value=caseid;
	container = document.getElementById("casespics");
	for (i=0; i<container.childNodes.length; i++)
	{
		cElement = container.childNodes[i];
		var myOldString=cElement.src;
		if(myOldString)
		{
			cElement.src = myOldString.replace("reg","");
		}

	}
	var curpic = document.getElementById(caseid);
	var cursrc=curpic.src;
	var newsrc=cursrc.replace("icon","iconreg");
	curpic.src=newsrc;

	var storage=document.getElementById("storagemedia");
	if(storage.value=="none") {
		var insertsd = document.getElementById("insertsdiv");
		//change the div acoording to the page
		var url = "ajax_functions.php?action=changeinserts&caseid="+caseid;
		var xml = LoadHTML(url);
		if(xml != null)
		{
			insertsd.innerHTML=xml;
		}
		//change pics acorrding to selected case
		var insertpictd = document.getElementById("insertpics");
		//change the div acoording to the page
		var url = "ajax_functions.php?action=changeinsertspics&caseid="+caseid;
		var xml = LoadHTML(url);
		if(xml != null)
		{
			insertpictd.innerHTML=xml;
		}
	}
	
	calcprice();

	return false;
}

function changesrc(curimg)
{
	var cursrc=curimg.src;
	var newsrc=cursrc.replace("icon","iconreg");
	curimg.src=newsrc;
}

function changesrcbck(curimg)
{
	var cursrc=curimg.src;
	var newsrc=cursrc.replace("reg","");
	curimg.src=newsrc;
}

function formvalid (curForm)
{
	if (curForm.fname.value=="")
	{
		curForm.fname.className="red";
		var fnametextd = document.getElementById("fnametext");
		fnametextd.innerHTML=_alert_firstName;
		curForm.fname.focus();

		return false;
	}
	else
	{
		curForm.fname.className=" ";
		var fnametextd = document.getElementById("fnametext");
		fnametextd.innerHTML=" ";
	}
	if (curForm.Phone.value=="")
	{
		curForm.Phone.className="red";
		var Phonetextd = document.getElementById("Phonetext");
		Phonetextd.innerHTML=_alert_phone_empty;
		curForm.Phone.focus();

		return false;
	}
	else
	{
		curForm.Phone.className=" ";
		var Phonetextd = document.getElementById("Phonetext");
		Phonetextd.innerHTML=" ";
	}
	if (!IsNumeric(curForm.Phone.value))
	{
		curForm.Phone.className="red";
		var Phonetextd = document.getElementById("Phonetext");
		Phonetextd.innerHTML=_alert_phone;
		curForm.Phone.focus();

		return false;
	}
	else
	{
		curForm.Phone.className=" ";
		var Phonetextd = document.getElementById("Phonetext");
		Phonetextd.innerHTML=" ";
	}

	if (curForm.Email.value=="")
	{
		curForm.Email.className="red";
		var Emailtextd = document.getElementById("Emailtext");
		Emailtextd.innerHTML=_alert_email;
		curForm.Email.focus();

		return false;
	}
	else
	{
		curForm.Email.className=" ";
		var Emailtextd = document.getElementById("Emailtext");
		Emailtextd.innerHTML=" ";
	}
	if (!checkEmail(curForm.Email.value))
	{
		curForm.Email.className="red";
		var Emailtextd = document.getElementById("Emailtext");
		Emailtextd.innerHTML=_tpl_emailNotValid;
		curForm.Email.focus();

		return false;
	}
	else
	{
		curForm.Email.className=" ";
		var Emailtextd = document.getElementById("Emailtext");
		Emailtextd.innerHTML=" ";
	}


	//if (confirm(_confirm_sendForm))
	//{
	//	document.getElementById("sendButton").value=_tpl_submitting;
		return true;
	//}
	//else
	//	return false;
}

function additemtocart()
{

	var top="";
	var catp=document.getElementById("Hcopies");
	var curencyp=catp.value;
	if(curencyp=="TENtop")
	{
		curencyp="TEN";
		top="TENtop";
	}
	else
	{
		top=curencyp;
	}
	var cases=document.getElementById("casesmedia");
	var storage=document.getElementById("storagemedia");
	var surfacetype=document.getElementById("surfacecolor");
 if(storage.value!="none") {
 	
	var unitprice=mediaprices[curencyp]+casesprices[cases.value][curencyp]+storageprices[storage.value][curencyp];
	if(!surfacetype.checked) {
			unitprice=unitprice-surfacediscount;
		}
 }
	else
	{
			var insertes=document.getElementById("insertcases");
			
			var dup=document.getElementById("dupy");
		
			if(insertes.value!="none")
			{
				var unitprice=mediaprices[curencyp]+casesprices[cases.value][curencyp]+insertsprices[insertes.value][curencyp];
			}
			else
			{
				var unitprice=mediaprices[curencyp]+casesprices[cases.value][curencyp];
			}
			if(!surfacetype.checked)
			{
				unitprice=unitprice-surfacediscount;
			}
			if(!dup.checked)
			{
				unitprice=unitprice-dupdiscount;
			}
	}
	if(maindiscount!='0')
	{
		unitprice=unitprice-((unitprice*maindiscount)/100);
	}
	var fullprice = (unitprice*amountchange[top]);
	var rofullprice = (Math.round(fullprice * 100) / 100);
 if(storage.value!="none") {
	var url = "cart_functions.php?ptype="+pagetypetitle+"&unitp="+unitprice+"&quent="+amountchange[top]+"&caseid="+cases.value+"&storageid="+storage.value+"&prdID="+pagetypeid+"&surface="+surfacetype.checked;
 }
 else
 {
 	var url = "cart_functions.php?ptype="+pagetypetitle+"&unitp="+unitprice+"&quent="+amountchange[top]+"&caseid="+cases.value+"&insertid="+insertes.value+"&surface="+surfacetype.checked+"&dup="+dup.checked+"&storageid=none&prdID="+pagetypeid;
 }
	var xml = LoadHTML(url);
	if(xml == null)
	{
		alert(_itemadderror);
	}
	window.location.href="ShoppingCart.php";
	return false;
}

function clearcart()
{
	if (confirm(_confirm_delcart))
	{
		var url = "ajax_functions.php?action=clearcart";
		var xml = LoadHTML(url);
		if(xml == null)
		{
			alert(_cartdelerror);
		}
		 window.location.reload( true );
		return true;
	}
	else
		return false;

}

function saTest()
{
/*	new Effect.Parallel([
	  new Effect.Move('actualprice', { sync: true, x: 0, y: 30, mode: 'relative' }),
	  new Effect.Opacity('actualprice', { sync: true, from: 1, to: 0 })
	], {
	  duration: 0.8,
	  delay: 0.5,
      afterFinish: function(effect)
        {
        	var obj = document.getElementById('actualprice')
        	obj.style.top = 0;
        	obj.style.left = 0;

        }}
	);*/

	new Effect.Parallel([
	  new Effect.Move('actualprice', { sync: true, x: 0, y: 30, mode: 'relative' }),
	  new Effect.Opacity('actualprice', { sync: true, from: 0, to: 1 })
	], {
	  duration: 0.8,
	  delay: 0.5,
      afterFinish: function(effect)
        {
        	var obj = document.getElementById('actualprice')
        	obj.style.top = "-30px";
        	obj.style.left = 0;
        }}
	);
}

function copieschk(selobj)
{
	if(selobj.value=="above")
	{
		openFrame("home");
		selobj.value="TEN";
	}
	calcprice();
}

function shopcartframe()
{
	openFrame("shop");
}

function cancelorder()
{
	var confirmdocs=document.getElementById("confirmdocs");
	if (confirm(_confirm_cancelorder))
	{
		confirmdocs.value="N";
		document.myform.submit();
		return true;
	}
	else
		return false;
}