// this code disables the right side mouse button
var message="© 2009 JK Trading. Page Protected"; //	Alert Box message
if (document.layers)
{
document.captureEvents(Event.MOUSEDOWN);
}
{
document.oncontextmenu=new Function("alert(message);return false");
}


// function to write data (called 'name') to cookie (data is 'value')
function createCookie(name,value) /* expiry date not set so cookie trashed on browser close */
{
document.cookie = name + "=" + escape(value);
}


// function to read data (stored in 'name') from cookie
function readCookie(name)
{
if (document.cookie.length>0)
{
cookie_start=document.cookie.indexOf(name + "=");
if (cookie_start != -1)
{ 
cookie_start = cookie_start + name.length + 1; 
cookie_end = document.cookie.indexOf(";",cookie_start);
if (cookie_end == -1) cookie_end = document.cookie.length;
return unescape(document.cookie.substring(cookie_start,cookie_end));
} 
}
return "";
}


// function which is called by all the iframe pages on loading to check to see if "orphaned"
function orphaned_page(pagemenu,currentpage)
{
var iframe_page = "index.php"; // variable iframe_page is the default loading page
// checks to see if current page -- self.location -- has been loaded outside of the iframe
if (top.location == self.location) // It sets a new URL pointing to the start page 
{
if (currentpage != "")
{
window.location = iframe_page + "?" + currentpage + "&" + pagemenu;
}
else
{
window.location = iframe_page + "?" + window.location.pathname + "&" + pagemenu;
}
}
}


// function called by index-page to gather any iframe load info transmitted within the URL
function findpage()
{
// this returns the URL from the question mark (?) in the URL string
if (window.location.search)
{
// this sets variable to the characters in "location" between specified indices of 1 and pos_index and end
var pos_index = location.search.indexOf('&','0')
pagemenu_start = location.search.substring(pos_index + 1,location.search.length);
tx_page = location.search.substring(1,pos_index);
}
else
{
pagemenu_start = "page-menu-00" // sets page-menu to a home page info at entry to site
tx_page = "";
}
}


// function to store current 'y' position or scroll point for page reloading
function store_position()
{
var old_y_position = document.documentElement.scrollTop; // store x-pos = 0 and y-pos =  document read
// var old_y_position = document.body.scrollTop; // does not work -- returns '0' in DOCTYPE xhtml 1.0 
createCookie('page_store_pos',old_y_position);
}


// function to set start 'y' position or scroll point on page load
function load_position()
{
if (!location.hash) // is there a Page Anchor present in the URL, if not use the page_load_pos co-ordinates 
{
var new_y_position = readCookie('page_load_pos');
window.scrollTo(0,new_y_position); // scroll to x-pos = 0 and y-pos = cookie read
}
else // is so go to the #Anchor
{}
}


// function to unhide the selected hidden divs to display Page Menus / Headings or Product Headers
function unhide(action,divID_new)
{
var newdiv_object = window.top.document.getElementById(divID_new);
{
switch(action)
{
case '1':
{
divID_old = readCookie('page_menu');
var olddiv_object = window.top.document.getElementById(divID_old);
olddiv_object.className="hidden";
newdiv_object.className="unhidden";
createCookie('page_menu',divID_new)
}
break;    
case '2':
{
window.document.getElementById(divID_new).style.display="block";
}
break;
default:{alert ('Please Alert the Webmaster');}
}
}
}


// function to unhide / hide the back button div
function back_button(action)
{
var object = window.top.document.getElementById('spare-div'); // back-button hidden div
{
switch(action)
{
case 'unhide': // unhide
{
object.style.display="block";
}
break;
case 'hide': // hide
{
object.style.display="none";
}
break;
default:{alert ('Please Alert the Webmaster');}
}
}
}


