﻿// iSearch v1.2

function iSearch(){
	
	this.targeturl = '';
	this.responseText = '';
	this.timeOut = 32;
	
	this.doSearch = function(obj){
		//target hack
		this.targeturl='http://isearch.qhmed.com/';
		var formstr = compform(obj);
		ajax(this.targeturl,formstr,'get','responseObj="isearch"');
		//ajax(this.targeturl,formstr,'get')
		
		this.responseText = '搜索中...';
		document.getElementById(obj).innerHTML = this.responseText;
		this.OTtimer(obj);
	}
	
	this.UpDate = function(obj){
		var objform = document.forms[obj];
		objform.isquick.value = 0;
		objform.special.value = 'update';
		this.doSearch(obj);
		
		this.responseText = '数据更新中...';
		document.getElementById(obj).innerHTML = this.responseText;
		
		this.OTtimer(obj);
	}
	
	
	this.OTtimer = function(obj){
			//setTimeout('iSearch.OTcheck(\''+obj+'\')',this.timeOut*1000);
	}
	
	this.OTcheck = function(obj){
		
		var searchObj = document.getElementById(obj);
		if (searchObj.innerHTML==this.responseText){
			searchObj.innerHTML = '服务器无响应,<a id="result" style="cursor:hand;text-decoration: underline;" onclick="iSearch.loadform(\''+obj+'\')">返回</a>';	
			}
	}
	
	this.Fill = function(keyword){
		document.getElementById('isearch_keyword').value = keyword;
	}
	
	this.loadform = function(obj){
			
		var argv = this.loadform.arguments;
		var argc = this.loadform.arguments.length;
		var keyword = (1<argc)? argv[1]:null;
		var stype = (2<argc)?argv[2]:null;
		var isquick = (3<argc)?argv[3]:null;
		var style = (4<argc)?argv[4]:null;
		var special = (5<argc)?argv[5]:null;
		
		var form = '';

		
		var hotkeyword = '感冒,止咳,祛痰,颗粒,降糖,降压,补血,风湿,鼻炎,脚气,消炎,皮肤,关节,神经,肿瘤,泌尿,痔疮,洗液,妇科,儿科,眼科,骨科,滴眼,口服,颈椎,前列,糖尿,心脑,解热,清热,病毒,注射,头孢,含片,贴剂,胃,肝,栓,膏';
		var tempkeyword = hotkeyword.split(',')
		var tempkeywordstr = '';
		for (var i=0;i<tempkeyword.length;i++){
			tempkeywordstr += '<a onclick="quickSearch(this.innerHTML)" title="搜索与'+tempkeyword[i]+'相关的信息">'+tempkeyword[i]+'</a> ';
		}

		switch(style){
			default:
				form += '<form name="'+obj+'" onSubmit="iSearch.doSearch(\''+obj+'\');return false;">';
				form += '<input id="isearch_keyword" name="keyword" type="text" style="width:120px" onfocus="this.select()" title="多个关键词请用空格分隔" /> ';
				form += '<select id="isearch_stype" name="stype"><option value="investment">招商</option><option value="agent">代理</option></select><br />';
				form += '<label for="isearch_isquick" title="从缓存中搜索数据,无须等待,极速体验.">快速<input id="isearch_isquick" name="isquick" type="checkbox" value="1" /></label>';
				form += '<input type="hidden" name="obj" value="'+obj+'" />';
				form += '<input type="hidden" name="special" value="'+special+'" />';
				form += '<input type="button" value=" 搜索 " class="button" onClick="iSearch.doSearch(\''+obj+'\')" />';
				form += '</form>';
				form += tempkeywordstr;				
				break;
			
			case 'main':
				form += '<form name="'+obj+'" id="search" onSubmit="iSearch.doSearch(\''+obj+'\');return false;"><font color=ff0000>信息搜索</font>';
				form += ' 关键词：<input id="isearch_keyword" name="keyword" type="text" onClick="this.select()" style="width:180px"  title="多个关键词请用空格分隔">';
				form += ' 分类：<input id="isearch_stype" name="stype" type="radio" value="investment" checked>招商<input name="stype" type="radio" value="agent">代理</option></select>';
				form += ' 快速：<input id="isearch_isquick" name="isquick" type="checkbox" value="1"> ';
				form += '<input type="hidden" name="obj" value="'+obj+'"><input type="hidden" name="style" value="main">';
				form += '<input type="hidden" name="special" value="'+special+'">';
				form += '<input type="button" value=" 信息搜索 " class="button" onClick="iSearch.doSearch(\''+obj+'\')">';
				//form += '<iframe id="baiduframe" frameborder="0"  marginheight="0" scrolling="no" width="150" height="26" src="http://unstat.baidu.com/bdun.bsc?tn=daqianyiyao&csid=102&rkcs=11&bgcr=FFCC66&ftcr=000000&rk=0&bd=0&bdas=0"></iframe>'
				form += '</form>';
				break;
			
			case 'lite':
				form += '<form name="'+obj+'" onSubmit="iSearch.doSearch(\''+obj+'\');return false;">';
				form += '<input id="isearch_keyword" name="keyword" type="text" style="width:120px" onfocus="this.select()" title="多个关键词请用空格分隔" /> ';
				form += '<select id="isearch_stype" name="stype"><option value="investment">招商</option><option value="agent">代理</option></select><br />';
				form += '<label for="isearch_isquick" title="从缓存中搜索数据,无须等待,极速体验.">快速<input id="isearch_isquick" name="isquick" type="checkbox" value="1" /></label>';
				form += '<input type="hidden" name="obj" value="'+obj+'" />';
				form += '<input type="hidden" name="special" value="'+special+'" />';
				form += '<input type="button" value=" 搜索 " class="button" onClick="iSearch.doSearch(\''+obj+'\')" />';
				form += '</form>';
				break;
		}
		
		
		//装载表单
		document.getElementById(obj).innerHTML = form;
		
		//装载表单数据
		if (keyword != null){document.forms[obj].keyword.value = keyword;}
		if (stype == 'agent'){
			document.forms[obj].stype.options[1].selected = true;
		}
		if (isquick == 1){document.forms[obj].isquick.checked = true;}
	}

}

function quickSearch(keyword){
	iSearch.Fill(keyword);
	iSearch.doSearch('isearch');
}

var iSearch = new iSearch();