/** popupsearch.js **/

function popSearch(page,height,width) {
	popSearch(page,height,width,"no");
}
function popSearch(page,height,width,scrlbar) {
	params = "height=" + height + ",width=" + width + ",status=yes,toolbar=no,directories=no,menubar=no,location=no,scrollbars=" + scrlbar + ",resizable=yes,top=50,left=50,screenX=50,screenY=50"
	popSearchBox = open(page,"SearchBox",params);
	popSearchBox.focus();
}

/** searchandlisting.js **/


/** originally from main file by jansen **/

function hasCheckedForBasket(){
	var inquiryFormName="inquiry";
	var inquiryForm;
	var ret=false;
	var objColls=inquiryForm=document.getElementsByName(inquiryFormName);
	if(objColls.length>0)
		inquiryForm=objColls[0];
	for (var i=0;i<inquiryForm.elements.length;i++) {
		var e=inquiryForm.elements[i];
		if ((e.type=='checkbox') && e.name!='starRank' && e.name!='csfVal' && e.name!='eventVal' && e.name!='bustypeVal' && e.name!='ctryVal' && e.name!='stateVal' && e.name!='cityVal' && e.disabled==false && e.checked==true) {
			ret=true;
			break;
		} 
	}
	return ret;
}

function loseSelectBasketAlert(){
	//important,if no add basket button,then return directly
	//the variant hasAddBasketButton if definded in the jsp page which has the ADD TO BASKET button
	if(typeof(hasAddBasketButton)=='undefined') return true;
	var ret=true;
	if(hasCheckedForBasket()==true){
		//if(window.confirm("You have not added the selected items to your basket.\nDo you wish to proceed without adding?")==true)
		if(window.confirm("你希望将选定项目添加到查询篮吗？")==true)
			ret=true;
		else
			ret=false;
	}
	return ret;
}

//added by Yiweiping 2005-05-11 : judge if the checkbox is selected 
function hasCheckedCategory(formName){
	var inquiryFormName=formName;
	var inquiryForm;
	var ret=false;
	var objColls=inquiryForm=document.getElementsByName(inquiryFormName);
	if(objColls.length>0)
		inquiryForm=objColls[0];
	for (var i=0;i<inquiryForm.elements.length;i++) {
		var e=inquiryForm.elements[i];
		if ((e.type=='checkbox') && e.disabled==false && e.checked==true) {
			ret=true;
			break;
		} 
	}
	return ret;
}

function loseSelectAlert(formName){
	//the variant hasAddBasketButton if definded in the jsp page which has the ADD TO BASKET button
	var ret=true;
	var formName ;
	if ( formName == null || formName=="" )
	{
		formName = document.forms[1].name ;
	}
	if(hasCheckedCategory("setalert")==true){
		if(window.confirm("You have not added the selected categories to your Product Alert. \nDo you wish to proceed without adding?")==true)
			ret=true;
		else
			ret=false;
	}
	return ret;
}
//added by Yiweiping 2005-05-11 : end

/** originally from main pages **/

self.name = "mother";
function checkMax (minfield,maxfield) {
	if (maxfield.value=='' && minfield.value!='') {
		maxfield.value = minfield.value;
	} else {
		curMin = parseInt(minfield.value);
		curMax = parseInt(maxfield.value);
		if (curMax < curMin) {
			maxfield.value = minfield.value;
		}
	}
}

/** originally from JSSelectClearAll **/