// this is the primary function to mask out any sizing changes and then display each item in sequence
function core_script_css(i)
{
document.write ("<div class=\"outer-items\">");
document.write ("<div class=\"next_in-items\">");
//	insert picture
document.write ("<div class=\"middle-items-img\">");
document.write ("<div class=\"info-valign-items-img\">");

document.write ("<img style=\"visibility:hidden\" id=\"" + div_id + "\"src=\"");
document.write (jsProductArray[i][4]);	//	product picture
document.write ("\" alt=\"");
document.write (jsProductArray[i][5]);	// product "alt title"
document.write ("\" onload=\"changeSize(" + div_id + ")\"></img>"); // modify the image size once it has finished loading in 
document.write ("</div>");
document.write ("</div>");
document.write ("<div class=\"middle-items-info\" style=\"width: auto\">");
document.write ("<div class=\"info-valign-items-info\">"); //	insert description
document.write ("<div style=\"text-align: left;\"><span class=\"enhance\">");
document.write (jsProductArray[i][5]);
document.write ("</span><br/>");	// product name
document.write ("Stock Code: &nbsp;");
document.write (jsProductArray[i][3]);
document.write ("<br /><br />");  // product item number
//	insert bullet points
for (n=6; n<=15; n++)
{
if (jsProductArray[i][n] != "") // Check for blank bullet point
{
document.write ("<span style=\"font-weight: normal;\">");
document.write ("&nbsp;&bull;&nbsp;");
document.write (jsProductArray[i][n]); // product description
document.write ("</span><br/>");
}
}
document.write ("<br/>");
//	insert price and shipping information
document.write ("<span class=\"enhance1\">Our Price &nbsp;&nbsp;&pound;" + jsProductArray[i][16] + "</span>&nbsp;&nbsp;"); // product cost 
pp_select() // call the function to add the Postage and Packing information to the displayed product item 
document.write ("</div>");
document.write ("</div>");
document.write ("</div>");
document.write ("<div class=\"middle-items-cart\">");
document.write ("<div class=\"add-to-cart-valign-items\">"); //	insert add to cart button
// Check for temporarily out of stock flag and display message if so
if (jsProductArray[i][23] == true) 
{
document.write ("<div class=\"no-stock\">Sorry but this item is temporarily out of stock. Please check availability again soon or <a href=\"mailto:orders@jktrading.co.uk?subject=Stock Enquiry\" target=\"_blank\">email us.</a></div>");
}
else
{
AddtoCartButton() // call the function to sequence the Add to Cart Button to the displayed product item 
}
document.write ("</div>");
document.write ("</div>");
document.write ("<div class=\"stop-floats\"></div>");
div_id++; // increase the Image Tag ID number 
document.write ("</div>");
document.write ("</div>");
document.write ("<div><hr noshade=\"noshade\"/></div>");
}


// this function displays the Add to Cart Button in each item sequence
function AddtoCartButton()
{
document.write ("<form target=\"paypal\" action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\">");
document.write ("<div class=\"AddtoCartButton-div\">");
document.write ("<br /><br />");
document.write ("<input type=\"image\" src=\"images/paypalbutton.gif\" name=\"submit\"  class=\"AddtoCartButton-input\" alt=\"Add to Cart\" />");	// Button Image
document.write ("<div style=\"width: auto; text-align: center; border: 0px blue solid;\">");
options_select() // call the function to see if there are any options for the displayed product item 
international_buyers()
document.write ("</div>");
document.write ("</div>");
//alert(i);
//alert(jsProductArray[i][16]);
document.write ("<input type=\"hidden\" name=\"add\" value=\"1\"/>");
document.write ("<input type=\"hidden\" name=\"cmd\" value=\"_cart\"/>");
document.write ("<input type=\"hidden\" name=\"business\" value=\"payments@jktrading.co.uk\"/>");
document.write ("<input type=\"hidden\" name=\"item_name\" value=\"" + jsProductArray[i][5] + "\"/>");
document.write ("<input type=\"hidden\" name=\"item_number\" value=\"" + jsProductArray[i][3] + "\"/>");
document.write ("<input type=\"hidden\" name=\"amount\" value=\"" + jsProductArray[i][16] + "\"/>");
document.write ("<input type=\"hidden\" name=\"no_shipping\" value=\"0\"/>");
document.write ("<input type=\"hidden\" name=\"no_note\" value=\"1\"/>");
document.write ("<input type=\"hidden\" name=\"currency_code\" value=\"GBP\"/>");
document.write ("<input type=\"hidden\" name=\"weight\" value=\"7\"/>");
document.write ("<input type=\"hidden\" name=\"weight_unit\" value=\"kgs\"/>");
document.write ("<input type=\"hidden\" name=\"lc\" value=\"GB\"/>");
document.write ("<input type=\"hidden\" name=\"bn\" value=\"PP-ShopCartBF\"/>");
document.write ("<input type=\"hidden\" name=\"return\" value=\"" + paypal_ok + "\"/>");
document.write ("<input type=\"hidden\" name=\"cancel_return\" value=\"" + paypal_us + "\"/>");
document.write ("</form>");

document.write ("<div class=\"AddtoCartButton-div\">");
document.write ("<div style=\"width: auto; text-align: center; border: 0px blue solid;\">");
document.write ("</div>");
document.write ("</div>");

}


/*
// this function displays the Add to Cart Button on the 'Postage and Packing Costs' page
function ShippingCartButton(pp)
{
jsProductArray[0][3] = ShippingArray[pp][3];
jsProductArray[0][5] = ShippingArray[pp][5];
jsProductArray[0][16] = ShippingArray[pp][16];
// document.write (pp);
// document.write (jsProductArray[0][16]);
AddtoCartButton()
}
*/


