function productdetail(prod,showrb,size) {
    if (size == '') size = '250:150';
    size = size.split(':');
    w = parseInt(size[0])+320;
    h = parseInt(size[1])+120;
    if (window.screen) {
        if (screen.availWidth < w) w = screen.availWidth -50;
        if (screen.availHeight < h) w = screen.availHeight -50;
        cw = Math.floor((screen.availWidth-w)/2);
        ch = Math.floor((screen.availHeight-h)/2);
    }
    x = '';
    if (showrb) x = '&showrb=true';
    window.open('/productdetailpop.php?p='+prod+x,'prodinfo'+w+'_'+h,'width='+w+',height='+h+',top='+ch+',left='+cw+',scrollbars=yes, resize=yes');
    return false;
}
function imgzoom(img,title,size) {
    size = size.split(':');
    w = parseInt(size[0])+50;
    h = parseInt(size[1])+50;
    if (window.screen) {
        if (screen.availWidth < w) w = screen.availWidth -50;
        if (screen.availHeight < h) w = screen.availHeight -50;
        cw = Math.floor((screen.availWidth-w)/2);
        ch = Math.floor((screen.availHeight-h)/2);
    }

    window.open('/imagezoom.php?t='+escape(title)+'&i='+img,'imgzoom'+w+'_'+h,'width='+w+',height='+h+',top='+ch+',left='+cw+',scrollbars=yes, resize=yes');
    return false;
}
function sizeinfo() {
    w = 640;
    h = 400;
    if (window.screen) {
        cw = Math.floor((screen.availWidth-w)/2);
        ch = Math.floor((screen.availHeight-h)/2);
    }

window.open('/sizeinfo.php','sizeinfo','width='+w+',height='+h+',top='+ch+',left='+cw+',scrollbars=yes');
    return false;
}

function cartqty(el,amt) {
    document.forms['prodform'].elements[el].value = ((parseInt(document.forms['prodform'].elements[el].value) + amt) >= 0)? parseInt(document.forms['prodform'].elements[el].value) + amt : '0';
}

function updatebasketprice(delcharge) {
    delvalue = delcharge;
    delcharge = delcharge.split(':');
    delcharge = delcharge[1];
    document.forms['prodform'].elements['deliverycharge'].value = '£'+ round_decimals((delcharge / 100),2);
    document.forms['prodform'].elements['total'].value = '£'+ round_decimals( ((parseInt(document.forms['prodform'].elements['subtotal'].value) + parseInt(delcharge)) / 100),2);
    document.forms['promoform'].elements['deliveryoption'].value = delvalue;
}


// ***********************************************************
/* This script is Copyright (c) Paul McFedries and 
Logophilia Limited (http://www.mcfedries.com/).
Permission is granted to use this script as long as 
this Copyright notice remains in place.*/

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}
// ***********************************************************
function helpmeregister() {
    w = 580;
    h = 300;
    if (window.screen) {
        cw = Math.floor((screen.availWidth-w)/2);
        ch = Math.floor((screen.availHeight-h)/2);
    }
    window.open('helpmeregister.php','helpme','width='+w+',height='+h+',top='+ch+',left='+cw+',scrollbars=yes');
    return false;
}
function helpmesignin() {
    w = 580;
    h = 300;
    if (window.screen) {
        cw = Math.floor((screen.availWidth-w)/2);
        ch = Math.floor((screen.availHeight-h)/2);
    }
    window.open('helpmesignin.php','helpme','width='+w+',height='+h+',top='+ch+',left='+cw+',scrollbars=yes');
    return false;
}
function checkeditaddress2(f) {
    var msg = '';
    if (f.elements['title'].value == '')
        msg += 'The \'title\' field must not be left blank.\r\n';
    if (f.elements['firstname'].value == '')
        msg += 'The \'first name\' field must not be left blank.\r\n';
    if (f.elements['lastname'].value == '')
        msg += 'The \'last name\' field must not be left blank.\r\n';
    if (f.elements['address1'].value == '')
        msg += 'The \'address line 1\' field must not be left blank.\r\n';
    if (f.elements['town'].value == '')
        msg += 'The \'town / city\' field must not be left blank.\r\n';
   /*if (f.elements['county'].value == '')
        msg += 'The \'county / state\' field must not be left blank.\r\n'; */
    if (f.elements['postcode'].value == '')
        msg += 'The \'postal code\' field must not be left blank.\r\n';
    if (msg != '') {
        alert(msg);
        return false;
    }
    return true;
}
function checkeditaddress(f) {
    var msg = '';
    if (f.elements['name'].value == '')
        msg += 'The \'name\' field must not be left blank.\r\n';
    if (f.elements['address1'].value == '')
        msg += 'The \'address line 1\' field must not be left blank.\r\n';
    if (f.elements['town'].value == '')
        msg += 'The \'town / city\' field must not be left blank.\r\n';
   /* if (f.elements['county'].value == '')
        msg += 'The \'county / state\' field must not be left blank.\r\n';*/
    if (f.elements['postcode'].value == '')
        msg += 'The \'postal code\' field must not be left blank.\r\n';
    if (msg != '') {
        alert(msg);
        return false;
    }
    return true;
}
function myconfirm(q) {
    return showModalDialog("/modal.php", q, "help:no; resizeable:yes; status:no; dialogWidth=350px;dialogHeight=200px");
}

