// INICIALIZACION DE VARIABLES //

var curleft = 0;
var curtop = 0;
var brand_count = 0;
var sq = String.fromCharCode(39); // single quote variable
var zoom_active = false;

// FUNCIONES //

function DisplayPreview(ElementID,folder,location,top_pos,left_pos,doc_folder){
	
	// aseguro que el numero del folder sea 3 digitos
	//var js_doc_folder = doc_folder;
    //while (js_doc_folder.length < 3) { js_doc_folder = "0" + js_doc_folder; };
	
	zoom_active = true;
	curr_Element = document.getElementById('doc_' + ElementID);	
	curr_Floater = document.getElementById('FloaterArea');
		
	findPos(curr_Element);
	curheight = curr_Element.offsetHeight
	curwidth = curr_Element.offsetWidth
		
	//check location
	str = window.location.href;
	mylocation = str.search(/localhost/);
	
	if( mylocation == -1 ){
		zoom_url = "http://zoom.puertoricosupplier.com/" + doc_folder + "/";		
	} else {
		zoom_url = "http://localhost/icon_uunet/big/preview_images_zoom/" + doc_folder + "/";
	}
		
	curr_Floater.innerHTML = '<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0"><TR><TD VALIGN="top"><BR><BR><BR><IMG SRC="../bsearch/images/preview_arrow.gif"></TD><TD><TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0" STYLE="{background-color: White; border:solid 2pt #990000; width:455; height:250; background-image: url(../bsearch/images/loading_bar.gif); background-repeat:no-repeat; background-position:117 35;}" ALIGN="center"><TR><TD CLASS="arial_8pt" VALIGN="top" ALIGN="center"><B>PREVIEW</B></TD></TR><TR><TD><IMG SRC="' + zoom_url + ElementID + '.jpg" BORDER="0"></TD></TR></TABLE></TD></TR></TABLE>';//
	curr_Floater.style.top = curtop - top_pos;
	curr_Floater.style.left = curleft - left_pos;
	
	curr_Floater.className = 'movable_show';
	
	curleft = 0;
	curtop = 0;
	
	// Documento acceso a Quick View
	GetURL('../search/tag_search_quickview.cfm?uai=3&product_id=' + ElementID + '&folder=' + folder,ElementID,'GET','','save');		
}

function QuickView(ElementID,folder,location){
	
	if( location == 'localhost' ){
		preview_url = 'http://localhost/icon_uunet/big/preview_images/';
	} else {
		preview_url = 'http://www.puertoricosupplier.com/preview/';
	}
	
	document.getElementById('doc_' + ElementID + '_quick').innerHTML = '<IMG SRC="' + preview_url + ElementID + '.gif" BORDER="1" STYLE="border-top:solid 1pt black;border-color:black" ALIGN="left" HSPACE="10">';
	document.getElementById('doc_' + ElementID + '_quick_img').innerHTML = '';		
	DisplayOff('FloaterArea');	
	
	// Documento acceso a Quick View
	if ( folder != 'auto' ){
		GetURL('../search/tag_search_quickview.cfm?uai=4&product_id=' + ElementID + '&folder=' + folder,ElementID,'GET','','save');
	}
}

function QuickView2(ElementID,folder,location,doc_folder){
	
	if( location == 'localhost' ){
		preview_url = 'http://localhost/icon_uunet/big/preview_images/' + doc_folder + "/";
	} else {
		preview_url = 'http://preview.puertoricosupplier.com/' + doc_folder + "/";
	}
	
	document.getElementById('doc_' + ElementID + '_quick').innerHTML = '<IMG SRC="' + preview_url + ElementID + '.gif" BORDER="1" STYLE="border-top:solid 1pt black;border-color:black" ALIGN="left" HSPACE="10" ONMOUSEOVER=DisplayPreview(' + sq + ElementID + sq + ',' + sq + location +'&pagenum=0' + sq + ',' + sq + sq + ',50,70,"' + doc_folder + '"); ONMOUSEOUT="DisplayOff2(' + sq + 'FloaterArea' + sq + ',' + sq + location + sq + ');">'; 
	document.getElementById('doc_' + ElementID + '_quick_img').innerHTML = '';		
	DisplayOff('FloaterArea');	
	
	// Documento acceso a Quick View
	if ( folder != 'auto' ){
		GetURL('../search/tag_search_quickview.cfm?uai=4&product_id=' + ElementID + '&folder=' + folder,ElementID,'GET','','save');
	}
}

function FilterSearch(type,url,item_id,item_count,item_title,color){
		
	scroll(0,0);
	document.getElementById('result_summary').innerHTML = '<CENTER><FONT COLOR="036A0B" CLASS="arial_font-13pt"><IMG SRC="../images/search_loading.gif" WIDTH="16" HEIGHT="16" BORDER="0" ALIGN="absmiddle">&nbsp; <B>Searching...</B></FONT></CENTER>'
	
	if ( type != 'none' ){
	
		for (var x = 0; x <= item_count; x++){
			document.getElementById(type + x + 'a').bgColor = '';
			document.getElementById(type + x + 'b').bgColor = '';
		};
		
		document.getElementById(type + item_id + 'a').bgColor = color;
		document.getElementById(type + item_id + 'b').bgColor = color;
		if ( type == 'brand' ){ brand_count = item_count; };	
	};
	
	GetURL(url,'area_search_result','GET','','display');
}

function ToolTip_Submit(tip_word){
	document.getElementById('search_keyword').value = tip_word;
	DisplayOff('FloaterArea');
	search_form.submit();
}


// FUNCIONES RE-USABLES //

function DisplayOff(ElementId){

	curr_Floater = document.getElementById(ElementId);
	curr_Floater.innerHTML = '';
	curr_Floater.className = 'movable_hide';
}

function DisplayOff2(ElementId){
	
	zoom_active = false;	
	setTimeout('if (zoom_active == false ){ DisplayOff("' + ElementId + '") }',2000);
}

//

function findPos(obj){
	
	if (obj.offsetParent)
	{			
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
	{
		curtop += obj.x;
		curleft += obj.x;
	}
}

function CheckValues(curr_value){
	
	if (curr_value.length == 0){ return false; }
	else{
		curr_value = curr_value.replace(/^\s+/,'').replace(/\s+$/,'');
		if (curr_value.length == 0){ return false; } else { return true; };
	};
	
};

// Funcion para hacer Loading dinamico de un script
function staticLoadScript(url){	
	var e = document.createElement("script");
	e.src = "scripts/" + url;	
	e.type="text/javascript";
	document.getElementsByTagName("head")[0].appendChild(e); 	
}

