// product_detail image swap
function updateImg(imgName,bigimg,smallimg,imgnum)
{
    document[imgName].src=smallimg;
    document.getElementById("imgBigInp").value=bigimg;
    createcookie('enlarged',bigimg + '+=' + imgnum,1);
    return false;
}

function updateImgNum(num)
{
    updateCurrMainIdx(num);
    var arrItem = mainImagesArray[currMainIdx];
    var big = arrItem[0];
    var small = arrItem[1];
    updateImg('imgBig',big,small);
    var cookienum = parseFloat(num)+1;
    var cookieset = document.getElementById("imgBigInp").value+"+="+cookienum;
    createcookie('enlarged',cookieset,1);
    return false;
}

function prevImage()
{
	updateImgNum(currMainIdx-1);
}
function nextImage()
{
	updateImgNum(currMainIdx+1);
}


 function updateCurrMainIdx(newidx) 
 { 
      document.getElementById('nummainelt'+currMainIdx).className=''; 
      currMainIdx = newidx; 
      if(currMainIdx < 0) 
      { 
           currMainIdx = 0; 
      } 
      if(currMainIdx >mainImagesArray.length-1) 
      { 
           currMainIdx = 0; 
      } 
      document.getElementById('nummainelt'+currMainIdx).className='on'; 
 }
// check quantity of products is > 0
function checkQty(formname,pre,post)
{
    var num;
    var obj;

    var hasEnough = false;

    obj = document.forms[formname].elements[pre];
    if(obj == null)
    {
       alert("Please select at least one product");
       return false;
    }
    num = parseInt(obj.value);
    if(!isNaN(num) && num > 0)
    {
       hasEnough = true;
    }

    if(hasEnough == false)
    {
        alert("Please select at least one product");
    }
    return hasEnough;
}

function checkProducts(colorSel,sizeSel)
{
    if(colorSel[colorSel.selectedIndex].value == null ||
            colorSel[colorSel.selectedIndex].value == '' ||
            colorSel[colorSel.selectedIndex].value == 'Choose a Color')
    {
        alert("Please select a color");
        return false;
    }
    if(sizeSel[sizeSel.selectedIndex].value == null ||
            sizeSel[sizeSel.selectedIndex].value == '' ||
            sizeSel[sizeSel.selectedIndex].value == 'Choose a Size')
    {
        alert("Please select a size");
        return false;
    }
    return true;
}

// payment options
function btnOnclick () {
	var optionsForm = window.document.paymentOptionsForm;
	var count = optionsForm.numOfClicks.value;
	optionsForm.numOfClicks.value = parseInt(count) + 1;
	if (optionsForm.numOfClicks.value == 1)
		optionsForm.submit();
	return;
}
function showfriends(xxx) {
var thediv = document.getElementById('thefriends');
if (thediv.style.display == 'none') {
thediv.style.display='block';
}
else {
thediv.style.display='none';
}
if(xxx == 'openit') {
thediv.style.display='block';	
}
}
function newwindow(thesrc,width,height) {
window.open(thesrc,'mywindow','width='+width+',height='+height+',scrollbars=yes,resizable=no,top=0,toolbar=0');
}
function optsubmit(theaction) {
if(theaction == 'product-send.do') {
totalz = 0;
temp = 'friend';
for(f=1; f<5; f++){
if(document.getElementById(temp + f).value == '') {
totalz = totalz + 1;	
}
}
if(totalz == 4) {
alert('You must fill out at least one email field');
}
else {
var frm = document.getElementById('submform');
frm.action = theaction;
frm.submit();
}
}
else {
var frm = document.getElementById('submform');
frm.action = theaction;
frm.submit();
}
}

function loadcookie(thecookie,thecolor,theimage,towhere) {
if (getcookie(thecookie) == thecolor) {
changeimg(theimage,'colors',towhere);
createcookie(thecookie,'',-1);
}
}

function changeimg(theone,thetype,towhere) {
if(thetype == 'alts') {
var arrItem = mainImagesArray[theone];
var big = arrItem[1];
document.imgBig.src= big;
}
else {
processSelectSizes(colorsform[theone]);
document.imgBig.src=thepath +  colorimgs[theone];
}
createcookie('enlarged',towhere,1);
}
function newwindow(thesrc,width,height) {
window.open(thesrc,'mywindow','width='+width+',height='+height+',scrollbars=yes,resizable=no,top=0,toolbar=0');
}