function all(name) {
	for ( var i=0; i < document.inquiry.elements.length; i++ ) {
    	var b=document.inquiry.elements[i];
        document.inquiry.elements[i].checked = name;
	}
}
// used for the all ticker because above methods not supported
function tickAll(chkboxset,tickerset,state) {
	if (chkboxset != null) {
		if (chkboxset.length>1) {
			for (var i=0; i < chkboxset.length; i++ ) {
				var chkbox = chkboxset[i];
				chkbox.checked = state;
	   		}
		} else {
			chkboxset.checked = state;
		}
	}
	if (tickerset != null)
	{
		for (var j=0; j < tickerset.length; j++ ) {
			var ticker = tickerset[j];
			if (ticker.checked != state) {
				ticker.checked = state;	
			}
		}
	}
	
}
function syncTickers(mycheckbox,tickerset) {
	if(mycheckbox.checked==false) {
		if (tickerset != null) {
			for (var j=0; j < tickerset.length; j++ ) {
				var ticker = tickerset[j];
				ticker.checked = false;	
			}
		}
	}
}
//use link to check all boxes instead of all_ticker, Jansen Oct12, 2004
//modified version to make the link a toggle instead
function selectAllCheckBox(checkBoxName){
	if(checkBoxName!=null){
		if (checkBoxName.length>1) {
			var	somethingNotChecked = false;
			var somethingChecked = false;
			var oEl=document.getElementsByName(checkBoxName);
			var checkboxDivider = document.getElementsByName("upperCheckBoxes");
			var maxBoxesToCheck = oEl.length;
			if (checkboxDivider!=null && checkboxDivider.length>0) {
				maxBoxesToCheck = parseInt(checkboxDivider.item(0).value);
			}
			for (var i=0;i<maxBoxesToCheck;i++){
				if (oEl.item(i).checked) {
					somethingChecked = true;
				} else {
					somethingNotChecked = true;
				}
			}
			if (somethingChecked==true && somethingNotChecked==true) {
				for (var i=0;i<maxBoxesToCheck;i++){
					oEl.item(i).checked=true;
				}
			} else if (somethingChecked==true && somethingNotChecked==false) {
				for (var i=0;i<maxBoxesToCheck;i++){
					oEl.item(i).checked=false;
				}
			} else if (somethingChecked==false && somethingNotChecked==true) {
				for (var i=0;i<maxBoxesToCheck;i++){
					oEl.item(i).checked=true;
				}
			}
		} else {
			if (checkBoxName.checked) {
				checkBoxName.checked = false;
			} else {
				checkBoxName.checked = true;
			}
		}
	}
}
function selectAllUnverified(checkBoxName,startFrom){
	if(checkBoxName!=null){
		if (checkBoxName.length>1) {
			var	somethingNotChecked = false;
			var somethingChecked = false;
			var oEl=document.getElementsByName(checkBoxName);
			var maxBoxesToCheck = oEl.length;
			for (var i=startFrom;i<maxBoxesToCheck;i++){
				if (oEl.item(i).checked) {
					somethingChecked = true;
				} else {
					somethingNotChecked = true;
				}
			}
			if (somethingChecked==true && somethingNotChecked==true) {
				for (var i=startFrom;i<maxBoxesToCheck;i++){
					oEl.item(i).checked=true;
				}
			} else if (somethingChecked==true && somethingNotChecked==false) {
				for (var i=startFrom;i<maxBoxesToCheck;i++){
					oEl.item(i).checked=false;
				}
			} else if (somethingChecked==false && somethingNotChecked==true) {
				for (var i=startFrom;i<maxBoxesToCheck;i++){
					oEl.item(i).checked=true;
				}
			}
		} else {
			if (checkBoxName.checked) {
				checkBoxName.checked = false;
			} else {
				checkBoxName.checked = true;
			}
		}
	}
}

/** originally from JSPopupHelp **/

function popup(page,height,width) {
	params = "height=" + height + ",width=" + width + ",status=no,toolbar=no,directories=no,menubar=no,location=no,scrollbars=yes,resizable=yes,top=50,left=50,screenX=50,screenY=50"
	popHelp = open(page,"HelpWindow",params);
	popHelp.focus();
}

/** originall from JSPopup **/
function pop(page,height,width){
        params = "height=" + height + ",width=" + width + ",status=1,toolbar=0,directories=0,menubar=0,location=0,scrollbars=1,resizable=1,top=50,left=50,screenX=50,screenY=50";
        mypopup = window.open(page,"PopupWindow",params);
        mypopup.focus();
}

//get visitors' screen resolution, append to a image url, 
//then write to current document
function writeScreenResolution(blankGIF){
	var r;
	do {
		r=Math.ceil(Math.random()*10000000000);
	} while(r<1000000000);
	var w=screen.width;
	var h=screen.height;
	var resolURL=blankGIF+"?resol="+w+"by"+h+"&rand="+r;
	document.write("<img src=\""+resolURL+"\" width=0 height=0 border=0>");
}

