// Search /////////////////////////////////////////////////////////////////////////
function initSearchField() {
	lpath=window.location+'';
	if (lpath.match("/en/")!=null) { defaultWord = "Search " }
	if (lpath.match("/tc/")!=null) { defaultWord = "搜尋 " }	
	if (lpath.match("/sc/")!=null) { defaultWord = "搜寻 " }
	
	if ($("#searchField").val() != defaultWord) {
		$("#searchField").css("color","#000");
	}
	
	$("#searchField").focus(function(){
		if ($("#searchField").val() == defaultWord) {
			$("#searchField").val("");
		}
		$("#searchField").css("color","#000");
	});

	$("#searchField").blur(function(){
		if ($("#searchField").val() == "") {
			$("#searchField").val(defaultWord);
			$("#searchField").css("color","#7b888e");
		}
	});
}
	
function searchGoogle() {
	theString = $("#searchField").val();
	if (theString!=defaultWord && theString!="") {
		document.location = "http://www.google.com/search?sitesearch=www.isi2013.hk&as_q=" + theString;
	}
}

// Left menu /////////////////////////////////////////////////////////////////////////
function initMenu() {
	if (pageID.indexOf("about")!=-1) {
		$("#menuAbout").css("display","block");
	}
}

function initSlides() {
	theNum  = 0;
	theNum1 = 0;
	slideArray = new Array('slide01', 'slide02', 'slide03', 'slide04', 'slide05', 'slide06', 'slide07', 'slide08', 'slide09');
	numSlides = slideArray.length;

	theNum = Math.floor(Math.random()*(numSlides));
	thePic = slideArray[theNum];
	$("#pic1").attr("src","../images/"+thePic+".jpg");
}

function slideSwitch() {  
  	theNum1 = theNum;
    if (theNum > numSlides-2) { theNum = 0 } else { theNum++ }
	thePic1 = slideArray[theNum1];
	$("#pic1").attr("src","../images/"+thePic1+".jpg");

    $('#pic1').fadeIn(800, function(){
	  thePic = slideArray[theNum];
      $("#pic" ).attr("src","../images/"+thePic+".jpg" );
	  $('#pic1').fadeOut(800);
	});
}

// Registration /////////////////////////////////////////////////////////////////////////
function winReg() {
	theWinReg = window.open('http://www.medcomhk.com/???/regist','local','scrollbars=yes, resizable=yes,menubar=no,toolbar=no, status=yes, width=798');
	theWinReg.focus();
}

function winAbs() {
	theWinAbs = window.open('http://www.medcomhk.com/???/abstract','local','scrollbars=yes, resizable=yes,menubar=no,toolbar=no, status=yes, width=798');
	theWinAbs.focus();
}

// Change language /////////////////////////////////////////////////////////////////////////
function getCookie(c_name) {
  var i,x,y,ARRcookies=document.cookie.split(";");
  for (i=0;i<ARRcookies.length;i++) {
    x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
    y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
    x=x.replace(/^\s+|\s+$/g,"");
    if (x==c_name) {
      return unescape(y);
    }
  }
}

function setCookie(c_name,value,expiredays) {
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toUTCString()+";path=/;");
}

function changeLang(fromLang,toLang) {
	setCookie("lang", toLang, 90);	
	x = window.location + '';
	x = x.replace( '/'+fromLang+'/', '/'+toLang+'/' );
	window.location.href = x;
}

function changeLangPath(fromLang,toLang) {
	x = window.location + '';
	x = x.replace( '/'+fromLang+'/', '/'+toLang+'/' );
	return x;
}


function popup(url) {
 params  = 'width='+screen.width;
 params += ', height='+screen.height;
 params += ', top=0, left=0'
 params += ', fullscreen=no';

 newwin=window.open(url,'videoWindow', params);
 if (window.focus) {newwin.focus()}
 return false;
}

