/* Strip whitespace from the beginning and end of a string Input : a string */ function trim(str) { return str.replace(/^\s+|\s+$/g,''); } /* Add items to shopping cart */ function getObject(id) { return document.getElementById(id); return (ns4) ? document.layers[id] : (ie4) ? document.all[id] : (ie5||ns5) ? document.getElementById(id) : null; } function addToCart(ID) { // alert(ID); //var qtyjs=eval('document.productlist.qty'+pd_id+'.value'); //var quatity=eval('document.productlist.qty'+pd_id+'.value'); //var text='./include/cart/Cart.php?action=add&p='+pd_id+'&qty='+quatity+''; //var text='?mwd=Cart&action=add&p='+pd_id+'&qty='+quatity; var error=''; var pdcr='N/A'; var pdsz='N/A' var qty=getObject('qty'+ID).value; if(getObject('cboColor_'+ID)){ pdcr=getObject('cboColor_'+ID).value; if(pdcr==''){ error +='Select product color. \n'; } } if(getObject('cboSize_'+ID)){ pdsz=getObject('cboSize_'+ID).value; if(pdsz==''){ error +='Select product size. \n'; } } if(qty=='' || qty==0){ qty=1; } if(error!=''){ msg='Please select the following field(s): \n'+error; alert(msg); return false; } else{ window.location.href='?mwd=Cart&action=add&p='+ID+'&qty='+qty+'&size='+pdsz+'&color='+pdcr; } } /* Add items to shopping cart */ function deleteProduct(cartId) { if(confirm('Are you sure to delete this item form shopping cart?')){ window.location.href='?mwd=Cart&action=delete&cid='+cartId; } } /* Make sure that textBox only contain number */ function checkNumber(textBox) { while (textBox.value.length > 0 && isNaN(textBox.value)) { textBox.value = textBox.value.substring(0, textBox.value.length - 1) } textBox.value = trim(textBox.value); /* if (textBox.value.length == 0) { textBox.value = 0; } else { textBox.value = parseInt(textBox.value); }*/ } /* Check if a form element is empty. If it is display an alert box and focus on the element */ function isEmpty(formElement, message) { formElement.value = trim(formElement.value); _isEmpty = false; if (formElement.value == '') { _isEmpty = true; alert(message); formElement.focus(); } return _isEmpty; } /* Set one value in combo box as the selected value */ function setSelect(listElement, listValue) { for (i=0; i < listElement.options.length; i++) { if (listElement.options[i].value == listValue) { listElement.selectedIndex = i; } } } function confirmEmtyCart(){ if (confirm('You want to remove all items form shopping cart?')) return true; } function cancelOrder(){ if (confirm('Do you want really to cancel this order,\nand remove all items from shopping cart?')) window.location.href='?mwd=Cart&action=cancelOrder'; } function searchProduct(){ keyword=document.getElementById("search").value; if(keyword=="" || keyword=="Search..."){ alert("Please enter keyword"); return false; } else if(keyword.length<4){ alert("Keyword too short"); return false; }else{ return window.location.href='?mwd=Search&q='+keyword; } } /* Open pouUp window and center it */ function openWindow(url,name,width,height){ //var width = 720; //var height = 600; var left = (screen.width - width)/2; var top = (screen.height - height)/2; var params = 'width='+width+', height='+height; params += ', top='+top+', left='+left; params += ', directories=no'; params += ', location=no'; params += ', menubar=no'; params += ', resizable=no'; params += ', scrollbars=yes'; params += ', status=no'; params += ', toolbar=no'; newwin=window.open(url,name, params); if (window.focus) {newwin.focus()} //return false; }