function GE( id )
{
	return document.getElementById(id);
}
function ContactNow()
{
	var result="";
	var Items=document.getElementsByName("chkIDs");
	for(var i=0;i<Items.length;i++)
	{
		var e=Items[i];
		if (e.checked==true)
		{
			result+=","+e.value;
		}		
	}
	if (result.indexOf(',') == 0) 
	{
		result=result.substr(1);
		window.open("/sendMsg/sendMsg.html?chkIDs="+result);
	}
	else
	{
		window.open("/Myecvv/basket.html");
	}
}
function AddToBasket()
{
	
	var selectedNum=0 ;
	var Items=document.getElementsByName("chkIDs");
	for(var i=0;i<Items.length;i++)
	{
		var e=Items[i];
		if (e.checked==true)
		{
			selectedNum++;
		}		
	}
	if(selectedNum > 0)
	{		
		var basketNum=parseInt(GE("basketNum").value);
		if (selectedNum+basketNum > 20) 
		{
			alert("Sorry,you have added 20 products to the basket.");
		}
		else
		{
			var f=GE("Form1");
			var Cmd=GE("Cmd");			
			Cmd.value="AddToBasket";
			GE("bntAddBasketUp").disabled = true;
			GE("bntAddBasketDown").disabled = true;
			f.submit();
		}	
	}
	else
	{
		alert("No item(s) selected");
	}
}
function AddOneToBasket(flag)
{
	switch(flag) {
	case 0:
		var f=GE("Form1");
		var Cmd=GE("Cmd");
		Cmd.value="AddToBasket";
		f.submit();
		break;
	case 1:
		alert("This product has been added to the basket.");
		return false;
		break;
	case 2:
		alert("Sorry,you have added 20 products to the basket.");
		return false;
	}
}
function showPic(picSrc,productID)
{

	GE('ImgUrl').href=picSrc;
	GE('NameUrl').href=GE('ImgUrl').href;
	var obj = GE('bigPic') ;
	img=document.createElement("img");
	img.src=picSrc;
	img.id = "tempImg";
	img.style.position="absolute";
	initImg(img,285,285);
	obj.src = img.src;
	obj.style.width = img.width;
	obj.style.height = img.height;
}
function contactSingle(id)
{
	window.open("/sendMsg/sendMsg.html?chkIDs="+id);
}
function searchProduct(userName)
{
	
	if( GE("KeyWord").value == "" || GE("KeyWord").value == "Search our products")
	{
		alert("Please enter a keyword for search.");
	}
	else if( GE("KeyWord").value.length > 50 )
		alert("Key word for search must be less than 50 characters.");
	else if( GE("KeyWord").value.length < 2 )
		alert("Keyword for search must at least 2 characters.");
	else
		window.location="/company/"+userName+"/products.html?keyword="+GE("KeyWord").value;
}
function SearchECVVTradeLeads()
{
	if( ReplaceUrl(GE("ECVVKeyWord").value) == "" || GE("ECVVKeyWord").value == "Search products")
		alert("Please enter a keyword for search.");
	else if( GE("ECVVKeyWord").value.length < 2 )
		alert("Keyword for search must at least 2 characters.");
	else if( GE("ECVVKeyWord").value.length > 50 )
		alert("Key word for search must be less than 50 characters.");
	else
		window.location.href="/product/P1T1ICY0G0Z0K/"+ReplaceUrl(GE("ECVVKeyWord").value)+".html";
}
function ReplaceUrl(p_source)
{	
	var res= p_source.replace(/[\W]/g,'-').split("@").join("-").split("_").join("-");
	ress = res.split("-");
	var result="";
	for(var i=0;i<ress.length;i++)
	{
		if (ress[i].length>0) {
			result += ress[i]+"-";
		}
	};
	if (result.lastIndexOf("-")==result.length-1) {
		result = result.substring(0,result.length-1)
	}
	return result;
}
function sendOK()
{
	GE('sendTag').style.display="block";
	GE("sendOK").style.display = "block";
	GE("sendError").style.display = "none";
}
function sendError()
{
	GE('sendTag').style.display="block";
	GE("sendOK").style.display = "none";
	GE("sendError").style.display = "block";
}
function initImg(obj,w,h)
{
	var ow = obj.width ;
	var oh = obj.height ;
	if( ow > w || oh > h)
	{
		var ws = ow / w ;
		var hs = oh / h ;
		if( ws > hs)
		{
			obj.width = w ;
			obj.height = oh / ws;
		}
		else
		{
			obj.width = ow / hs ;
			obj.height = h ;
		}
	}
}
function getFreeSample(main)
{
	window.open("http://www.chinaeee.org.cn/Inquiry.asp?main="+main+"&sourceurl="+location.href)
}

function NewAddOneToBasket( id )
{
	var flag = GE( "hidBasket" ).value;
	switch( flag ) 
	{
		case "0":
			ECVV.NewCompany.Page.ProductDetail.AddToBasket( id , callback );
			return false ;
		case "1":
			window.open("/Myecvv/basket.html");
			return false;
		case "2":
			window.open("/Myecvv/basket.html");
			return false;
	}
}
function callback( res )
{
	if ( res.value ) 
	{
		GE( "btnBasket" ).src = "/newimages/supplier/addtoBasketed.gif";
		GE("hidBasket").value = "1" ;
	}
}
function PostBuyList()
{
	window.open("/Companies/Post-Buying-Lead.html");
}
function Goto( url )
{
	location.href = url;
}

