function janela(i, W, H, S, M){
		lpos = (screen.availWidth / 2) - (W / 2);
		tpos = (screen.availHeight / 2) - (H / 2);
		window.open(i, '', 'scrollbars='+S+', statusbar=no, menubar='+M+', left='+lpos+',top='+tpos+', width='+W+', height='+H);
}
	

function addItem(nameInfo, qtyItem) {

        nameInfoVal = nameInfo.value;
        splitPos = nameInfoVal.indexOf("|");

        nameItem = nameInfoVal.substring(0,splitPos);
        priceItem = nameInfoVal.substring(splitPos+1,nameInfoVal.length);

        //if (confirm('Colocar na Lista de Imóveis:  '+nameItem+' anunciado por '+priceItem+' ?')) {
        if (confirm('Colocar na Lista de Imóveis:  '+nameItem+' ?')) {
        	index = document.cookie.indexOf("ShopCart");
        	countstart = (document.cookie.indexOf("=", index) + 1);
    		countend = document.cookie.indexOf(";", index);
            if (countend == -1) {
                countend = document.cookie.length;
        	}
        
        	document.cookie="ShopCart="+document.cookie.substring(countstart, countend)+"["+nameItem+","+priceItem+"#"+qtyItem+"]";

        }

        return true;
}

function showItems() {
                index = document.cookie.indexOf("ShopCart");
                countstart = (document.cookie.indexOf("=", index) + 1);
                countend = document.cookie.indexOf(";", index);
                if (countend == -1) {
                            countend = document.cookie.length;
                }
                fulllist = document.cookie.substring(countstart, countend);
                totprice = 0;

                document.writeln('<table class="viewimoveis" border="0" cellspacing="0" cellpadding="0">');
                document.writeln('<tr class="titulo"><td width="20%">Imóvel</td><td>Categoria</td><td width="20%">Opções</td></tr>');

                itemlist = 0;
                for (var i = 0; i <= fulllist.length; i++) {
	                	if( i % 2 )
                    		iStyle = 0;
                 		else
                   			iStyle = 1;

                        if (fulllist.substring(i,i+1) == '[') {
                                itemstart = i+1;
                        } else if (fulllist.substring(i,i+1) == ']') {
                                itemend = i;
                                thequantity = fulllist.substring(itemstart, itemend);
                                itemlist=itemlist+1;

                                document.writeln('<tr class="listbody_'+ iStyle +'"><td>'+theitem+'</td><td>'+theprice+'</td><td class="acoes"><a href="javascript:removeItem('+itemlist+')" class="exclui">Excluir</a></td></tr>');

                        } else if (fulllist.substring(i,i+1) == ',') {
                                theitem = fulllist.substring(itemstart, i);
                                itemstart = i+1;
                        } else if (fulllist.substring(i,i+1) == '#') {
                                theprice = fulllist.substring(itemstart, i);
                                itemstart = i+1;
                        }
                }

                document.writeln('</table>');

}

function showItems2() {
        index = document.cookie.indexOf("ShopCart");
        countstart = (document.cookie.indexOf("=", index) + 1);
                countend = document.cookie.indexOf(";", index);
                if (countend == -1) {
                            countend = document.cookie.length;
                }
        fulllist = document.cookie.substring(countstart, countend);
        totprice = 0;

      //  document.writeln('<form name="checkout" method="post" action="mail.php">');
        document.writeln('<table class="viewimoveis" border="0" cellspacing="0" cellpadding="0">');
        document.writeln('<tr class="titulo"><td width="20%">Imóvel</td><td>Categoria</td></tr>');

        itemlist = 0;
        for (var i = 0; i <= fulllist.length; i++) {
	            if( i % 2 )
                	iStyle = 0;
                else
                	iStyle = 1;
                   			
                if (fulllist.substring(i,i+1) == '[') {
                        itemstart = i+1;
                } else if (fulllist.substring(i,i+1) == ']') {
                        itemend = i;
                        itemlist=itemlist+1;

                        document.writeln('<tr class="listbody_'+ iStyle +'"><td>'+theitem+'</td><td>'+theprice+'</td></tr>');
                        document.writeln('<input type="hidden" name="item[]" value="'+theitem+'" size="40">');

                } else if (fulllist.substring(i,i+1) == ',') {
                        theitem = fulllist.substring(itemstart, i);
                        itemstart = i+1;
                } else if (fulllist.substring(i,i+1) == '#') {
                        theprice = fulllist.substring(itemstart, i);
                        itemstart = i+1;
                }
        }

        document.writeln('</table>');

}
        function removeItem(itemno) {
                newItemList = null;
                itemlist = 0;
                for (var i = 0; i <= fulllist.length; i++) {
                        if (fulllist.substring(i,i+1) == '[') {
                                itemstart = i+1;
                        } else if (fulllist.substring(i,i+1) == ']') {
                                itemend = i;
                                theitem = fulllist.substring(itemstart, itemend);
                                itemlist=itemlist+1;
                                if (itemlist != itemno) {
                                        newItemList = newItemList+'['+fulllist.substring(itemstart, itemend)+']';
                                }
                        }
                }
                index = document.cookie.indexOf("ShopCart");
                document.cookie="ShopCart="+newItemList;
                document.location.href = "view.php";
        }

        function clearBasket() {
                if (confirm('Tem certeza que deseja remover todos os imóveis da lista?')) {
                        index = document.cookie.indexOf("ShopCart");
                        document.cookie="ShopCart=.";
                }
        }

        function moreBasket() {
	          //  history.go(-1);
        }

function submitForm(theForm,theSelect) {
        var theOption = theSelect[theSelect.selectedIndex].value;
        theForm.submit();
}

function mClk(src) {
if(event.srcElement.tagName=='TD'){
src.children.tags('A')[0].click();}
}

function mClk2(src) {
if(src.tagName=='A'){
src.click();}
}


