/****************************************************/
/* Fun??o que seta os ids na tela de proc_unico     */
/****************************************************/
function setids(atag){
	
	var ct = 0;
	var txt = atag.href;
	if(document.c == null){
		return ct;
	}

	var a = document.c.elements;
	var i;
	var p = new RegExp("(.*[?&])ids=([^&]*)(.*)","");
	var m = p.exec(txt);
	var prelk;
	var poslk;
	var lk;
	var x;
	var h = new Array;
	var arr = new Array;
	if((m != null)||(m.length != 4)){
		x = "";
		prelk = txt;
		poslk = "";
		if(prelk.indexOf("?") < 0)
			lk = "?ids=";
		else
			lk = "&ids=";
	} else{
		x = m[2];
		prelk = m[1];
		poslk = m[3];
		lk = "ids=";
		arr = x.split("%2C");

		for(i = 0; i < arr.length; i++)
			if(arr[i])
				h["I"+arr[i]] = arr[i];
	}

	for( i = 0; i < a.length; i++){
		if((typeof(a[i].type)!="undefined")&&(a[i].type=="checkbox")){
			if (a[i].checked)
				h["I"+a[i].value] = a[i].value;
			else
				h["I"+a[i].value] = null;
		}
	}

	for(var hh in h){
		if((h[hh] != null) && h[hh]){
			++ct;
			lk+= h[hh]+',';
		}
	}

	atag.href = prelk + lk + poslk;

	
	return ct;

}

/*************************************************************/
/* function setformids(txt)  */
/**************************************************************/

function setformids(txt){
	if(document.c == null)
		return '';

	var a = document.c.elements;
	var i;
	var lk;
	var x;
	var h = new Array;
	var arr = new Array;

	x = txt;
	lk = "";
	arr = x.split(",");
	for(i=0; i<arr.length; i++)
		if(arr[i])
			h["I"+arr[i]]=arr[i];

	for(i=0; i<a.length; i++){
		if((typeof(a[i].type)!="undefined")&&(a[i].type=="checkbox")){
			if(a[i].checked)
				h["I"+a[i].value] = a[i].value;
			else h["I"+a[i].value] = null;
		}
	}

	for(var hh in h)
		if((h[hh] != null) && h[hh])
			lk+= h[hh]+',';

	return lk;
}

/*************************************************************/
/* function lgpos(atag,pos)  */
/**************************************************************/

function lgpos(atag,pos){
	var txt = atag.href;
	var sep="&";

	if(txt.indexOf("?")<0)
		sep="?";
		atag.href=txt+sep+"pos="+pos;
}


/*************************************************************/
/* Verifica se existe algum produto selecionado         */
/**************************************************************/
function prodSelecionado(){

	if(document.c == null)
		return '';

	var a = document.c.elements;
	var i;

	for(i=0; i < a.length; i++){
		if((typeof(a[i].type)!="undefined")&&(a[i].type=="checkbox")){
			if(a[i].checked)
				return true;
		}
	}

	return false;
}


/*************************************************************/
/* Fun??o que chama a tela de compara??o caso exista         */
/* algum id setado na proc_unico, ou uma popup de explica??o */
/**************************************************************/
function popCompare(pURL){

	if(!setids(pURL)) {
		window.open('http://www.buscape.com.br/pop_compare.htm','pop','top=10,width=548,height=296,left=10,scrollbars=0,statusbar=0,resizable=0');
		return false;
	} else {
		return true;
	}

}

/*************************************************************/
/* Indica produto a amigo  */
/**************************************************************/

function sendFriend(pURL){

	window.open(this.href,'comparacao_email','width=300,height=390,toolbars=no,scrollbars=no,menubar=no,statusbar=no');
	return false;

}

/*************************************************************/
/* Mostra os Campos de Refino  */
/**************************************************************/

function expandrefino(){
	ref = document.getElementById('refinojs');
	tit = document.getElementById('titulojs');

	if(ref.style.display=='none'){
		ref.style.display='inline';
		tit.style.display='none';
	} else {
		ref.style.display='none';
		tit.style.display='inline';
	}
}

/*************************************************************/
/* Varifica se ? necess?rio mostrar o div de Refino, no Onload  */
/***********************************************************/

function temRefino(){

	if (document.f.flagonline[0].checked ||
		document.f.esel.checked ||
		document.f.estado.value != '0' ||
		document.f.formapgmto[0].checked ||
		document.f.formapgmto[1].checked ||
		document.f.formapgmto[2].checked ||
		document.f.formapgmto[3].checked ||
		document.f.formapgmto[4].checked){

		expandrefino();
	}

}

/*************************************************************/
/* Fun??o para mostrar os avisos na tela  */
/***********************************************************/

function expandIt(item){
	var whichEl;

	if(navigator.appName == 'Microsoft Internet Explorer' || navigator.appVersion >= 4.0)
		whichEl = document.all(item);
	else
		whichEl = document.getElementById(item);

	whichEl.style.display = (whichEl.style.display == "none") ? "" : "none";
}

/*************************************************************/
/* Abre Pop-up  */
/***********************************************************/

function open_PopUp(pop){
	window.open(pop.href,"_blank","width=410,height=444,toolbars=no,scrollbars=no,menubar=no,statusbar=no");
}

/*************************************************************/
/* Abre Pop-up  */
/***********************************************************/

function envia_amigo(page){
	pag = page + escape(location.href);
	window.open(pag,"_blank","width=300,height=390,toolbars=no,scrollbars=no,menubar=no,statusbar=no");
}

