var server_path = './fry/index_trigger.php?&' ;
var option = 'catalog';

function searchByNumber(oArgs){
	code_product = getElement("searchbynumber");
	if(code_product.value.length>=4)
		return {
			source: server_path+'option='+option+'&task=findWord&word='+escape(oArgs.keyword)+'&code_product='+code_product.value,
			sourceType: 'json/url'
		};
}

function resultFind(oTip){
	return oTip.code;
}


function startCatalog(id){
	querystring = "showOn=debbuger&option="+option+"&task=startCatalog&id="+id;
	makeAjaxRequest(server_path, querystring, "showAjaxResponseCatalog");
}


function showAjaxResponseCatalog() {
	if (_request_object.readyState == 4){  
		var showOn = _request_object.getResponseHeader("showOn");
		eval('txt_result = '+_request_object.responseText);
		//var submenu = getElement('submenu');				submenu.innerHTML  = subMenu(txt_result.category_details.id);
		//var category_name = getElement('category_name');
        //category_name.innerHTML  = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="86" height="473"><param name="movie" value="'+txt_result.category_details.image+'" /><param name="quality" value="high" /><embed src="'+txt_result.category_details.image+'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="86" height="473"></embed></object>';
		var container = getElement("img_container");		container.src = txt_result.product_details.container;
		var stainfresh = getElement("img_stainfresh");		stainfresh.src = txt_result.product_details.stainfresh;
		var product_name = getElement("productname");		product_name.innerHTML = txt_result.product_details.name;	
		var select_categories = getElement('category');
		generateSelect(select_categories, txt_result.categories, txt_result.category_details.id);
		generateThumbnail(txt_result.product_list, txt_result.category_details.id);
		generatePaging(txt_result.product_list);
		setTimeout("productApply('"+txt_result.product_details.productapply+"', '"+txt_result.category_details.id+"');",2000);
		//productApply(txt_result.product_details.productapply, txt_result.category_details.id);
		/**div = document.getElementById(showOn);div.innerHTML = _request_object.responseText;/**/
	}
}

/**************************************************************************************************************************************/
/**************************************************************************************************************************************/
function thisMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

function productApply(image, id_category) {
	if((id_category>=1 && id_category<=29) || (id_category>=35 && id_category<=42) || id_category==51 || id_category==54 || id_category==55 || id_category==58){type_object='manos_mc'}
	else if((id_category>=30 && id_category<=34) || (id_category>=43 && id_category<=50) || id_category==59){type_object='labios_mc'}
	else if(id_category==52){type_object='labios_mc'}
	else if(id_category==53){type_object='exhibidores_mc'}
	thisMovie("productapply").changeImage(image, type_object);
}
/**************************************************************************************************************************************/
/**************************************************************************************************************************************/


function generateSelect(obj_select, categories_json, id_category){
	cleanOptionsSelect(obj_select);
	obj_select.options[0] = new Option('', '');
	for (i=0; i<categories_json.length; i++){
		obj_select.options[i+1] = new Option(categories_json[i].name, categories_json[i].frid);
		if (id_category==categories_json[i].frid){
			obj_select.options[i+1].selected=(id_category)?true:false;
		}
	}
	
}

function cleanOptionsSelect(obj_select){
	while (obj_select.options.length > 0){
		obj_select.options[0]=null;
	}
}

function generatePaging(product_list){
	div_paging = getElement('paging');
	pages = Math.ceil(product_list.length / 15);
	if (pages >1){
		temp = '<table border="0" cellspacing="0" cellpadding="3" align="center"><tr valing="middle"><td><a href="javascript:goArrow(\'-\')" class="rollover_go_back">Go back one page</a></td>'; 
		for(i=1; i<=pages; i++){
			temp += '<th><a href="javascript:displayPage(\''+i+'\')" class="main_menu">'+i+'</a></th>';
		}
		temp += '<td><a href="javascript:goArrow(\'+\')" class="rollover_go_forward">Go forward one page</a></td></tr></table>';
		div_paging.innerHTML =  temp;
	}
	else{
		div_paging.innerHTML = '';
		
	}
}

function generateThumbnail(product_list){
		pages = Math.ceil(product_list.length / 15);
		document.getElementById("total_pages").value = pages;
		var content = '';
		for(page=1; page<=pages; page++){
			content += '<div id="page_'+page+'" style="display:none;">';
				content +='<table border="0" cellspacing="0" cellpadding="3" align="center">';
				var num_cells = 0;
				start = (page*15) -15;
				end = page*15;
				for(i=start; i<end; i++){/**/
					num_cells++;
					if(num_cells==1){content+='<tr align="center" valign="top" height="94">';}
					try{content +='<td width="71"><a href="javascript:detailsProduct('+product_list[i].frid+');" class="thumbnail_txt"><img src="'+product_list[i].staindry+'" border="0" width="44" height="44"><br><br>'+product_list[i].name+'</a></td>';}
					catch(e){content +='<td width="71">&nbsp;</td>';}
					if(num_cells==5){num_cells=0;content+='</tr>';}
				}
				content +='</table>';			
			content += '</div>';
		}
		var thumbnail = getElement('thumbnail');
		thumbnail.innerHTML = content;
		document.getElementById('page_1').style.display='block';
}

function goArrow(operator){
	eval('var current_page = '+document.getElementById("current_page").value+operator+'1;');
	var last_page = document.getElementById("total_pages").value * 1;
	current_page=(current_page<1)?1:current_page;
	current_page=(current_page>last_page)?last_page:current_page;
	
	displayPage(current_page);
}

