// Javascript to delete and re-display Product box on Marketworks.
// Version 1.3

// This was written by Jon Langley - Jon@Jons-all-sorts.co.uk.
// If you must use it, please ask.
// If you want help, please ask.

// Tested on Marketworks 3 column and ZEN template.
// Assume can work on all. If in doubt, ASK!

// Get URL and extract parameters
var query = window.location.search.substring(1); 
var inv_num = '';
var category = ''; // Category
var meti = ''; // Item number. I use "i" as a vars, so used item backwards
var sfid = ''; // My SF ID
var AdNo = ''; //Force Adnumber.
var vars = query.split("&"); 
for (var x=0;x<vars.length;x++) { 
var pair = vars[x].split("="); 
  if (pair[0] == 'c') { 
    var category = pair[1]; } //found Category.
  if (pair[0] == 'i') { 
    var meti = pair[1]; } //found item number
  if (pair[0] == 'AdNo') { 
    var AdNo = pair[1]; } //found Ad number
  if (pair[0] == 'sfid') { 
    var sfid = pair[1]; } } //found SF ID.

// I display other currencies so these are the exchange rates I use to show estimates
var USD_Rate = 1.47; 
var EUR_Rate = 1.13; 
var GBP_Rate = 1;
var TempField1 = ''; // Inventory ExtraField1 - imported for future use.
var TempField2 = ''; // Inventory ExtraField2 - imported for future use.
var TempField3 = ''; // Inventory ExtraField3 - imported for future use.
var TempField4 = ''; // Inventory ExtraField4 - imported for future use.
var TempField5 = ''; // Inventory ExtraField5 - imported for future use.
var TempField6 = ''; // Inventory ExtraField6 - imported for future use.
var TempField7 = ''; // Inventory ExtraField7 - imported for future use.
var TempField8 = ''; // Inventory ExtraField8 - imported for future use.
var TempField9 = ''; // Inventory ExtraField9 - imported for future use.
var TempField10 = ''; // Inventory ExtraField10 - imported for future use.
var TempField11 = ''; // Inventory ExtraField11 - imported for future use.
var TempField12 = ''; // Inventory ExtraField12 - imported for future use.
var child_code = new Array();
var child_text = new Array();
var child_count = 0;

document.write('<style>');
if (category == '' || category =='0'){category='000000';}

catcheck('129590,129591,129592,129593,129594',category,'Arts');
catcheck('129597,129598,129599,129600',category,'Fimo');
catcheck('129603,129604,129605,129607,129608',category,'subMaxi');
catcheck('129609,129610,129611,129612,129613',category,'subMyFirst');
catcheck('129614,129615,129616,129617,129618',category,'subMidi');
catcheck('129619,129620,129621,129622,129623',category,'subMini');
catcheck('129602,129603,129609,129614,129619,129624,129603,129604,129605,129607,129608,129609,129610,129611,129612,129613,129614,129615,129616,129617,129618,129619,129620,129621,129622,129623',category,'Hama');
catcheck('129627,129628,129629,129630,155125',category,'JohnAdams');
catcheck('129633,129634,129635',category,'Seasonal');

catcheck('129636,129637,129638,129639',category,'Toys');
document.write('</style>');