function GetPostion()
{
    var   W,   H,   SL,   ST; 
    var   clientWidth,clientHeight;
    var   w=window,   d=document,   dd=d.documentElement; 

    if(w.innerWidth)   W=w.innerWidth; 
    else   if(dd&&dd.clientWidth)   W=dd.clientWidth; 
    else   if(d.body)   W=d.body.clientWidth; 

    if(w.innerHeight)   H=w.innerHeight; 
    else   if(dd&&dd.clientHeight)   H=dd.clientHeight;   
    else   if(d.body)   H=d.body.clientHeight; 

    if(w.pageXOffset)   SL=w.pageXOffset; 
    else   if(dd&&dd.scrollLeft)   SL=dd.scrollLeft; 
    else   if(d.body)   SL=d.body.scrollLeft; 

    if(w.pageYOffset)   ST=w.pageYOffset; 
    else   if(dd&&dd.scrollTop)   ST=dd.scrollTop; 
    else   if(d.body)   ST=d.body.scrollTop; 
    
        var scrollLeft = (document.documentElement.scrollLeft ?
            document.documentElement.scrollLeft : document.body.scrollLeft);
    var scrollTop = (document.documentElement.scrollTop ?
            document.documentElement.scrollTop : document.body.scrollTop);
    W=W+scrollLeft;
    H=H+scrollTop;
    return{clientWidth:W,clientHeight:H}; 
}
function reseMessengerPosition()
{
    var p=GetPostion();
    var container =  document.getElementById("divInquire");
    var containerLeft =p.clientWidth  - container.clientWidth - 20;
    var containerTop = p.clientHeight  - container.clientHeight;
    container.style.top=containerTop+"px";
    //container.style.left=containerLeft+"px";
    container.style.right="1px";
}
// reseMessengerPosition();
function AddEvent(obj)
{
    if (window.addEventListener)
    {
    window.addEventListener("resize", obj, false);
    window.addEventListener("scroll",obj,false);
    }
    else if (window.attachEvent)
    {
        window.attachEvent("onresize", obj);
        window.attachEvent("onscroll", obj);
    }
    else
    {
    window.onresize=obj;
    window.onscroll=obj;
    }
}
function RunFunction()
{
	clearTimeout(timer);
	timer =setTimeout('reseMessengerPosition()',10);
}
function ShowAndHide(obj1,obj2)
{
	var div1=document.getElementById(obj1);
	var div2=document.getElementById(obj2);
	div1.style.display=div1.style.display=="none" ? "":"none";
	div2.style.display=div2.style.display=="none" ? "":"none";
	
		var container =  document.getElementById("divInquire");
		var p=GetPostion();
		var containerLeft =p.clientWidth  - div2.clientWidth - 20;
        var containerTop = p.clientHeight  - div2.clientHeight;
		container.style.top=containerTop+"px";
        //container.style.left=containerLeft+"px";
        container.style.right="1px";
}
function Validate()
{
	var objDiv=document.getElementById("divError");
	var objMessage=document.getElementById("txtContent");
	if(objMessage.value.length<1)
	{
		objDiv.style.display="";
		objDiv.innerHTML="Please enter your message.";
		return false;
	}
	else if(objMessage.value.length<20 || objMessage.value.length>3000)
	{
		objDiv.style.display="";
		objDiv.innerHTML="Your message should be between 20-3000 characters.";
		return false;
	}
	return true;
}
function DoSubmit( PostUrl )
{
    if(Validate())
    {
		var f=document.getElementById("formInquire");
		f.action = PostUrl;
		f.target="_blank";
		ShowAndHide('divInquire3','divInquire1');
		f.submit();
    }
}
function TxtFocus()
{
	var oTxt=document.getElementById("txtContent");
	oTxt.value="";
	oTxt.focus();
}
function chgImg(id)
{
	var obj = document.getElementById("Img");
	img=document.createElement("img");
	img.src=arrImg[id];
	img.id = "tempImg";
	img.style.position="absolute";
	initImg(img,230,170);
	obj.src = img.src;
	obj.style.width = img.width;
	obj.style.height = img.height;
	document.getElementById("PhotoHref").href = arrImg[id];
	for(var i=0 ; i<arrImg.length ; i++)
		document.getElementById("num"+i).className = null;
	document.getElementById("num"+id).className ="actNum";
	curPage = id;
	clearInterval(MyInterval);
}
function autoChgImg(id)
{
	var obj = document.getElementById("Img");
	img=document.createElement("img");
	img.src=arrImg[id];
	img.id = "tempImg";
	img.style.position="absolute";
	initImg(img,230,170);
	obj.src = img.src;
	obj.style.width = img.width;
	obj.style.height = img.height;
	document.getElementById("PhotoHref").href = arrImg[id];
	for(var i=0 ; i<arrImg.length ; i++)
		document.getElementById("num"+i).className = null;
	document.getElementById("num"+id).className ="actNum";
	curPage = id;
}
function ConvertImg()
{
	var nextPage;
	if( curPage < arrImg.length-1 )
		nextPage = curPage+1;
	else
		nextPage = 0;
	autoChgImg(nextPage);
}