
var temp;
var tempFalg = "";
var tempInner;
var imagePass = true;

function forward(el, href, pId) {
	
	var msg =document.getElementById("tipMsg");
	if(msg)	msg.style.display = "block";
//	msg.id = "tipMsg";
//	msg.className = "tipMsg";
//	msg.innerHTML = "Loading...";
	
//	document.body.appendChild(msg);
    dojo.io.bind(
    {
    	url:href, 
    	encoding:'utf-8',
    	load:function (type, data, evt) {
	        if (pId != null) {
	            pId.disabled = false;
	        }
	        if(data == "w") {
	        	window.location.replace("http://www.artmuseum.com.cn/login.htm");
	        	return;
	        }
        	el.innerHTML = data;
        	if(msg) msg.style.display = "none";
    	}, 
    	timeoutSeconds:5000, error:function (type, error) {
        	alert(error.message);
    	}, timeout:function (type) {
       		alert("timeout");
    	}, 
    	mimetype:"text/plain"
    });
}
function forwardForm(el, href, form) {
	//createLoading(el);
    dojo.io.bind({url:href, load:function (type, data, evt) {
    	if(el) el.innerHTML = data;
    },
    encoding:'utf-8',
    formNode:form, timeoutSeconds:5000, error:function (type, error) {
        alert(error.message);
    }, timeout:function (type) {
        alert("timeout");
    }, mimetype:"text/plain"});
}
function forwardFormBack(el, href, form) {
    dojo.io.bind({url:href, load:function (type, data, evt) {
        el.innerHTML = data;
		highlightWord(document.getElementById("s_info"),document.getElementById('keyword').value);
    }, encoding:'utf-8',formNode:form, timeoutSeconds:5000, error:function (type, error) {
        alert(error.message);
    }, timeout:function (type) {
        alert("timeout");
    }, mimetype:"text/plain"});
}
function doForwardForm(url) {
    var form = document.getElementById("s_form");
    var s_info = document.getElementById("s_info");
    forwardForm(s_info, url, form);
}
function backColor(t) {
    if (temp == null) {
    	alert("32");
        return;
    }
    if (temp != t) {
        document.getElementById(temp).innerHTML = tempInner;
        temp = t;
        if (document.getElementById(temp) != null) {
            tempInner = document.getElementById(temp).innerHTML;
        }
    }
}
function doSearchArtist(url) {
    var s = document.forms["a_search"].s.value;
    var c = document.forms["a_search"].c.value;
    var n = document.forms["a_search"].n.value;
    var href = "a_search.htm?s=" + s + "&c=" + c + "&n=" + n;
	href = encodeURI(href);
//    if (url != null && url != "") {
//       href = url;
//        document.forms["a_search"].n.value = "";
//        document.forms["a_search"].c.selectedIndex = 0;
//        document.forms["a_search"].s.selectedIndex = 0;
//   }
    var all_listinfo = document.getElementById("all_listinfo");
    forward(all_listinfo, href);
}
function doForward(url, t) {
    var s_info = document.getElementById("s_info");
		
    if (s_info != null) {
        forward(s_info, url);
        return false;
    }
    if (t != null && temp == null) {
        temp = t;
        if (document.getElementById(temp) != null) {
            tempInner = document.getElementById(temp).innerHTML;
        }
    }
    var sort = document.getElementById(t);
    if (t == "o10") {
        backColor(t);
        if(sort)sort.innerHTML = "<span class='nowselect'>Oil Painting</span>";
    }
    if (t == "k20") {
        backColor(t);
        if(sort)sort.innerHTML = "<span class='nowselect'>Kirigami</span>";
    }
    if (t == "s30") {
        backColor(t);
        if(sort)sort.innerHTML = "<span class='nowselect'>Sculpture<span>";
    }
    if (t == "w50") {
        backColor(t);
        if(sort)sort.innerHTML = "<span class='nowselect'>Watercolor/Gouache</span>";
    }
    if (t == "g60") {
        backColor(t);
        sort.innerHTML = "<span class='nowselect'>Engraving</span>";
    }
    if (t == "c40") {
        backColor(t);
        if(sort)sort.innerHTML = "<span class='nowselect'>Chinese Painting</span>";
    }   
    if (t == "s11") {
        backColor(t);
        if(sort)sort.innerHTML = "<span class='nowselect'>Realism</span>";
    }
    if (t == "s12") {
        backColor(t);
        if(sort)sort.innerHTML = "<span class='nowselect'>Abstract</span>";
    }
    if (t == "s13") {
        backColor(t);
        if(sort)sort.innerHTML = "<span class='nowselect'>Art Deco</span>";
    }
    if (t == "s14") {
        backColor(t);
        if(sort)sort.innerHTML = "<span class='nowselect'>Asian</span>";
    }
   if (t == "s15") {
        backColor(t);
        if(sort)sort.innerHTML = "<span class='nowselect'>Cubist</span>";
    }
      if (t == "s16") {
        backColor(t);
        if(sort)sort.innerHTML = "<span class='nowselect'>Impressionist</span>";
    }
     if (t == "s17") {
        backColor(t);
        if(sort)sort.innerHTML = "<span class='nowselect'>Miniature</span>";
    }
     if (t == "s18") {
        backColor(t);
        if(sort)sort.innerHTML = "<span class='nowselect'>Outsider Art</span>";
    }
     if (t == "s19") {
        backColor(t);
        if(sort)sort.innerHTML = "<span class='nowselect'>Pop Art</span>";
    }
     if (t == "s20") {
        backColor(t);
        if(sort)sort.innerHTML = "<span class='nowselect'>Surrealism</span>";
    }
     if (t == "s21") {
        backColor(t);
        if(sort)sort.innerHTML = "<span class='nowselect'>Other</span>";
    }
    if(document.forms["a_search"] && !new RegExp("/all_artist.htm","g").test(url)) {
    	document.forms["a_search"].n.value = "";
        document.forms["a_search"].c.selectedIndex = 0;
        document.forms["a_search"].s.selectedIndex = 0;
    }
    var all_listinfo = document.getElementById("all_listinfo");
    forward(all_listinfo, url);
    return false;
}
function doOrderBy(select, href) {
    var orderBy = select[select.selectedIndex].value;
    var selectHref = href + (orderBy);
    var s_info = document.getElementById("s_info");
    if(s_info != null) {
    	forward(s_info, selectHref);
    	return false;
    }
    
    var all_listinfo = document.getElementById("all_listinfo");
    forward(all_listinfo, selectHref);
}
function changePage(href) {
    var pId = document.getElementById("curP");
    pId.disabled = true;
    var selectHref = href + (pId.selectedIndex + 1);
    doPageForward(selectHref, pId);
}
function changeTopPage(href) {
    var pId = document.getElementById("curP0");
    pId.disabled = true;
    var selectHref = href + (pId.selectedIndex + 1);
    doPageForward(selectHref, pId);
}
function doPageForward(href, pId) {
	var s_info = document.getElementById("s_info");
	if(s_info != null) {
		if(pId != null) {
	    	forward(s_info,href,pId);
		} else {
	    	forward(s_info,href);		
		}
    	return false;
    }
    var handle_page_view = document.getElementById("handle_page_view");
    if(handle_page_view != null) {
		if(pId != null) {
			forward(handle_page_view,href,pId);
		} else {
			forward(handle_page_view,href);
		}
		return false;
	}
    var all_listinfo = document.getElementById("all_listinfo");
    if (pId != null) {
        forward(all_listinfo, href, pId);
    } else {
        forward(all_listinfo, href);
    }
    return false;
}
function doArtistName(href) {
    var aName = document.getElementById("a_name");
    forward(aName, href);
    return false;
}
function doWatch(href,el) {
    if(el) {
    	forward(el, href);
    	el.onclick="";
    } else {
	    var aWatch = document.getElementById("a_watch");
	    forward(aWatch, href);
	    aWatch.parentNode.onclick = null;
    }
    return false;
}
function doAllSearch() {
    var mainContent = document.getElementById("main_content");
    var wrap = document.getElementById("wrap");
//	alert(mainContent.childNodes.length);
    if (mainContent != null) {
        wrap.removeChild(mainContent);
        for (var i = 0; i < mainContent.childNodes.length; i++) {
            var note = mainContent.childNodes.item(0);
            mainContent.removeChild(note);
        }
    }
    var allSearch = document.getElementById("allSearch");
    var s = document.forms[0].s.value;
    var c = document.forms[0].c.value;
    var search_result = document.getElementById("search_result");
    search_result.innerHTML = "Searching... please wait a moment";
    var href = "allSearch.htm?test=123";
    dojo.io.bind({url:href, timeoutSeconds:5000, method:"POST", formNode:allSearch, load:function (type, data, evt) {
        search_result.innerHTML = data;
    }, encoding:'utf-8',error:function (type, error) {
        alert(error.message);
    }, timeout:function (type) {
        alert("timeout");
    }, mimetype:"text/plain"});
}
function highlightWord(node,word) {    // Iterate into this nodes childNodes    
	if (node.hasChildNodes) {        
		var hi_cn;        
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			highlightWord(node.childNodes[hi_cn],word);       
		 }   
	 }   // And do this node itself    
	 if (node.nodeType == 3) { // text node        
	 	tempNodeVal = node.nodeValue.toLowerCase();       
		tempWordVal = word.toLowerCase();        
		if (tempNodeVal.indexOf(tempWordVal) != -1) {           
			pn = node.parentNode;            
			if (pn.className != "highlight") {                // word has not already been highlighted!                
				nv = node.nodeValue;                
				ni = tempNodeVal.indexOf(tempWordVal);                // Create a load of replacement nodes                
				before = document.createTextNode(nv.substr(0,ni));                
				docWordVal = nv.substr(ni,word.length);                
				//docWordVal = word;
				after = document.createTextNode(nv.substr(ni+word.length));                
				hiwordtext = document.createTextNode(docWordVal);                
				hiword = document.createElement("span");                
				hiword.className = "highlight";                
				hiword.appendChild(hiwordtext);                
				pn.insertBefore(before,node);                
				pn.insertBefore(hiword,node);                
				pn.insertBefore(after,node);                
				pn.removeChild(node);            
			}        
		}    
	}
}
function searchHighlight() {    
	if (!document.createElement) return;    
	ref = document.referrer;    
	if (ref.indexOf('?') == -1 || ref.indexOf('http://blog.run2me.com/geniusleft/') != -1)    {        
		qref = document.location.href;        
		if (ref.indexOf('?') == -1) return;    
	}    
	qs = ref.substr(ref.indexOf('?')+1);    
	qsa = qs.split('&');    
	for (i=0;i<qsa.length;i++) {        
		qsip = qsa[i].split('=');        
		if (qsip.length == 1) continue;         // keyword refer: q= for Google or for msn, p= for Yahoo, wd= for baidu, w= for QQ        
		if (qsip[0] == 'q' || qsip[0] == 'p' || qsip[0] == 'wd' || qsip[0] == 'w'  ) {        
			words = unescape(qsip[1].replace(/\+/g,' ')).split(/\s+/);           
			for (w=0;w<words.length;w++) {            
				highlightWord(document.getElementsByTagName("body")[0],words[w]);            
			}       
		}    
	}
}
function DrawImage(ImgD) {
   		/*
   		var image=new Image();
		ImgD = (ImgD) ? ImgD : this;   		
  		if(ImgD) {
  			if(ImgD.src) {
		  		image.src=ImgD.src;
  			}
  		} else {
  			image.src = this.src;
  		}
   		if(ImgD.width>0 && ImgD.height>0){
       		if(image.width/image.height>= 1){
       			if(image.width>100){  
       				ImgD.width=100;
       				ImgD.height=(image.height*100)/image.width;
    		    }else{
      				ImgD.width=image.width;  
      				ImgD.height=image.height;
    			}
      			ImgD.alt=image.width+"X"+image.height;
  		   } else{
     			if(image.height>100){  
     				ImgD.height=100;
     				ImgD.width=(image.width*100)/image.height;     
     			}else{
     				ImgD.width=image.width;  
     				ImgD.height=image.height;
     			}
     	 		ImgD.alt=image.width+"X"+image.height;
     	  }
   		}
   		*/
   		var image=new Image();
   		image.src = this.src;
   		ImgD = (ImgD) ? ImgD : this;
   		var w = image.width;
   		var h = image.height;
   		if(w>1500 || h>1500) {
			imagePass = false;
   		} else {
   			imagePass = true;
   		}
   		if(w>0 && h>0){
       		if(w/h>= 1){
       			if(w>100){  
       				ImgD.width=100;
       				ImgD.height=(h*100)/w;
    		    } else {
    		    	ImgD.width = w;
    		    	ImgD.height = h;
    		    }
      			ImgD.alt=image.width+"X"+image.height;
  		   } else{
     			if(h>100){  
     				ImgD.height=100;
     				ImgD.width=(w*100)/h;     
     			} else {
    		    	ImgD.width = w;
    		    	ImgD.height = h;
    		    }
     	 		ImgD.alt=image.width+"X"+image.height;
     	  }
   		} else {
  // 			alert("请重新�?�择");
   		}	
	}
	
	function vImg(ImgD) {
   		
   		var image=new Image();
   		
		return;
		ImgD = (ImgD) ? ImgD : this;   		
  		if(ImgD) {
  			if(ImgD.src) {
		  		image.src=ImgD.src;
  			}
  		} else {
  			image.src = this.src;
  		}
   		if(image.width>0 && image.height>0){
       		if(image.width/image.height>= 1){
       			if(image.width>100){  
       				ImgD.width=100;
       				ImgD.height=(image.height*100)/image.width;
    		    }else{
      				ImgD.width=image.width;  
      				ImgD.height=image.height;
    			}
      			ImgD.alt=image.width+"X"+image.height;
  		   } else{
     			if(image.height>100){  
     				ImgD.height=100;
     				ImgD.width=(image.width*100)/image.height;     
     			}else{
     				ImgD.width=image.width;  
     				ImgD.height=image.height;
     			}
     	 		ImgD.alt=image.width+"X"+image.height;
     	  }
   		}
	}
	
	var w3c=(document.getElementById)? true:false;
	var agt=navigator.userAgent.toLowerCase();
	var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));
	var ie5=(w3c && ie)? true : false;
	var ns6=(w3c && (navigator.appName=="Netscape"))? true: false;
	var op8=(navigator.userAgent.toLowerCase().indexOf("opera")==-1)? false:true;
				
	function mask(el) {
		var mask = document.createElement("div");
		mask.style.position ="absolute";
		mask.style.zIndex = "3000";
		mask.style.backgroundImage = "url('images/zmz-resource1.gif')";
		var nLt=0;
		var nTp=0;
		var offsetParent = el;
		while (offsetParent!=null && offsetParent!=document.body) {
			 nLt+=offsetParent.offsetLeft;
			 nTp+=offsetParent.offsetTop;
			 if(!ns6){
			    parseInt(offsetParent.currentStyle.borderLeftWidth)>0?nLt+=parseInt(offsetParent.currentStyle.borderLeftWidth):"";
			    parseInt(offsetParent.currentStyle.borderTopWidth)>0?nTp+=parseInt(offsetParent.currentStyle.borderTopWidth):"";
			 }
			offsetParent=offsetParent.offsetParent;
		}
		mask.style.left = nLt + "px";
		mask.style.top = nTp + "px";
		mask.style.width = el.clientWidth + "px";
		mask.style.height = el.clientHeight + "px";
		document.body.appendChild(mask);
	}
	function showNewWindow(theURL,winName,features) { //v2.0
          window.open(theURL,winName,features);
          return false;
}
function NEW_goToURL(target,url) { //v3.0
        url = encodeURI(url);
        if (target=='_top'){
            parent.location=url;
        }else if (target=='_blank'){
            var newwin = window.open('','_blank','scrollbars=1,resizable=1,left=0,top=0,width=550,height=430');
            newwin.location=url;
            newwin.focus();
        }else if (target=='_blank1'){
            var newwin = window.open('','_blank','scrollbars=1,resizable=1,left=0,top=0,width=650,height=430');
            newwin.location=url;
            newwin.focus();
        }else if (target=='_blank2'){
            var newwin = window.open('','_blank','toolbar=1,location=1,status=1,menubar=1,scrollbars=1,resizable=1,left=0,top=0');
            newwin.location=url;
            newwin.focus();
        }else if (target=='_blank3'){
            var newwin = window.open('','_blank','scrollbars=no,resizable=no,left=0,top=0,width=790,height=550');
            newwin.location=url;
            newwin.focus();
        }else if (target=='chatroom'){
            var newwin = window.open('','searchWin','scrollbars=no,resizable=no,left=0,top=0,width=790,height=550');
            newwin.location=url;
            newwin.focus();
        }else if (target=='auction'){
            var newwin = window.open('','_blank','scrollbars=1,resizable=1,left=0,top=0,width=800,height=600');
            newwin.location=url;
            newwin.focus();
        }else if (target=='small'){
            var newwin = window.open('','_blank','scrollbars=no,resizable=no,left=300,top=300,width=400,height=200');
            newwin.location=url;
            newwin.focus();
        }else{
            if (parent.frmaes != null){
                parent.frames(target).location=url;
            }else{
                this.location=url;
            }
        }
        return;

}
