/**
 * Portal V2.0 common js 
 */
function clearSelect(id)
{
  var sObj=document.getElementById(id);
 if ((sObj == undefined) || (sObj.tagName.toUpperCase() != "SELECT"))
 {
	 return;
 }

  for(var i=sObj.length;i>=0;i--)
  {
    sObj.options[i]=null;
  }
}
function setSelect(id,v)
{
  var sObj=document.getElementById(id);
  if ((sObj == undefined) || (sObj.tagName.toUpperCase() != "SELECT"))
  {
  return;
  }

  for(var i=0; i<sObj.length; i++)
  {
  	  if(sObj.options[i].value==v)
  	  {
  	  	sObj.options[i].selected=true;
  	  }
  }
}
function addSelectItem(id,txt,val,selected)
{
 var sObj=document.getElementById(id);
 if ((sObj == undefined) || (sObj.tagName.toUpperCase() != "SELECT"))
 {
	 return;
 }
 if(selected == undefined)
 {
	 selected=false;
 }
  var opt=new Option(txt,val,false,false);
  sObj.options[sObj.options.length]=opt;
  opt.selected=selected;
}

function getSingleSelectValueById(id){
  var obj=document.getElementById(id);
 if (obj==undefined)
 {
	  return null;
 }
  return obj.options[obj.selectedIndex].value;
}
function setCity(sv)
{
   var v=parseInt(getSingleSelectValueById("province"));
   clearSelect("city");
 if (v==null)
 {
	 addSelectItem("city","²»ÏÞ","0");
	 return;
 }
  
 var v=parseInt(v);
    var subObj=sublocation_array[v];
 if(subObj==undefined)
 {
	 return;
 }

  for(key in subObj)
 {
 	if(sv!=undefined && sv==key)
 	{
 		addSelectItem("city",subObj[key],key,true);
 	}else{
	    addSelectItem("city",subObj[key],key);
 	}
 }
}
function setSelectState(name,v){
  var chks = document.getElementsByName(name);	
  if(chks==undefined || chks.length<=0)
  {
  	  return;
  }
  
  for(var i=0; i<chks.length;i++)
  {
  	 chks[i].checked = v;
  }
}
function getCurrentDate(separator)
{
    var now=new Date();
 var m=(now.getMonth()+1)+'';
 var d=now.getDate()+'';
 m=((m.length==1)?('0'+m):m);
 d=((d.length==1)?('0'+d):d);
 if(separator==undefined){
   return now.getYear()+m+d;
 }
 return now.getYear()+separator+m+separator+d;
}
function getNextDate(separator)
{
    var now=new Date();
 var tmp=new Date(now.getYear(),now.getMonth(),now.getDate());

    var t=tmp.getTime()+24*3600*1000;
    var next=new Date(t);
    
 var m=(next.getMonth()+1)+'';
 var d=next.getDate()+'';
 
 m=((m.length==1)?('0'+m):m);
 d=((d.length==1)?('0'+d):d);
 
 if(separator==undefined){
   return next.getYear()+m+d;
 }
 
 return next.getYear()+separator+m+separator+d;
}
function Cookie(document, name, hours, path, domain, secure)
{
    this.$document = document;
    this.$name = name;
    if (hours)
        this.$expiration = new Date((new Date()).getTime() + hours*3600000);
    else this.$expiration = null;
    if (path) this.$path = path; else this.$path = null;
    if (domain) this.$domain = domain; else this.$domain = null;
    if (secure) this.$secure = true; else this.$secure = false;
}
Cookie.prototype.store = function () {
    var cookieval = "";
    for(var prop in this) {
        if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function')) 
            continue;
        if (cookieval != "") cookieval += '&';
        cookieval += prop + ':' + escape(this[prop]);
    }

    var cookie = this.$name + '=' + cookieval;
    if (this.$expiration)
        cookie += '; expires=' + this.$expiration.toGMTString();
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    if (this.$secure) cookie += '; secure';

    this.$document.cookie = cookie;
}
Cookie.prototype.load = function() { 
    var allcookies = this.$document.cookie;
    if (allcookies == "") return false;

    var start = allcookies.indexOf(this.$name + '=');
    if (start == -1) return false;   
    start += this.$name.length + 1;  
    var end = allcookies.indexOf(';', start);
    if (end == -1) end = allcookies.length;
    var cookieval = allcookies.substring(start, end);

    var a = cookieval.split('&');    
    for(var i=0; i < a.length; i++) 
        a[i] = a[i].split(':');
    
    for(var i = 0; i < a.length; i++) {
        this[a[i][0]] = unescape(a[i][1]);
    }
    return true;
}
Cookie.prototype.remove = function() {
    var cookie;
    cookie = this.$name + '=';
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
    this.$document.cookie = cookie;
}



function switch_tab(d)
{
	var index=parseInt(d);
	if(index < 0 && index > 3)
	{
      index = 0;
	}
	
	for(var ti=0;ti<=3;ti++)
	{
		if(index==ti){
	    document.getElementById("p"+ti).style.display = "block";
			document.getElementById("lbl_p"+ti).className = "nonce";	
		}else{
			document.getElementById("p"+ti).style.display = "none";
			document.getElementById("lbl_p"+ti).className = "";	
		}
	}
}

var isPollOne = true;
var pollVarOne = Math.floor(Math.random()*10)%4+1;
function setPollOne(v)
{
  isPollOne=v;
}

function pollPlayOne()
{
  if (isPollOne)
  {
	pollVarOne=pollVarOne%4;
	switch_tab(pollVarOne);
	pollVarOne++;
  }
  if ((pollVarOne%7) == 1)
  {
   setTimeout("pollPlayOne()",5000);
  }else{
   setTimeout("pollPlayOne()",4000);
  }
}



