function openPopUpWindow(url) {
window.open(url,'Window', 'width=350,height=510,resizable=no,status=no,toolbar=no,menubar=no,location=no,scrollbars=auto')
}

    function changeSpaces(tstring) {
        nstring='';
        for (var i=0; i <= tstring.length; i++) {
            if (tstring.charAt(i)==' ') { nstring=nstring+'^';
            } else { nstring=nstring+tstring.charAt(i); }
        }
        return nstring;
    }

function checkAdvanced(adv) {
     newAdv='';advlist=0;
    for (var j=0;j<=adv.length;j++) {
            if (adv.substring(j,j+1) == '{') {
            thisadv=1;
            advstart=j+1;
        } else if (adv.substring(j,j+1) == '}') {
            advend=j;
            advPrice2=adv.substring(advstart,advend);
            advlist++; applicable=true;
            if (applicable==true) {
                newAdv = newAdv+ '{'+advFrom+'~'+advTo+'~'+advPrice+'~'+advPrice2+'}'
            }
        } else if (adv.substring(j,j+1)=='~') {
            if (thisadv== 1) advFrom=adv.substring(advstart,j);
            if (thisadv== 2) advTo=adv.substring(advstart,j);
            if (thisadv== 3) advPrice=adv.substring(advstart,j);
            if (thisadv== 4) advPrice2=adv.substring(advstart,j);
            thisadv++;advstart=j+1;
        }
    }
    if (newAdv=='') newAdv='0';
    return newAdv;
}
    function buyItem(newCode,newSKU,newItem,newPrice,newQuantity) {
        if(newItem == '-Select Size-') {
            rc = alert('Please select size.');
        } 

                index=document.cookie.indexOf('TiffanyRoseCart');
				var thisitem
                countbegin=(document.cookie.indexOf('=',index)+1);
                countend=document.cookie.indexOf(';',index);
                if(countend==-1) { countend=document.cookie.length; }
                 fulllist = document.cookie.substring(countbegin,countend);
                 amended = false;
                 newItemList=''; itemlist=0;
                 for (var i=0;i<=fulllist.length;i++) {
                     if (fulllist.substring(i,i+1) == '[') {
                         thisitem=1;
                         itemstart=i+1;
                         fullstart=i+1;
                     } else if (fulllist.substring(i,i+1) == ']') {
                         itemend=i;
                         thequantity=fulllist.substring(itemstart,itemend);
                         itemlist++;
                         if (theItem==newItem ) {
                             amended=true;
                          //   tempquantity=eval(thequantity)+eval(newQuantity);
                             tempquantity=eval(newQuantity);
                             newItemList=newItemList+'['+theCode+'|'+theSKU+'|'+theItem+'|'+thePrice+'|'+tempquantity+']';
                         } else {
                             newItemList=newItemList+'['+theCode+'|'+theSKU+'|'+theItem+'|'+thePrice+'|'+thequantity+']';
                         }
                     } else if (fulllist.substring(i,i+1)=='|') {
                         if (thisitem==1) theCode=fulllist.substring(itemstart,i);
                         if (thisitem==2) theSKU=fulllist.substring(itemstart,i);
                         if (thisitem==3) theItem=fulllist.substring(itemstart,i);
                         if (thisitem== 4) thePrice=fulllist.substring(itemstart,i);
                         thisitem++;itemstart=i+1;
                     }
                 }
                 if (amended==false) {
                     newItemList=newItemList+'['+newCode+'|'+newSKU+'|'+newItem+'|'+newPrice+'|'+newQuantity+']'; }
                 index = document.cookie.indexOf('TiffanyRoseCart');
					var expire_days = 30
					var expire_date = new Date()
					var ms_from_now = expire_days * 24 * 60 * 60 * 1000
					expire_date.setTime(expire_date.getTime() + ms_from_now)
					var expire_string = expire_date.toGMTString()
		         document.cookie='TiffanyRoseCart='+newItemList+'; expires= '+expire_string+'; path=/;'
				 top.location='/maternity/info/<? echo $ROSE_BASKET_PAGE; ?>.html';
            }
