﻿// JScript File

function SetCwinHeight(obj)   
{   
        var cwin=obj;   
        if (document.getElementById)   
        {   
                var iHeight;
                        if (cwin.contentDocument  && cwin.contentDocument.body.offsetHeight){
                                //alert('1.offsetHeight' + cwin.contentDocument.body.offsetHeight);
                                //cwin.height = cwin.contentDocument.body.offsetHeight;  
                                iHeight = cwin.contentWindow.document.getElementById('country').offsetHeight + 200;
                        }
                        else if(cwin.Document && cwin.Document.body.scrollHeight)
                        {   
                                //alert('1.scrollHeight'+cwin.Document.body.scrollHeight);
                                //cwin.height = cwin.Document.body.scrollHeight;
                                iHeight = cwin.Document.body.scrollHeight;
                         }
                //alert(iHeight);
                if (iHeight < 600){
	                iHeight = 600;
	            }
	            
	            cwin.style.height = iHeight +'px';
        }   
}   

function SetProductNewsHeight(obj)   
{   
        var cwin=obj;   
        if (document.getElementById)   
        {   
                var iHeight=400;
                        if (cwin.contentDocument  && cwin.contentDocument.body.offsetHeight){
                                //alert('1.offsetHeight' + cwin.contentDocument.body.offsetHeight);
                                //cwin.height = cwin.contentDocument.body.offsetHeight;  
                                iHeight = cwin.contentWindow.document.getElementById('c3news').offsetHeight;
                        }
                        else if(cwin.Document && cwin.Document.body.scrollHeight)
                        {   
                                //alert('1.scrollHeight'+cwin.Document.body.scrollHeight);
                                //cwin.height = cwin.Document.body.scrollHeight;
                                iHeight = cwin.Document.body.scrollHeight;
                         }
                //alert(iHeight);
                if (iHeight < 400){
	                iHeight = 400;
	            	}
	            //alert(iHeight);
	            
	            //cwin.style.height = iHeight +'px';
	            document.getElementById('c3news').style.height = iHeight +'px';
        }   
}

//Javascript 換圖片
function domRollover() {
	if (navigator.userAgent.match(/Opera (\S+)/)) {
		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}
	if (!document.getElementById||operaVersion <7) return;
	var imgarr=document.getElementsByTagName('img');
	var imgPreload=new Array();
	var imgSrc=new Array();
	var imgClass=new Array();
	//alert(imgarr.length);
	for (i=0;i<imgarr.length;i++){
	
		if (imgarr[i].className.indexOf('domroll')!=-1){
		    
			imgSrc[i]=imgarr[i].getAttribute('src');
			imgClass[i]=imgarr[i].className;
			imgPreload[i]=new Image();
			if (imgClass[i].match(/domroll (\S+)/)) {
				imgPreload[i].src = imgClass[i].match(/domroll (\S+)/)[1]
			}
			imgarr[i].setAttribute('xsrc', imgSrc[i]);
			imgarr[i].onmouseover=function(){
				this.setAttribute('src',this.className.match(/domroll (\S+)/)[1])
			}
			imgarr[i].onmouseout=function(){
				this.setAttribute('src',this.getAttribute('xsrc'))
			}
		}
	}
}

//'1.檢查是否有該物件
//'2.判斷日期是否OK
function IsValidVariable(Variable){
    try{
        eval(Variable);
        return   true;
    }
    catch(e){
        return   false;
    }
}

function ok_date(startdatestring,enddatestring){
    var startdate;
    var enddate;
    if(IsValidVariable(startdatestring) == true){startdate = eval(startdatestring)};
    if(IsValidVariable(enddatestring) == true){enddate = eval(enddatestring)};
    var thisDate = new Date();
    var returnBoolean = false;
    if(typeof(startdate) != 'undefined' && typeof(enddate) != 'undefined'){
         if(startdate < thisDate && enddate > thisDate){
            returnBoolean = true;
         }
    }else if(typeof(startdate) != 'undefined' && typeof(enddate) == 'undefined'){
         if(startdate < thisDate){
            returnBoolean = true;
         }
    }else if(typeof(startdate) == 'undefined' && typeof(enddate) != 'undefined'){
         if(enddate > thisDate){
            returnBoolean = true;
         }
    }else if(typeof(startdate) == 'undefined' && typeof(enddate) == 'undefined'){
         returnBoolean = true;
    }
    return returnBoolean;
}