function testit(initvals,frmaction) {
    var changes=false;
    for(var i=0; i<initvals.length;i++) {
        val = initvals[i].split(':');
        if (document.forms['prodform'].elements[val[0]].value != val[1])
            changes = true;
    }
    if (changes) {
        var userAnswer=myconfirm("You have made some changes. Do you wish to update your basket?");
        if (!userAnswer)
            document.forms['prodform'].reset();
    }
    document.forms['prodform'].action = frmaction;
    document.forms['prodform'].submit();
    return false;
}
function regdecline() {
    w=500;
    h=360;
    if (window.screen) {
        if (screen.availWidth < w) w = screen.availWidth -50;
        if (screen.availHeight < h) w = screen.availHeight -50;
        cw = Math.floor((screen.availWidth-w)/2);
        ch = Math.floor((screen.availHeight-h)/2);
    }

    window.open('regdecline.php','regdecline','width='+w+',height='+h+',top='+ch+',left='+cw+',scrollbars=yes, resize=yes');
    return false;
}
function showhelp(p) {
    w=500;
    h=360;
    if (window.screen) {
        if (screen.availWidth < w) w = screen.availWidth -50;
        if (screen.availHeight < h) w = screen.availHeight -50;
        cw = Math.floor((screen.availWidth-w)/2);
        ch = Math.floor((screen.availHeight-h)/2);
    }

    window.open('/help.php?p='+p,'help','width='+w+',height='+h+',top='+ch+',left='+cw+',scrollbars=yes, resize=yes');
    return false;
}

function showreviews(cat) {
    w=500;
    h=400;
    if (window.screen) {
        if (screen.availWidth < w) w = screen.availWidth -50;
        if (screen.availHeight < h) w = screen.availHeight -50;
        cw = Math.floor((screen.availWidth-w)/2);
        ch = Math.floor((screen.availHeight-h)/2);
    }

    window.open('/showreviews.php?cat='+cat,'reviews','width='+w+',height='+h+',top='+ch+',left='+cw+',scrollbars=yes, resize=yes');
    return false;
}

/* evil anti-right-clicky thing */
var leave = 1;
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");

