var mass_links;
//<div id="sihab_search_div1" style="display:none;visibility:hidden"> 

var host = (m = /^(.*)\?(.*)$/.exec(document.location)) ? m[1] : document.location;

search_button = checkVar('site_search_button') ? site_search_button : "Search";

search_style = checkVar('site_search_style') ? site_search_style : "<style>  input, textarea, select { border: 1px solid #CCC;	border-top-color: #999; 	border-left-color: #999; }  .phpdigHighlight { color: #000000; background-color: #ADB5CE; font-weight: bold; }  </style>";

//caption_text = checkVar('site_caption_text') ? site_caption_text : "Search Results";

caption_text = checkVar('site_caption_text') ? site_caption_text : "Search Results";
//caption_text = caption_text + " - ";
caption_text = caption_text + " &nbsp;&nbsp;&nbsp;&nbsp; -  Powered by <a href=http://www.webirunner.com> www.webirunner.com </a> ";

caption_color = checkVar('site_caption_color') ? site_caption_color : "#ffffff";

caption_background_color = checkVar('site_caption_background_color') ? site_caption_background_color : "#4D79FF";

caption_border_color = checkVar('site_caption_border_color') ? site_caption_border_color : "#809FFF";

caption_font = checkVar('site_caption_font') ? site_caption_font : "Verdana,Arial,Helvetica";

close_text = checkVar('site_close_text') ? site_close_text : "Close";

close_color = checkVar('site_close_color') ? site_close_color : "#ffffff";

text_color = checkVar('site_text_color') ? site_text_color : "#000000";

text_size = checkVar('site_text_size') ? site_text_size : "10px";

text_font = checkVar('site_text_font') ? site_text_font : "Verdana,Arial,Helvetica";

background_color = checkVar('site_background_color') ? site_background_color : "#ffffff";

search_limit = checkVar('site_search_limit') ? site_search_limit : 4;

box_sticky = checkVar('site_box_sticky') ? site_box_sticky : 0;

box_width = checkVar('site_box_width') ? site_box_width : 200;

box_height = checkVar('site_box_height') ? site_box_height : 100;

box_mouse_position = checkVar('site_box_mouse_position') ? site_box_mouse_position : "RIGHT";
//kan vara LEFT, RIGHT, CENTER, ABOVE, BELLOW

box_offsetx = checkVar('site_box_offsetx') ? site_box_offsetx : 10;

box_offsety = checkVar('site_box_offsety') ? site_box_offsety : 10;

box_snapx = checkVar('site_box_snapx') ? site_box_snapx : 0;

box_snapy = checkVar('site_box_snapy') ? site_box_snapy : 0;

box_fixx = checkVar('site_box_fixx') ? site_box_fixx : -1;

box_fixy = checkVar('site_box_fixy') ? site_box_fixy : -1;

box_relx = checkVar('site_box_relx') ? site_box_relx : null;

box_rely = checkVar('site_box_rely') ? site_box_rely : null;

box_hauto = checkVar('site_box_hauto') ? site_box_hauto : 1;

box_vauto = checkVar('site_box_vauto') ? site_box_vauto : 1;


//search_resuls_table_borders_color = checkVar('site_search_table_borders_color') ? site_search_table_borders_color : "#338833";

//#search_div = " <div id=\"sihab_search_div1\">  <form action=\"javascript:void('0');\" onSubmit=\"doSearch();\"> <input type=text id=sihab_search_box1 class=input> <input type=submit> </form>  </div> <div id=sihab_search_result style=\"float: left; position: relative; top: 12px; left: 22px;\"></div>";
search_div = checkVar('site_search_div') ? site_search_div : "<div id=\"sihab_search_div1\">  <form action=\"javascript:void('0');\" onSubmit=\"doSearch();\" > <input type=text id=sihab_search_box1 class=input style=\"width: 90px;\"> <input type=submit value=" + search_button + "> </form>  </div> <div id=sihab_search_result style=\"z-index: 100; position: relative; top: 12px; left: 22px;\"></div>";


document.write( search_style + "\n\n" + search_div);

function checkVar(what) {
	return Boolean(typeof window[what] != 'undefined');
}