// this function checks for product options or if the postage and packing page is being displayed
function options_select()
{
if (jsProductArray[i][18] != "")	// select whether product options exist
{
document.write ("<div style=\"border: 0px blue solid; margin: 20px 0px 20px 0px;\">");
document.write ("<input type=\"hidden\" name=\"on0\" value=\"");
document.write (jsProductArray[i][18]);	//	Output for PayPal Cart Option Description
document.write (" Selected is \"><span class=\"enhance\">Select ");
document.write (jsProductArray[i][18]);	//	Output for drop down menu heading
//document.write ("<br />");
document.write ("<select style=\"background-color: white;\" name=\"os0\">");
{
for (j=19; j<=22; j++)
{
if(jsProductArray[i][j] != "")	// Check for blank option fields
{
document.write ("<option style=\"background-color: white;\" value=\"" + jsProductArray[i][j]);	//	Output for PayPal Cart Option
document.write ("\">&nbsp;" + jsProductArray[i][j] + "&nbsp;");	//	Output for drop down menu option
}
}
document.write ("</select></span>");
}
}
else
{
if (p_and_p != true)	//	Selects if loaded Postage and Packing Page to exclude "No Option" Message
{
// document.write ("<div class=\"no-options\">sorry no options<br />are available</div>");	//	Add any text here for "No Options" if required
}
else
{
//p_and_p = false;	//	Resets flag to allow "No Options" Message
}
}
document.write ("</div>");
}


// this function checks to see if available for international purchase
function international_buyers()
{
if (p_and_p != true) // Selects if loaded Postage and Packing Page to exclude International Buyers Button
{
if (jsProductArray[i][24] != "") 
{

document.write ("<div class=\"international\">");
document.write ("<hr/><a href=\"" + jsProductArray[i][24] + "\" target=\"_blank\">");
document.write ("Non UK buyers <br />please click here");
document.write ("</a>");
document.write ("</div>");
}
else
{}
}
else
{}
// the following line is commented out to allow variable p_and_p to be used in function options_select
p_and_p = false;	//	Resets flag to allow "No Options" Message
}


// this function displays the p+p image dependant on the product shipping code
function pp_select()
{
if (jsProductArray[i][17] == "1")	// select product shipping mode
{
document.write ("<a href=\"shipping.html\" onclick=\"unhide('1','page-menu-09');\">");
document.write ("<img src=\"images/reddot.jpg\" class=\"shipping-dot\" alt=\"Shipping Information\">");
document.write ("</img></a>");
}
else
{
document.write ("<a href=\"shipping.html\" onclick=\"unhide('1','page-menu-09');\">");
document.write ("<img src=\"images/bluedot.jpg\" class=\"shipping-dot\" alt=\"Shipping Information\">");
document.write ("</img></a>");
}
}


// this function reads the Product Images and resizes them to fit the optimal page
function changeSize(div_id)
{
var ht = 0;
var wd = 0;
var img_size = 180; // sets the Maximum size to be 180px by 180px
var aspect_ratio = 1;
object = document.getElementById(div_id);
var wd = object.height;
var ht = object.width;

var aspect_ratio = (( object.height/object.width).toFixed(2)); // records the aspect ratio of Height to Width
if (aspect_ratio >= 1) // selects either Portrait (>=1) or Landscape (<1)
{
object.height=img_size; // resets the larger dimension to the max size available
object.width=img_size/aspect_ratio; // calculates the other dimension to maintain original aspect ratio
}
else
{
object.height=img_size*aspect_ratio; // calculates the other dimension to maintain original aspect ratio
object.width=img_size; // resets the larger dimension to the max size available
}
object.style.visibility = "visible"; // make image visible again
}


// this function produces the view-a-cart button and link to Paypal 
function view_cart()
{
document.write ("<form target=\"paypal\" action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\">");
document.write ("<input type=\"hidden\" name=\"cmd\" value=\"_cart\">");
document.write ("<input type=\"hidden\" name=\"business\" value=\"payments@jktrading.co.uk\">");
document.write ("<input type=\"image\" src=\"images/view_cart.gif\" border=\"0\" name=\"submit\" alt=\"View your cart\">");
document.write ("<input type=\"hidden\" name=\"display\" value=\"1\">");
document.write ("</form>");
}

// ------------------------------------------------------------------------------------------------ SET UP NON LEFT CLICK SELECT

function disableselect(e){
return false
}

function reEnable(){
return true
}

//if IE4+
document.onselectstart=new Function ("return false")

//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