//This function gets the info passed to it, creates a style sheet to hide the original and then creates a new one based on the parameters from URL and from variables passed to it.
function disp_box(Retail_Price,Qty_On_Hand,Inv_Num,Shipping,EU_Ship,ROW_Ship,TempField1,TempField2,TempField3,TempField4,TempField5,TempField6,TempField7,TempField8,TempField9,TempField10,TempField11,TempField12){
child_code[0] = TempField1;
child_text[0] = TempField2;
child_code[1] = TempField3;
child_text[1] = TempField4;
child_code[2] = TempField5;
child_text[2] = TempField6;
child_code[3] = TempField7;
child_text[3] = TempField8;
child_code[4] = TempField9;
child_text[4] = TempField10;
child_code[5] = TempField11;
child_text[5] = TempField12;
for (var x=0;x<6;x++) { 
	if (child_code[x] != '') { child_count = child_count + 1;}
}




// Convert Price Values to proper Numeric Values.
temp = Retail_Price.substr(1,(Retail_Price.length-1)); 
Retail_Price = temp * 1; 
temp = Shipping.substr(1,(Shipping.length-1)); 
Shipping = (temp * 1);
temp = EU_Ship.substr(1,(EU_Ship.length-1)); 
EU_Ship = temp * 1;
temp = ROW_Ship.substr(1,(ROW_Ship.length-1)); 
ROW_Ship = temp * 1;

// Create Style Sheet
document.write('<STYLE>#centercontainer table div,#idbuycont {display:none;}#MyBox {border:2px solid #689ACD;margin:5px;padding:10px;}#MyProd {display:table;width:100%;min-height:5px;padding:5px;}#Row1,#Row1a,#Row2,#Row3 {width:100%;min-height:5px;}#MyAddToCart,#MyPrice,#null {float:left;width:51%;min-height:5px;}#MyCheckout,#MyStock,#MyOurRef {float:right;width:49%;min-height:5px;}#MyShipping {width:100%;min-height:5px;}</STYLE>'); 

// All this next bit is the new box and content.
document.write('<div id="MyBox"><div id="Row1"><div id="MyPrice"><strong>Our Price:</strong> &pound;' + Retail_Price + '<br>(approx ' + (USD_Rate * Retail_Price).toFixed(2) + ' USD or ' + (EUR_Rate * Retail_Price).toFixed(2) + ' EUR)</div>');

//Checks if child items. if no, then display Qty in stock. If YES, display number of variations.
if (child_count <= 1) {
document.write('<div id="MyStock"><strong>Stock Availability: </strong><br>'); 
if (Qty_On_Hand>3) {
  document.write(Qty_On_Hand + ' in stock for quick despatch.</div>');
  } else if (Qty_On_Hand>0) {
  document.write('Only ' + Qty_On_Hand + ', so Order now.</div>');
  } else {
  document.write('Out of Stock. Due in soon.</div>');
  }
}
else {
document.write('<div id="MyStock"><strong> ' + child_count + ' variations available </strong></div>'); 
}
document.write('</div><div id="Row1a"><div id="null"></div><div id="MyOurRef"><strong>Our Ref:</strong> ' + Inv_Num + '</div></div>');


document.write('<div id="Row2"><div id="MyAddToCart"><form action="deluxestore_checkout.aspx" method="get" name="form1" id="form1"><p>'); 
if (Qty_On_Hand>0) {

//Checks if Child Items. If no, then standard Add to Cart Button. If YES, then create Select Box and Add to Cart.
	if (child_count <= 1) {
		document.write('<strong>Quantity:</strong> <input type="text" size="2" name="qty" id="qty" value="1" onkeyup=checknum("qty") maxlength="3" style="font-family: Verdana, Arial, Helvetica, serif; font-size : 11px" ID="Text1" ></input> <input type="submit" class="clsButton2" name="btnPickBulletImage" value="Add to Basket"><input type=hidden name=i value=' + meti + '>');
		} else {
		document.write('<select name="i"><option value="0">Select One</option>');
			for (x=0;x<6;x++) { 
				if (child_code[x]!="") { // As this is a loop, check the one we are looking at.
				// This next block will print the HTML AND the variables. In this example, a Table.
				document.write('<option value="' + child_code[x] + '">' + child_text[x] + '</option>');
				} //End IF.
			} //End For.
		document.write('</select><input type=hidden name="qty" id="qty" value="1"></input> <br><input type="submit" class="clsButton2" name="btnPickBulletImage" value="Add to Basket">');
		}
  } else {
  document.write('&nbsp;');
  } 


document.write('<input type=hidden name=c value=' + category + '><input type=hidden name=sfid value=' + sfid + '>');
document.write('<input type=hidden name=bas value=b> <input type=hidden name=oi value=> <input type=hidden name=cfrom value=id> <input type=hidden name=sid value=1></p> </form></div>'); 
document.write('<div id="MyCheckout"><form style="margin:0px;" name="form11" method="post" action="deluxestore_checkout.aspx?sid=1&bas=b&from=sc&sfid='+sfid+'&i=1&qty=1"><input type="submit" value="Go to Checkout"></form></div></div>');


document.write('<div id="Row3"><div id="MyShipping">&nbsp;<br><strong>Shipping Options:</strong><br><strong>To UK:</strong> From '); 

document.write('&pound;' + (Shipping.toFixed(2))); 
document.write('<br><strong>To EU:</strong> From ');
document.write('&pound;' + (EU_Ship *1).toFixed(2) + ' (approx ' + (EUR_Rate * EU_Ship).toFixed(2) + ' EUR)'); 
document.write('<br><strong>To ROW:</strong> From '); 
document.write('&pound;' + (ROW_Ship *1).toFixed(2) + ' (approx ' + (USD_Rate * ROW_Ship).toFixed(2) + ' USD)'); 
document.write('<br> Use the '); 
document.write('<input type="submit" class="clsButton2" name="btnShipCalculator" value="Shipping Calculator" onclick=window.open("../en/rateCalc.aspx?u=66929&c=' + sfid + '&i=' + meti + '")>'); 
document.write(' for specific Countries/Quantities</div></div></div>');
document.write('<p><H2>DESCRIPTION:</h2></p>');
return;
}


