﻿// JScript File
function emailfriend(){

   var newhref=bupa_web_site_url+"/b5/contact_bupa/forward_friends.aspx?fromurl="+escape(window.location.href);
   window.location.href=newhref;



}
   var fontSize = 14;
   function print_onclick() {
        var bdhtml=window.document.body.innerHTML;
        //alert(bdhtml.length);//4619
        var sprnstart="<!--startprint-->";
        var sprnend="<!--endprint-->";
        //alert(bdhtml.indexOf(sprnstart)+17);//582
        var sprnhtml=bdhtml.substring(bdhtml.indexOf(sprnstart)+17,bdhtml.length);               
        //alert(sprnhtml.indexOf(sprnend));//3246
        sprnhtml=sprnhtml.substring(0,sprnhtml.indexOf(sprnend));
        /*open new page print
        window.document.body.innerHTML=sprnhtml;
        window.print();
        */              
        document.body.innerHTML = '<div style="width:600px">' + sprnhtml + '</div>'; 
        window.print();
        window.history.go(0);

    }
    function doZoom(size)
    {
        if(size != 0) fontSize = size + fontSize;
        else fontSize = 14;
        document.body.style.fontSize = fontSize + "px";
    } 
    function forwardtofriend(thisurl,getUri)
    {
        var sendMail=window.open("ForwardToFriend.html","告知好友","toolbar =no, menubar=no, scrollbars=no, resizable=no, location=no, status=no,width=300,height=120");
        sendMail.document.write("<html><head><style type='text/css'>body{font-size:14px;}</style></head><body><form method='get' action='" + 
                                getUri + "'>好友姓名:<input name='name' /><br/>好友郵箱:<input name='email' /><br/><input type='submit' value='發送'/>" +
                                "<input type='hidden' name='thisuri' value='" + thisurl + "' /></form></body></html>");
        sendMail.document.close();
    }
    


function jumphttps(url){
   var href=bupa_web_site_url_https+url;
   window.location.href=href;
   
}

function jumphttp(url){
     var href=bupa_web_site_url+url;
      window.location.href=href;


}

function pageToEn(){
    var lastURL=window.location.href;
    var newURL=lastURL.replace('/b5/','/en/');
    window.location.href=newURL;
}

function pageToB5(){
    var lastURL=window.location.href;
    var newURL=lastURL.replace('/en/','/b5/');
    window.location.href=newURL;
}    


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];}
}

// JScript File

			

function quickdoReset() {
	 document.getElementById("quickage").value="";
	 document.getElementById("error").innerHTML="";
 if(document.getElementById("quickbenefit"))
	 document.getElementById("quickbenefit").selectedIndex=0;
	 return false;
     
}


function quickcheckIsInteger(str) {
    if(str == "")
        return true;
    if(/^(\-?)(\d+)$/.test(str))
        return true;
    else
        return false;
}