/* TP/TCS ALPHA PAGINATION */
function exposeSet(whichSet,whichBlock) {
	setToShow = document.getElementById(whichSet);
	blockToHide = document.getElementById(whichBlock);
	for (a=0; a<setArray.length; a++) {
		if (whichSet != setArray[a])
			document.getElementById(setArray[a]).style.display = 'none';
	}
	for (w=0;w<blockArray.length;w++) {
		if (whichBlock != blockArray[w]);
			document.getElementById(blockArray[w]).style.display = 'inline';
	}
	setToShow.style.display = 'block';
	blockToHide.style.display = 'none';
}
var imgWinDiv = document.getElementById("enlarge_images");
function show(largeImgURL) {
	imgWinDiv.innerHTML = "<img src='" + largeImgURL + "' border='1' >";
}
function showPdt(pdtID) {
	document.onmousemove = move_layer;
	var myProdDir = pdtID.substring(pdtID.length-3,pdtID.length);
	imgWinDiv.innerHTML = "<img src='http://pdt.static.globalsources.com.cn/IMAGES/PDT/SMALL/" + myProdDir + "/S" + pdtID + ".jpg' border='1'>";
	//imgWinDiv.innerHTML = "<img src='http://static.dev.globalsources.com.cn/IMAGES/PDT/SMALL/" + myProdDir + "/S" + pdtID + ".jpg' border='1'>";
}
function hide() {
	imgWinDiv.innerHTML = "";
	document.onmousemove = null;
}
function move_layer(event) {
	event = event || window.event;
	imgWinDiv.style.left=event.clientX+document.body.scrollLeft+1;
	imgWinDiv.style.top =event.clientY+document.body.scrollTop+1;
}
function hlChecked(thisChkBox,chkBoxes,numElems,origColor) {
	var hlbkg = "#d6ddee";
	if (chkBoxes.length == undefined) {
		var chkBox = chkBoxes;
		var elem1 = "HL" + chkBox.value + "A";
		var obj1 = document.getElementById(elem1);
		var elem2 = "HL" + chkBox.value + "B";
		if (chkBox.checked && (obj1!=null && obj1!=undefined)) {
			obj1.style.backgroundColor = hlbkg;
			if (obj1.className=='gridprdHL')
				obj1.className='gridprdNoHL';
			if (numElems == 2) {
				var obj2 = document.getElementById(elem2);
				obj2.style.backgroundColor = hlbkg;
				if (obj2.className=='gridprdHL')
					obj2.className='gridprdNoHL';
			}
		} else if (obj1!=null && obj1!=undefined && (chkBox.value == thisChkBox.value)) {
			obj1.style.backgroundColor = origColor;
			if (numElems == 2) {
				var obj2 = document.getElementById(elem2);
				obj2.style.backgroundColor = origColor;
			}
		}
	} else {
		for (var j=0; j < chkBoxes.length; j++ ) {
			var chkBox = chkBoxes[j];
			var elem1 = "HL" + chkBox.value + "A";
			var obj1 = document.getElementById(elem1);
			var elem2 = "HL" + chkBox.value + "B";
			if (chkBox.checked && (obj1!=null && obj1!=undefined)) {
				obj1.style.backgroundColor = hlbkg;
				if (obj1.className=='gridprdHL')
					obj1.className='gridprdNoHL';
				if (numElems == 2) {
					var obj2 = document.getElementById(elem2);
					obj2.style.backgroundColor = hlbkg;
					if (obj2.className=='gridprdHL')
						obj2.className='gridprdNoHL';
				}
			} else if (obj1!=null && obj1!=undefined && (chkBox.value == thisChkBox.value)) {
				obj1.style.backgroundColor = origColor;
				if (numElems == 2) {
					var obj2 = document.getElementById(elem2);
					obj2.style.backgroundColor = origColor;
				}
			}
		}
	}
}