function displayPage(number){
	pages = getElement('total_pages');
	pages = pages.value *1;
	for(i=1;i<=pages;i++){
		//alert(document.getElementById('page_'+i).style.display);
		if (document.getElementById('page_'+i).style.display == 'block'){
			Zapatec.Effects.hide('page_'+i, 3, 'fade');
			setTimeout('displayPageBlock('+number+')', 1650);
			//document.getElementById('page_'+i).style.display='none';
		}
	}
}

function displayPageBlock(number){
	document.getElementById('page_'+number).style.display='block';
	document.getElementById('current_page').value=number;	
}

function detailsProduct(id){
	querystring = "showOn=debbuger&option="+option+"&task=container_stainfresh&id="+id;
	makeAjaxRequest(server_path, querystring, "showAjaxResponseDetailsProduct");
}

function detailsProductCode(code){
	querystring = "showOn=debbuger&option="+option+"&task=container_stainfresh_code&code="+code;
	makeAjaxRequest(server_path, querystring, "showAjaxResponseDetailsProduct");
}

function showAjaxResponseDetailsProduct(){
	if (_request_object.readyState == 4){
		var showOn = _request_object.getResponseHeader("showOn");
		eval('txt_result = '+_request_object.responseText);
		if (typeof txt_result=='object'){
			var container = getElement("img_container");		container.src = txt_result.container;
			var stainfresh = getElement("img_stainfresh");		stainfresh.src = txt_result.stainfresh;
			product_name = getElement("productname");
			product_name.innerHTML = txt_result.name;
			try{productApply(txt_result.productapply, txt_result.id);}catch(e){}
		}
		/**
		div = document.getElementById(showOn);
		div.innerHTML = _request_object.responseText;
		/**/
	}//	stainfresh
}



function subMenu(frid_parent){
	/**/
	var submenu='';
	if((frid_parent>=1 && frid_parent<=29) || frid_parent==54){submenu='<table border="0" cellspacing="0" cellpadding="2"><tr><td align="center"><a href="./aboutcolorclub.html" class="rollover_colorclub_about">About Color Club</a></td><td align="center"><a href="./catalog.php?id=1" class="rollover_colorclub_shadecollection">Shade Collection</a></td><td align="center"><a href="./colordisplay.html" class="rollover_colorclub_displays">Displays</a></td><td align="center"><a href="./collectionmenu.html" class="rollover_colorclub_seasonalcollection">Seasonal Collection</a></td></tr></table>';}
	else if(frid_parent>=30 && frid_parent<=50){submenu='<table border="0" cellspacing="0" cellpadding="2"><tr><td align="center"><a href="./aboutartclub.html" class="rollover_artclub_about">About Art Club</a></td><td align="center"><a href="./catalog.php?id=30" class="rollover_colorclub_shadecollection">Shade Collection</a></td><td align="center"><a href="./displayartclub.html" class="rollover_colorclub_displays">Displays</a></td><td align="center"><a href="./collectionart.html" class="rollover_colorclub_seasonalcollection">Seasonal Collection</a></td><td align="center"><a href="./nailartdesings.html" class="rollover_colorclub_nailartdesings">Nail Art Desings</a></td></tr></table>';}
	else if(frid_parent==51){submenu='<table border="0" cellspacing="0" cellpadding="2"><tr><td align="center"><a href="./aboutcolorclub.html" class="rollover_clubcare_about">About Treatments</a></td><td align="center"><a href="./catalog.php?id=51" class="rollover_treatments_shadecollection">Catalog</a></td></tr></table>';}
	else if(frid_parent==52){submenu='<table border="0" cellspacing="0" cellpadding="2"><tr><td align="center"><a href="./aboutcolorclub.html" class="rollover_lipgloss_about">About Lip Gloss</a></td><td align="center"><a href="./catalog.php?id=52" class="rollover_colorclub_shadecollection">Shade Collection</a></td></tr></table>';}
	else{submenu='';}
	/**/
	return submenu;
}








































































/**
function generateThumbnailNetscape(product_list){
	var thumbnail = getElement("thumbnail");											// INSTANCIA THUMBNAIL
		var table = document.createElement("table");									// CREA TABLE
		var num_cells = 0;
		for(i=0; i<product_list.length; i++){
			num_cells++;
			if(num_cells==1){
				var row = document.createElement("tr");										// CREA TR
					row.setAttribute('align','center');										// PONE ATRIBUTO ALIGN A TR
					row.setAttribute('valign','TOP');										// PONE ATRIBUTO VALIGN A TR
			}
					var cell = document.createElement("td");									// CREA TD
					cell.setAttribute('align','center');											// PONE ATRIBUTO ALIGN A TD
						var content_cell = document.createElement('img');							// CREA IMG
						content_cell.setAttribute('src', product_list[i].staindry);						// PONE ATRIBUTO SRC A IMG
						content_cell.setAttribute('border', '0');										// PONE ATRIBUTO BORDER A IMG
						content_cell.setAttribute('width', '44');										// PONE ATRIBUTO WIDTH A IMG
						content_cell.setAttribute('height', '44');										// PONE ATRIBUTO HEIGTH A IMG
					cell.appendChild(content_cell);													// AGREGA IMG A TD
						content_cell = document.createElement('br');								// CREA BR
					cell.appendChild(content_cell);													// AGREGA BR A TD
						content_cell = document.createTextNode(product_list[i].name);				// CREA NOMBRE PRODUCTO
					cell.appendChild(content_cell);													// AGREGA NOMBRE A TD
				row.appendChild(cell);															// AGREGA TD A TR
			table.appendChild(row);															// AGREGA TR A TABLE
			num_cells = (num_cells==5)?0:num_cells;
		}
	thumbnail.appendChild(table);														//AGREGA TABLE A THUMBNAIL
}
/**/
