//******************************************************
// 包含文件 用法： $import('../include/mian.js', 'js');
//              $import('../style/style.css', 'css');
//******************************************************

String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
function $import(path, type){
 var i, 
      base, 
      src = "common.js", 
      scripts = document.getElementsByTagName("script"); 
 

 for (i = 0; i < scripts.length; i++) {
      if (scripts[i].src.match(src)) {
          base = scripts[i].src.replace(src, "");
          break;
      }
  }
 
  if (type == "css") {
      document.write("<" + "link href=\"" + base + path + "\" rel=\"stylesheet\" type=\"text/css\"></" + "link>");
  } else {
      document.write("<" + "script src=\"" + base + path + "\"></" + "script>");
  }
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else if (obj.y) curtop += obj.y;
	return curtop;
}
function splitId(str){
	var obj = new Object();
	var tmp = str.split(":");
	obj.tempId = tmp[0];
	obj.newId = tmp[1];
	return obj;
}

/*
function interlibSearchInit(){
	$("simpleSearchDiv").style.display="none";
	$("simpleSearchDiv").style.position="absolute";
	$("simpleSearchDiv").style.backgroundColor="#FFFFE0";
	$("simpleSearchDiv").style.border="2px solid #D9E7FF";
	$("simpleSearchDiv").style.marginLeft="50px";
	$("simpleSearchDiv").style.padding="10px";
}
function simpleSearch(){	
	if($("simpleSearchDiv").style.display=="none")
		$("simpleSearchDiv").style.display="block";			
	else
		$("simpleSearchDiv").style.display="none";
}
function closeWindow(){
	$("simpleSearchDiv").style.display="none";
}
//attachEvent("onload",interlibSearchInit);



function submitSEARCH(Obj_click){		
	normalSearch(Obj_click);	
}

function normalSearch(Obj_click){
	var sql = "";  
	if (document.simpleSearchForm.val1.value.trim()==""){
	    alert(App.Loc.serachValue);
	    return;
	}
	//document.simpleSearchForm.val1.value=UTF8UrlEncode(document.simpleSearchForm.val1.value.trim());

	document.simpleSearchForm.val1.value=document.simpleSearchForm.val1.value.trim();
	if(document.simpleSearchForm.matching.selectedIndex == 0){
		if(document.simpleSearchForm.val1.value !=""){
			sql = sql + makeIdx(document.simpleSearchForm.col1.value) + " like upper('" + document.simpleSearchForm.val1.value +"%'))";
		}
	}
	if(document.simpleSearchForm.matching.selectedIndex == 1){
		if(document.simpleSearchForm.val1.value !=""){ 
			sql = sql + makeIdx(document.simpleSearchForm.col1.value) + " like upper('%" + document.simpleSearchForm.val1.value +"%'))";
		}
	}
	if(document.simpleSearchForm.matching.selectedIndex == 2){
		if(document.simpleSearchForm.val1.value !=""){ 
			sql = sql + makeIdx(document.simpleSearchForm.col1.value) + " like upper('" + document.simpleSearchForm.val1.value +"'))";
		}
	}
	document.simpleSearchForm.searchSign.value="NO";
	var MT = "";		
	if(document.simpleSearchForm.booktype.selectedIndex == 0){
	   MT = " and booktype=1";
	}
	if(document.simpleSearchForm.booktype.selectedIndex == 1){
	   MT = " and booktype=2";
	} 
	if(document.simpleSearchForm.booktype.selectedIndex == 2){
	   MT = " and booktype=3";
	}
	
	
	if(document.simpleSearchForm.marcformat.selectedIndex == 0){
	   MT = MT + " and marcformat='CNMARC'";
	}
	if(document.simpleSearchForm.marcformat.selectedIndex == 1){
	   MT = MT + " and marcformat='USMARC'";
	}
	
	sql = "select BOOKRECNO,AUTHOR,CLASSNO,BOOKTYPE,ISBN,PAGE,PRICE,PUBLISHER,PUBDATE,TITLE,SUBJECT "
	    + "from biblios where " + sql + MT;	
	
	document.simpleSearchForm.filter.value = UTF8UrlEncode(sql);		
	Obj_click.disabled=true;
	document.simpleSearchForm.action = "http://www.interlib.com.cn:8060/test/websearch/bookSearch";
	document.simpleSearchForm.submit();
}
function makeIdx(s){
     var filter = new String(s);
     var sql    = "";
     if (filter=="a.title") {
	 sql = "bookrecno in (select bookrecno from bib_titidx where upper(title) ";
     }
     if (filter=="b.isbn") { 
	 sql = "bookrecno in (select bookrecno from bib_isbnidx where upper(isbn) ";
     }
     if (filter=="c.author") {
	 sql = "bookrecno in (select bookrecno from bib_autidx where upper(author) ";
     }
     if (filter=="d.classno") {
         sql = "bookrecno in (select bookrecno from bib_claidx where upper(classno) ";
     }
     if (filter=="e.controlno") {
	 sql = "bookrecno in (select bookrecno from bib_ctrlidx where upper(controlno) ";
     }
     if (filter=="f.orderno") {
	 sql = "bookrecno in (select bookrecno from bib_ordidx where upper(orderno) ";
     }
     if (filter=="g.publisher") {
	 sql = "bookrecno in (select bookrecno from bib_pubidx where upper(publisher) ";
     }
     if (filter=="h.unino") {
	 sql = "bookrecno in (select bookrecno from bib_uniidx where upper(unino) ";
     }						
     if (filter=="i.subject") {
	 sql = "bookrecno in (select bookrecno from bib_subidx where upper(subject) ";
     }
     if(filter=="hd.callno"){
     	sql="bookrecno in(select bookrecno from holding where upper(callno) ";
     }   
    // sql = UTF8UrlEncode(sql);
    return sql;
}



function UTF8UrlEncode(input){
	var output = "";
	var currentChar = '';
	
	for(var counter = 0; counter < input.length; counter++){
	        currentChar = input.charCodeAt(counter);
	        
	        if((48 <= currentChar) && (currentChar <= 57))
	                output = output + input.charAt(counter);
	        else if((65 <= currentChar) && (currentChar <= 90))
	                output = output + input.charAt(counter);
	        else if((97 <= currentChar) && (currentChar <= 122))
	                output = output + input.charAt(counter);
	        else
	                output =  output + UTF8UrlEncodeChar(currentChar); 
	}
	return output;
}

function UTF8UrlEncodeChar(input){
        if(input <= 0x7F) return "%" + input.toString(16);

        var leadByte = 0xFF80; var hexString = ""; var leadByteSpace = 5;
        while(input > (Math.pow(2, leadByteSpace + 1) - 1))
        {
                hexString = "%" + ((input & 0x3F) | 0x80).toString(16) + hexString;
                leadByte = (leadByte >> 1);
                leadByteSpace--;
                input = input >> 6;
        } 
        return ("%" + (input | (leadByte & 0xFF)).toString(16) + hexString).toUpperCase();
}

*/