// This function creates a find this item on eBay link.
// AND!!!! If Amazon_Asin is assigned, display Amazon link direct to product.
// If you have "Borrowed" this code, change codes 30697849 to your OWN unique Store ID. 
// If in doubt, ask. I will be happy to help.
function disp_ebay(Item_Title,Amazon_Asin){
Item_Title = Trim(Item_Title);
Amazon_Asin = Trim(Amazon_Asin);
document.write('<table width="100%" border="0" cellspacing="2" cellpadding="2"><tr>');

// Display Top eBay section.
document.write('<td align="center"><a target="_blank" href="http://rover.ebay.com/rover/1/710-5232-2978-1/1?AID=9479574&PID=1723873&mpre=http%3A//search.ebay.co.uk/search/search.dll%3Ffrom=R40%26_trksid=m37%26satitle=' + Item_Title + '">Find these items in eBay </a></td>');

if (Amazon_Asin!="") { 
// Display Top Amazon section.
document.write('<td align="center"><a target="_New" href="http://www.amazon.co.uk/gp/redirect.html?ie=UTF8&location=http%3A%2F%2Fwww.amazon.co.uk%2Fs%3FinitialSearch%3D1%26url%3Dsearch-alias%253Daps%26field-keywords%3D' + Item_Title + '%26Go.x%3D0%26Go.y%3D0%26Go%3DGo&tag=joalso-21&linkCode=ur2&camp=1634&creative=6738">Find these items on Amazon.co.uk</a><img src="http://www.assoc-amazon.co.uk/e/ir?t=joalso-21&amp;l=ur2&amp;o=2" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></td>');
  }
document.write('</tr><tr>');
// Display Bottom eBay section.
document.write('<td align="center"><a target="_blank" href="http://rover.ebay.com/rover/1/710-5232-2978-1/1?AID=9479574&PID=1723873&mpre=http%3A//search.stores.ebay.co.uk/search/search.dll%3Fquery%3D' + Item_Title + '%26sasel%3D30697849"><IMG src="http://www.Jons-all-sorts.co.uk/hi/67/66929/storeslogo.gif" border=0></A></td>');
if (Amazon_Asin!="") { 
// Display Bottom Amazon section.
document.write('<td align="center"><a target="_New" href="http://www.amazon.co.uk/gp/redirect.html?ie=UTF8&location=http%3A%2F%2Fwww.amazon.co.uk%2Fs%3FinitialSearch%3D1%26url%3Dsearch-alias%253Daps%26field-keywords%3D' + Item_Title + '%26Go.x%3D0%26Go.y%3D0%26Go%3DGo&tag=joalso-21&linkCode=ur2&camp=1634&creative=6738"><img src="http://g-ec2.images-amazon.com/images/G/02/uk-shared/logos/amazon-logo-151x32.gif" /></a></td>');
  }
document.write('</tr></table><p></p>');
return;
}

// Well you read this far.
// This took me a lot of work. If you would like to use it, I would rather you ask first.
// If you want help installing/understanding/customizing it, then please ask.

// Banner Rotation