function quickdoSubmit() {
	// Start check the age
	theAge =document.getElementById("quickage").value;
	//theError = document.getElementById("error");
    benefit=1;
	if(document.getElementById("quickbenefit"))          
	   benefit=document.getElementById("quickbenefit").selectedIndex+1;             
	else {
           
            if(document.getElementById("select")){
                 benefit=document.getElementById("select").selectedIndex+1;   
            }
        }
       
	href="";
    //alert(benefit);
	if(theAge != "" && quickcheckIsInteger(theAge)) {
		theAge = parseInt(theAge);
	
	   if(benefit <= 2 ){
		if(theAge >= 18 && theAge <= 100) {
		   href=bupa_web_site_url_https+"/b5/quickquote/Care_Pro_IQ.aspx?age="+theAge+"&benefit="+benefit;		  
		   window.location.href=href;
		   return ;		
		} else if (theAge > 100) {
		    alert("請輸入年齡在0和100之間。");	
		    document.getElementById("quickage").value=""; 	
		    document.getElementById("quickage").focus();
		} else if(theAge >=0) {
		    href=bupa_web_site_url_https+"/b5/quickquote/Care_Kid_IQ.aspx?age="+theAge+"&benefit="+benefit;		   
		    window.location.href=href;
		}else{
		    alert("請輸入年齡在0和100之間。");
		    document.getElementById("quickage").value="";
		    document.getElementById("quickage").focus(); 
			return ;
		
		}
		}else{
		
		
		    
         if(theAge >59) {
		       alert("此計劃為年屆59歲或以下人士而設。");
		       document.getElementById("quickage").value=""; 	
		       document.getElementById("quickage").focus();
		       return ;
		  } else if(theAge >=0) {
		      
		  } else{
		       alert("請輸入年齡在0和59之間。");
		       document.getElementById("quickage").value=""; 	
		       document.getElementById("quickage").focus();
			   return ;
		
		  }    
		  
		  
	      var sa =document.getElementById("sa").value;        
          if(sa != "" && quickcheckIsInteger(sa)) 
           {
                  
           }else{
           alert("請選擇保障金額。");
		   document.getElementById("sa").value=""; 	
		   document.getElementById("sa").focus();
		   return;
        
          }        
          sa=parseInt(sa);		  		  
		  if(sa >=200000 && sa<= 1500000) {	     
		   
		  } else{
		       alert("保障金額為港幣20萬至150萬。");
		       document.getElementById("sa").value=""; 	
		       document.getElementById("sa").focus();
			   return ;
		
		  }  
        
         var smoke ="no";
         href=bupa_web_site_url_https+"/b5/quickquote/CII.aspx?age="+theAge+"&sa="+sa+"&smoke="+smoke;
         
               		   
	     window.location.href=href;
		
		
	}
		
		
		
		
		
		
		
		
	} else {	
		 alert("請輸入年齡在0和100之間。");
		 document.getElementById("quickage").value=""; 
		 document.getElementById("quickage").focus();
		return;
	}

	
}



function index_quickquote_onchange(select){
      var tr1=document.getElementById("sa_tr_1");
      var tr2=document.getElementById("sa_tr_2");
      if(select.selectedIndex !=2 ){
         if(tr1.style){
           tr1.style.display="none";
           tr2.style.display="none";
         }else{
           tr1.display="none";
           tr2.display="none";
          }
      }else{
      
         if(tr1.style){
           tr1.style.display="";
           tr2.style.display="";
         }else{
           tr1.display="";
           tr2.display="";
          }
      
      
      
      
      }

}

function age_keypress(e){
  
   // get event if not passed
    if (!e) var e = window.event;
    // get character code of key pressed
    if (e.keyCode) numCharCode = e.keyCode;
    else if (e.which) numCharCode = e.which;
    if(numCharCode==13){
        quickdoSubmit();
        return false;
    }

}

function search_keypress(e,obj){
   if (!e) var e = window.event;
    // get character code of key pressed
    if (e.keyCode) numCharCode = e.keyCode;
    else if (e.which) numCharCode = e.which;
    if(numCharCode==13){
        search_submit(obj);
        return false;
    }
}
function search_submit(obj){
    var href=bupa_web_site_url+"/b5/searchInfo/index.aspx?q="+escape(obj.value);               		   
	window.location.href=href;

}

function replaceVideo(obj,divId,url){    
    document.getElementById(divId).innerHTML = "<object width='425' height='344'><param name='movie' value='"+url
    +"'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='"+url
    +"' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='425' height='344'></embed></object>";
    var objs = document.getElementsByTagName("div");
    
    for(i=0; i<objs.length;i++){   
       if(obj.className != "tvc_btn_contain tvc_current" && objs[i].className == "tvc_btn_contain tvc_current"){
            objs[i].className = "tvc_btn_contain";
            objs[i].style.background='url(\'images/tvc_btn.jpg\')';
            break;
        }
    }
    
    obj.className = "tvc_btn_contain tvc_current";    
}


function myOnmouseout(obj){
    if(obj.className == "tvc_btn_contain"){
        obj.style.background='url(\'images/tvc_btn.jpg\')';
    }
}