function doSearch(){
	query = encodeURIComponent(document.getElementById('sihab_search_box1').value);
	//query = urlencode(query);
	feed=importXML("t_xml_spid.php?search=" + query + "&limit=" + search_limit);

	result_count =  feed.getElementsByTagName('search_result')[0].getAttribute('value');
	mass_links = "";
	//alert(result_count);
	 for(i = 1; i <= result_count; i++){
		link = feed.getElementsByTagName('item' + i)[0].getAttribute('link');
		title = feed.getElementsByTagName('item' + i)[0].getAttribute('title');
		description = feed.getElementsByTagName('item' + i)[0].getAttribute('description');
		description = replace_all(description);
		title = replace_all(title);
		link_org  = link;
		link_new = "<a href=\"" + link_org + "\" target=\"_blank\"><b> " + title + " </b></a><br>";
		link_copy = link_new + description + "<br>" + '<a href="' + link_org + '" target="_blank">' + link_org + '</a>';
		//alert(link);
		mass_links = mass_links + link_copy + "<br><br><br>\n";
        }
	start_table = '<table border=0 width=500><tr><td style="padding:5px;background-color:' + caption_color + ';width=500px;font-family:' + text_font + ';font-size:' + text_size + '">';
	end_table = "</td></tr></table>";
	mass_links = start_table + mass_links  + end_table;
	//alert(mass_links);
	return overlib(mass_links,STICKY,box_sticky,box_width,box_height,box_mouse_position,OFFSETX,box_offsetx,OFFSETY,box_offsety,SNAPX,box_snapx,SNAPY,box_snapy,FIXX,box_fixx,FIXY,box_fixx,RELX,box_relx,RELY,box_rely,CLOSECLICK,HAUTO,box_hauto,VAUTO,box_vauto,CAPTION,caption_text,CAPCOLOR,caption_color,CAPTIONFONT,caption_font,CLOSETEXT,close_text,CLOSETITLE,close_text,CLOSECOLOR,close_color,FGCOLOR,caption_border_color,BGCOLOR,caption_background_color,TEXTCOLOR,text_color,TEXTSIZE,text_size);

	result_box = document.getElementById('sihab_search_result');
	result_box.innerHTML = mass_links;
	//alert(result_box.innerHTML);
}


function replace_all(description){

	for(ib=0;ib<50;ib++){
		description =  description.replace("&gt;",">");
	 }

	for(ib=0;ib<50;ib++){
		description =  description.replace("&amp;","&");
	 }

	for(ib=0;ib<50;ib++){
		description =  description.replace("&lt;","<");
	}

	for(ib=0;ib<50;ib++){
		description =  description.replace("&quot;","\"");
		}

return description;
}


var xmlFeed=false;
var gecko= (document.implementation && document.implementation.createDocument) ? true:false;
var ie= (window.ActiveXObject && document.all) ? true:false;

// FIX MIMETYPES/DOCUMENT HEADERS FOR GECKO
// By Vladdy from CodingForums.com
function fixXmlMimeType(filename)
{
oxmlhttp = null;
try {
oxmlhttp = new XMLHttpRequest();
oxmlhttp.overrideMimeType("text/xml");
}
catch(e) {
try {
oxmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e) {
return null;
}
}

if (!oxmlhttp) return null;

try {
oxmlhttp.open("GET", filename, false);
oxmlhttp.send(null);
}
catch(e) {
return null;
}

return oxmlhttp.responseXML;
}


// IMPORT XML DOCUMENT
// Code from the Public Domain
function importXML(FeedParserRSSFile)
{
// For Gecko Browsers
if (gecko)
{
xmlFeed = document.implementation.createDocument("", "", null);
xmlFeed.async=false;
xmlFeed = fixXmlMimeType(FeedParserRSSFile);
}

// For IE/Win
else if (ie)
{
xmlFeed = new ActiveXObject("Microsoft.XMLDOM");
xmlFeed.async=false;
xmlFeed.load(FeedParserRSSFile);
}

// If a browser doesn't support this, do nothing.
else return false;

// If it's all good, return the object.
if (typeof xmlFeed != "undefined") return xmlFeed;
else return false;
}