function selectinthisWindow(form)
{
var formindex=form.thislocation.selectedIndex;
window.location=form.thislocation.options[formindex].value;
}
function hyperlinkjump(form)
{
var myindex=form.golocation.selectedIndex
location=form.golocation.options[myindex].value;
}

 menuItems = new Array();
 menuItemNum = 0;

 function addMenuItem(text, url, img){
  if(img) menuItems[menuItemNum] = new Array(text, url, img);
  else if(text) menuItems[menuItemNum] = new Array(text, url);
  else menuItems[menuItemNum] = new Array();
  menuItemNum++;
 }

 menuWidth = 230; //menu width
 menuHeight = 22; //menu height
 menuDelay = 50; //delay before menu appears
 menuSpeed = 8; //speed which menu appears (lower=faster)
 menuOffset = 2; //offset of menu from mouse pointer

 addMenuItem("© The Egyptian Cotton Store Limited.","#");

 
 if(window.navigator.appName == "Microsoft Internet Explorer" && window.navigator.appVersion.substring(window.navigator.appVersion.indexOf("MSIE") + 5, window.navigator.appVersion.indexOf("MSIE") + 8) >= 5.5)
  isIe = 1;
 else
  isIe = 0;

 if(isIe){
  menuContent = '<table id="rightMenu" width="0" height="0" cellspacing="0" cellpadding="0" style="font:menu;color:menutext;"><tr height="1"><td style="background:threedlightshadow" colspan="4"></td><td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threedlightshadow"></td><td style="background:threedhighlight" colspan="2"></td><td style="background:threedshadow"></td><td style="background:threeddarkshadow"></td></tr><tr height="10"><td style="background:threedlightshadow"></td><td style="background:threedhighlight"></td><td style="background:threedface"><table cellspacing="0" cellpadding="0" nowrap style="font:menu;color:menutext;cursor:default;">';
  for(m=0;m<menuItems.length;m++){
   if(menuItems[m][0] && menuItems[m][2])
    menuContent += '<tr height="17" onMouseOver="this.style.background=\'highlight\';this.style.color=\'highlighttext\';" onMouseOut="this.style.background=\'threedface\';this.style.color=\'menutext\';" onClick="parent.window.location.href=\'' + menuItems[m][1] + '\'"><td style="background:threedface" width="1" nowrap></td><td width="21" nowrap><img src="' + menuItems[m][2] + '"></td><td nowrap>' + menuItems[m][0] + '</td><td width="21" nowrap></td><td style="background:threedface" width="1" nowrap></td></tr>';
   else if(menuItems[m][0])
    menuContent += '<tr height="17" onMouseOver="this.style.background=\'highlight\';this.style.color=\'highlighttext\';" onMouseOut="this.style.background=\'threedface\';this.style.color=\'menutext\';" onClick="parent.window.location.href=\'' + menuItems[m][1] + '\'"><td style="background:threedface" width="1" nowrap></td><td width="21" nowrap></td><td nowrap>' + menuItems[m][0] + '</td><td width="21" nowrap></td><td style="background:threedface" width="1" nowrap></td></tr>';
   else
    menuContent += '<tr><td colspan="5" height="4"></td></tr><tr><td colspan="5"><table cellspacing="0"><tr><td width="2" height="1"></td><td width="0" height="1" style="background:threedshadow"></td><td width="2" height="1"></td></tr><tr><td width="2" height="1"></td><td width="100%" height="1" style="background:threedhighlight"></td><td width="2" height="1"></td></tr></table></td></tr><tr><td colspan="5" height="3"></td></tr>';
  }
  menuContent += '</table></td><td style="background:threedshadow"></td><td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threedlightshadow"></td><td style="background:threedhighlight"></td><td style="background:threedface"></td><td style="background:threedshadow"></td><td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threedlightshadow"></td><td style="background:threedshadow" colspan="3"></td><td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threeddarkshadow" colspan="5"></td></tr></table>';

  menuPopup = window.createPopup();
  menuPopup.document.body.innerHTML = menuContent;
 }

 function showMenu(){
  menuXPos = event.clientX + menuOffset;
  menuYPos = document.documentElement.scrollTop + event.clientY + menuOffset;

  menuXIncrement = menuWidth / menuSpeed;
  menuYIncrement = menuHeight / menuSpeed;

  menuTimer = setTimeout("openMenu(0,0)", menuDelay);

  return false;
 }
 function verifycheck(){
	 conf=confirm("Are You sure want to delete address");
	 if(conf) 
		 return true;
	 else
		 return false;
 }


 function openMenu(height, width){
  iHeight = height;
  iWidth = width;

  menuPopup.show(menuXPos, menuYPos, iWidth, iHeight, document.body);

  if(iHeight < menuHeight)
   menuTimer = setTimeout("openMenu(iHeight + menuYIncrement, iWidth + menuXIncrement)", 1);
  else
   clearTimeout(menuTimer);
 }


 if(isIe) document.oncontextmenu = showMenu;
 /* end evil anti-right-clicky thing */