/** Added for Product Mouse Over MR **/
function getPPPosition(tag){
	var Position =[0,0];
	while(tag){
		tn=tag.tagName.toUpperCase();
		Position[0]+=tag.offsetLeft;
		Position[1]+=tag.offsetTop;
		if(tn=="BODY") break;
		tag=tag.offsetParent;
	}
	return Position;
}
function showPPSummary(e,prodID,inBasket,rollOvInqURL){
	try {
		clearTimeout(timer);
	} catch(s) {}

	$$("showFrame_inq").href = rollOvInqURL + "&product_id=" + prodID;

	if (inBasket) {
		$$("showFrame_addbask").innerHTML = "已加入询盘篮";
		$$("showFrame_addbask").href = "http://" + (((typeof thisHost != "undefined") && (thisHost != null))?thisHost:"www.globalsources.com.cn") + "/gsol/GeneralManager?action=ReMap&where=GoInquiryBasket";
	} else {
		$$("showFrame_addbask").innerHTML = "加到询盘篮";
		$$("showFrame_addbask").href = "http://" + (((typeof thisHost != "undefined") && (thisHost != null))?thisHost:"www.globalsources.com.cn") + "/gsol/nsl/GeneralManager?redirect_to=this&action=AddInquiryItem&product_id=" + prodID;
	}

	eventElement=e.target||e.srcElement;
	var elementSrc = eventElement.src;
	var elementAlt = eventElement.alt;
	var elementParentHref = eventElement.parentNode.href;
	
	var toUse = prodID;
	var myProdDir = toUse.substring(toUse.length-3,toUse.length);
	//var src = "http://static.dev.globalsources.com.cn/IMAGES/PDT/SMALL/" + myProdDir + "/S" + toUse + ".jpg";
	var src = "http://pdt.static.globalsources.com.cn/IMAGES/PDT/SMALL/" + myProdDir + "/S" + toUse + ".jpg";
	
	var xy = getPPPosition(eventElement);
	var showF = $$("showFrame");
	var showFB = $$("showFrame_bg");
	showF.style.left = showFB.style.left = (xy[0]+imgWidth)+"px";
	showF.style.top = showFB.style.top = (xy[1]-overTop )+"px";
	showF.style.display = showFB.style.display = "block";
	$$("showFrame_img").src = src;
	$$("showFrame_img").alt = elementAlt;
	$$("showFrame_img").parentNode.href = elementParentHref;
}
function showPPOut(){
	timer = setTimeout("donePPOut()",500);
}
function donePPOut(){
	$$("showFrame").style.display = $$("showFrame_bg").style.display = "none";
}
function clearPPTimer(){
	try {
		clearTimeout(timer);
	} catch(s) {}
}
function secondLevelPop(page,height,width){
    params = "height=" + height + ",width=" + width + ",status=1,toolbar=0,directories=0,menubar=0,location=0,scrollbars=1,resizable=1,top=50,left=150,screenX=50,screenY=50";
    mypopup = window.open(page,"PopupWindow2",params);
    mypopup.focus();
}
function popcontact(page,height,width){
        params = "height=" + height + ",width=" + width + ",toolbar= no, menubar=no, scrollbars=no, resizable=no, location=no, status=no, top=300, left=600";
        mypopup = window.open(page,"PopupWindow",params);
        mypopup.focus();
}
//Add below for project cGSOL_v94_Display Unverified PPs On Verified PPs Search
var tipwidth='150px' //default tooltip width
var tipbgcolor='#FFFFFF'  //tooltip bgcolor
var disappeardelay=250  //tooltip disappear speed onMouseout (in miliseconds)
var vertical_offset="0px" //horizontal offset of tooltip from anchor link
var horizontal_offset="-3px" //horizontal offset of tooltip from anchor link
var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
	document.write('<div id="fixedtipdiv" style="position:absolute; left:155px; top:230px; width:432px; z-index:3; background-color:#FFFFFF; border:1px solid #006; padding:5px; font-size:12px;;visibility:hidden;width:'+tipwidth+';" ></div>')

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function popshowhide(obj, e, visible, hidden, tipwidth){
	if (ie4||ns6)
		dropmenuobj.style.left=dropmenuobj.style.top=-500
	if (tipwidth!=""){
		dropmenuobj.widthobj=dropmenuobj.style
		dropmenuobj.widthobj.width=tipwidth
	}
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
		obj.visibility=visible
	else if (e.type=="click")
		obj.visibility=hidden
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
	if (whichedge=="rightedge"){
		var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
	}else{
		var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
	}
	return edgeoffset
}