var bannerAD=new Array();
var bannerADlink=new Array();
var bannerADstatus=new Array();
 
   bannerAD[0]="http://www.jons-all-sorts.co.uk/hi/67/66929/fudgeheaven.jpg"; // Image0
   bannerADlink[0]="http://www.fudgeheaven.co.uk/";// Link to Image0
   bannerADstatus[0]="";// Display Link to Image0

   bannerAD[1]="http://www.ftjcfx.com/image-1723873-10374226"; // Image1
   bannerADlink[1]="http://www.tkqlhce.com/click-1723873-10374226"; //Link to Image1
   bannerADstatus[1]="http://www.thomascook.com/tc_offers/tc_offers_s.asp?page=lates";// Link to Image1

   bannerAD[2]="http://www.ftjcfx.com/image-1723873-10386450";
   bannerADlink[2]="http://www.jdoqocy.com/click-1723873-10386450";
   bannerADstatus[2]="http://www.skype.com/";

   bannerAD[3]="http://www.lduhtrp.net/image-1723873-10285637";
   bannerADlink[3]="http://rover.ebay.com/rover/1/710-5232-2978-15/1?aid=10285637&pid=1723873";
   bannerADstatus[3]="http://www.ebay.co.uk/";

   bannerAD[4]="http://www.ftjcfx.com/image-1723873-10365654";
   bannerADlink[4]="http://www.tkqlhce.com/click-1723873-10365654";
   bannerADstatus[4]="http://www.joincreditexpert.com/";

   bannerAD[5]="http://www.ftjcfx.com/image-1723873-10374226"; 
   bannerADlink[5]="http://www.tkqlhce.com/click-1723873-10374226"; 
   bannerADstatus[5]="http://www.thomascook.com/tc_offers/tc_offers_s.asp?page=lates";

   bannerAD[6]="http://www.ftjcfx.com/image-1723873-10386450";
   bannerADlink[6]="http://www.jdoqocy.com/click-1723873-10386450";
   bannerADstatus[6]="http://www.skype.com/";

   bannerAD[7]="http://www.lduhtrp.net/image-1723873-10285637";
   bannerADlink[7]="http://rover.ebay.com/rover/1/710-5232-2978-15/1?aid=10285637&pid=1723873";
   bannerADstatus[7]="http://www.ebay.co.uk/";

   bannerAD[8]="http://www.ftjcfx.com/image-1723873-10365654";
   bannerADlink[8]="http://www.tkqlhce.com/click-1723873-10365654";
   bannerADstatus[8]="http://www.joincreditexpert.com/";

   bannerAD[9]="http://www.uk2numbers.co.uk/img/0845-numbers-uk2.gif";
   bannerADlink[9]="http://www.UK2numbers.co.uk/?rr=HCJ80540";
   bannerADstatus[9]="http://www.UK2numbers.co.uk/";

   bannerAD[10]="http://www.uk2numbers.co.uk/img/0845-numbers-uk2.gif";
   bannerADlink[10]="http://www.UK2numbers.co.uk/?rr=HCJ80540";
   bannerADstatus[10]="http://www.UK2numbers.co.uk//";

   bannerAD[11]="http://www.jons-all-sorts.co.uk/hi/67/66929/fudgeheaven.jpg"; 
   bannerADlink[11]="http://www.fudgeheaven.co.uk/";
   bannerADstatus[11]="";

   bannerAD[12]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank
   bannerADlink[12]="";
   bannerADstatus[12]="";
			// I get paid for the ones above
   bannerAD[13]="http://www.mustget1.com/june_images/must_get_1.gif"; //must_get_1
   bannerADlink[13]="http://www.mustget1.com/";
   bannerADstatus[13]="";
   bannerAD[14]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank
   bannerADlink[14]="";
   bannerADstatus[14]="";
   bannerAD[15]="http://www.kingsbridgekaraoke.co.uk/catalog/images/kkbanner.jpg"; //shkaraoke
   bannerADlink[15]="http://www.kingsbridgekaraoke.co.uk/";
   bannerADstatus[15]="";
   bannerAD[16]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank
   bannerADlink[16]="";
   bannerADstatus[16]="";

   bannerAD[17]="http://www.tramikisupplies.co.uk/ekmps/shops/tramikisupplies/images/system/tram(2).gif"; 
   bannerADlink[17]="http://www.tramikisupplies.co.uk/";
   bannerADstatus[17]="";
   bannerAD[18]="http://www.alistoyshed.co.uk/images/top.jpg"; //alistoyshed05
   bannerADlink[18]="http://www.alistoyshed.co.uk/";
   bannerADstatus[18]="";
   bannerAD[19]="http://sexylittlenumbers.co.uk/store/images/logo.jpg"; //sexydresses4u
   bannerADlink[19]="http://www.sexylittlenumbers.co.uk/";
   bannerADstatus[19]="";
   bannerAD[20]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank 
   bannerADlink[20]="";
   bannerADstatus[20]="";
   bannerAD[21]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank 
   bannerADlink[21]="";
   bannerADstatus[21]="";
   bannerAD[22]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank 
   bannerADlink[22]="";
   bannerADstatus[22]="";
   bannerAD[23]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank
   bannerADlink[23]="";
   bannerADstatus[23]="";
   bannerAD[24]="http://www.cheaperbatteries.co.uk/ekmps/shops/batteries/images/system/cb_small_logo.jpg"; //cheaperbatteries
   bannerADlink[24]="http://www.cheaperbatteries.co.uk/";
   bannerADstatus[24]="";
   bannerAD[25]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank
   bannerADlink[25]="";
   bannerADstatus[25]="";
   bannerAD[26]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank
   bannerADlink[26]="";
   bannerADstatus[26]="";
   bannerAD[27]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank
   bannerADlink[27]="";
   bannerADstatus[27]="";
   bannerAD[28]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank
   bannerADlink[28]="";
   bannerADstatus[28]="";
   bannerAD[29]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank
   bannerADlink[29]="";
   bannerADstatus[29]="";
   bannerAD[30]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank
   bannerADlink[30]="";
   bannerADstatus[30]="";
   bannerAD[31]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank
   bannerADlink[31]="";
   bannerADstatus[31]="";
   bannerAD[32]="http://www.gardenerscottage.com/85cd43c0.gif"; //gardenerscottage
   bannerADlink[32]="http://www.gardenerscottage.com/";
   bannerADstatus[32]="";
   bannerAD[33]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank
   bannerADlink[33]="";
   bannerADstatus[33]="";
   bannerAD[34]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank
   bannerADlink[34]="";
   bannerADstatus[34]="";
   bannerAD[35]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank
   bannerADlink[35]="";
   bannerADstatus[35]="";
   bannerAD[36]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank
   bannerADlink[36]="";
   bannerADstatus[36]="";
   bannerAD[37]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank
   bannerADlink[37]="";
   bannerADstatus[37]="";
   bannerAD[38]="http://pics.ebaystatic.com/aw/pics/s.gif"; //Blank
   bannerADlink[38]="";
   bannerADstatus[38]="";
   bannerAD[39]="http://www.costumecabin.co.uk/siteimages/desires/27072/134994.gif"; //motormadgizard
   bannerADlink[39]="http://www.costumecabin.co.uk/";
   bannerADstatus[39]="Costume Cabin";

