if (window.location.href.indexOf("convoy.com.hk")>=0) {
	if (window.location.protocol!="https:"){
		window.location.href = window.location.href.replace(window.location.protocol, "https:");
	}
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function PopupBlog(){

	OpenWindow("/Convoy%20Blog/blog.aspx", "ConvoyBlog",860, 820, "center", "middle", false, "scroll");

	/*var wind = window.open("/Convoy%20Blog/blog.aspx", "blog", "width=860, height=820, scrollbars=yes, status=yes");
	try {
		wind.focus();
	}catch(e){}
	*/
}

function SubmitSearch(param){
	var lang = GetParam("lang");

	if (lang=="")
		lang = "en-US";

	document.location.href="/Convoy/search.aspx?lang="+lang+"&q="+param;

}


function GetParam(key) {
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+key+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];

}

function resizeBlogThumbnailImage(obj){
	ResizeImage(obj, 120, 120, true);
}

function ResizeImage(image, setWidth, setHeight, enlarge) {

	var w,h,r,d,nw,nh;
	w = image.width;
	h = image.height;
	r = w/h;
	//alert(w + "X"+ h);

	if (r>=1&&(w>setWidth||enlarge)){
		/* too wide */
		d = setWidth/w;
		nw = setWidth;
		nh = Math.round(h*d);
	}else if(r<1&&(h>setHeight||enlarge)){
		/* too height */
		d = setHeight/h;
		nh = setHeight;
		nw = Math.round(w*d);
	}else {
		nw = w;
		nh = h;
	}
	image.style.width = nw+"px";
	image.style.height = nh+"px";

	//alert(image.style.width + "X"+ image.style.height + ", "+w+"X"+h+", r:"+r+", d:"+d);
}


function OpenWindow (url, name, width, height, xpos, ypos, chrome, scroll, resizable){
  var x, y, w, h, moveX=0, moveY=0, features="";
  chrome = chrome ? "yes" : "no";
  scroll = scroll ? "yes" : "no";
  resizable = resizable ? "yes" : "no";
  features += "toolbar="+chrome+",location="+chrome+",status="+chrome+",menubar="+chrome;
  features += ",scrollbars="+scroll+",resizable="+resizable;
  if(width) features += ",width="+width;
  if(height) features += ",height="+height;
  if(xpos && window.screen){
    w = window.screen.availWidth;
    width = parseInt(width);
    switch(xpos){
      case "left": x = 0; break;
      case "center": x = (w-width)/2; break;
      case "right": x = w-width; break;
      default: x = xpos;
    }
    features += ",screenX="+x+",left="+x;
    var moveX = x;
  }
  if(ypos && window.screen){
    h = window.screen.availHeight;
    height = parseInt(height);
    switch(ypos){
      case "top": y = 0; break;
      case "middle": y = (h-height)/2; break;
      case "bottom": y = h-height; break;
      default: y = ypos;
    }
    features += ",screenY="+y+",top="+y;
    var moveY = y;
  }
  features +=",left="+moveX+",top="+moveY;
	eval("openWinReference = window.open(url, name, features);");  
	openWinReference.focus();
}