function fixedtooltip(menucontents, obj, e, tipwidth){
	if (window.event) event.cancelBubble=true
	else if (e.stopPropagation) e.stopPropagation()
	clearhidetip()
	dropmenuobj=document.getElementById? document.getElementById("fixedtipdiv") : fixedtipdiv
	dropmenuobj.innerHTML=menucontents

	if (ie4||ns6){
		popshowhide(dropmenuobj.style, e, "visible", "hidden", tipwidth)
		dropmenuobj.x=getposOffset(obj, "left")/3
		dropmenuobj.y=getposOffset(obj, "top")
		dropmenuobj.style.left=dropmenuobj.x+"px"
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+5 +"px"
	}
}

function hidetip(e){
	if (typeof dropmenuobj!="undefined"){
		if (ie4||ns6)
			dropmenuobj.style.visibility="hidden"
	}
}

function delayhidetip(){
	if (ie4||ns6)
		delayhide=setTimeout("hidetip()",disappeardelay)
}

function clearhidetip(){
	if (typeof delayhide!="undefined")
		clearTimeout(delayhide)
}
var desc = '<table border="0" cellspacing="0" cellpadding="0"><tr><td><img src="http://www.globalsources.com.cn/gsol/cn/clean/images/BLING.GIF" align="absmiddle" style="float:left; margin:0 5px 5px 0;"></td><td><SPAN lang="EN-US"><strong>环球资源已核实这些供应商的资质，确保其具备贸易实力和诚意；更通过专业团队与供应商紧密合作，核实供应商信息的真实性以及及时更新。</strong></SPAN></td></tr></table>';
var descForUnverified = '<table border="0" cellspacing="0" cellpadding="0"><tr><td><img src="http://www.globalsources.com.cn/gsol/cn/clean/images/NOT_VERIF.GIF" align="absmiddle" style="float:left; margin:0 5px 5px 0;"></td><td><SPAN lang="EN-US"><strong>由于未经环球资源核实 ，我们无法保证公司和产品信息的准确性。</strong></SPAN></td></tr></table>';

function openmsn(url){
	window.open(url,'','height=590,   width=294,   top=0,   left=0,   toolbar=no,   menubar=no,   scrollbars=yes,resizable=yes,location=no,   status=no');
}

function OnJSONPResponseList(obj){
	$(document).ready(function (){
		//alert("fff=="+obj.comefrom);
		if(obj.comefrom=='jsonlist'){
			$('div[@id='+obj.objectid+']').empty();
			$('div[@id='+obj.objectid+']').removeClass();
			$('div[@id='+obj.objectid+']').addClass(obj.className);
			var ahref = $('<A href="javascript:void(0);" onclick="openmsn(\''+obj.chaturl+'\')">'+obj.html+'</a>');
			$('div[@id='+obj.objectid+']').append(ahref);
		}else if(obj.comefrom=='jsongrid'){
			//sss
			$('span[@id='+obj.objectid+']').empty();
			var ahref = $('<A href="javascript:void(0);" class="'+obj.className+'" onclick="openmsn(\''+obj.chaturl+'\')">'+obj.html+'</a>');
			$('span[@id='+obj.objectid+']').append(ahref);
		}
	});
}

function createScript(scriptUrl){
	var script =document.createElement("script");
	script.setAttribute("type", "text/javascript");
	script.setAttribute("src",scriptUrl);
	return script;
}
function showHideContents(elemID,linkObjID,copyForShow,copyForHide) {
	if (document.getElementById) {
		if (document.getElementById(elemID).style.display == "block") {
			document.getElementById(elemID).style.display = "none";
			document.getElementById(linkObjID).innerHTML = copyForShow;
		} else {
			document.getElementById(elemID).style.display = "block";
			document.getElementById(linkObjID).innerHTML = copyForHide;
		}
	} else if (document.layers) {
		if (document[elemID].display == "block") {
			document[elemID].display = "none";
			document[linkObjID].innerHTML = copyForShow;
		} else {
			document[elemID].display = "block";
			document[linkObjID].innerHTML = copyForHide;
		}
	}
}
function applySortFilt(formObj) {
	//if (formObj.selectedIndex==formObj.length-1) {//when select "Filter by Supplier Name"
	if (formObj[formObj.selectedIndex].text.indexOf("筛选")>=0) {//when select "Filter by XXXXXXX"
		popSearch(formObj[formObj.selectedIndex].value,'260','320');
	} else {
		if (formObj[formObj.selectedIndex].value != '') {
			location.href = formObj[formObj.selectedIndex].value;
		}
	}
}