var adNum=AdNo;
if (AdNo == '' ) {
var adNum=Math.floor(Math.random()*(bannerAD.length));
}
 
function jump2url(){
jumpUrl=bannerADlink[adNum];
jumpTarget='_blank';
if (jumpUrl != ''){
if (jumpTarget != '')window.open(jumpUrl,jumpTarget);
else location.href=jumpUrl;
}
}

function displayStatusMsg($request) {
if (bannerADstatus[adNum]=='') {
status=bannerADlink[adNum];
} else {
status=bannerADstatus[adNum];
}
if ($request=='clear') {
status='Done';
}
document.returnValue = true;
}

function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() {
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function LTrim(str)
{
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(0)) != -1) {
    // We have a string with leading blank(s)...
    var j=0, i = s.length;
    // Iterate from the far left of string until we
    // don't have any more whitespace...
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
    j++;
    // Get the substring from the first non-whitespace
    // character to the end of the string...
    s = s.substring(j, i);
  }
  return s;
}

function RTrim(str)
{
  // We don't want to trim JUST spaces, but also tabs,
  // line feeds, etc.  Add anything else you want to
  // "trim" here in Whitespace
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
    // We have a string with trailing blank(s)...
    var i = s.length - 1;       // Get length of string
    // Iterate from the far right of string until we
    // don't have any more whitespace...
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
      i--;
    // Get the substring from the front of the string to
    // where the last non-whitespace character is...
    s = s.substring(0, i+1);
  }
  return s;
}

function Trim(str)
{
  return RTrim(LTrim(str));
}

function catcheck(str1,str2,str3)
{
document.write('#cats dd .catssub' + str3 + ', .catssub' + str3);
if (str1.match(str2)==str2) {
document.write(' {display:block;}');
} else {
document.write(' {display:none;}');
}
return;
}
