/*!
 *
 * Copyright (c) 2010 TIEBUSA DESIGN (http://www.tiebusa.com)
 *
 *
 * Global items v1.1
 * Last update: Frederick Yau 20100812;
 *
 */
var ie = document.all ? true : false;
var isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
var loc = document.location.toString();	
var isEnglish = !!!(loc.search("/eng/")+1);	

var switchLanguage=function(){	
	alert("Coming Soon!");
	return;
//	if(isEnglish){
//		document.location = loc.replace("/jp/","/eng/");
//	} else {
//		document.location = loc.replace("/eng/","/jp/");
//	}
}

/*** tbsfader *******************************************************************/
var tbsfader=function(){
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 900;
	var speed = 3;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){				
				tt = document.getElementById(v);					
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
			}
			tt.style.display = 'block';			
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				w = '1000px';	
				tt.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				tt.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tbsfader.fade(1)},timer);			
		},		
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tbsfader.fade(-1)},timer);
		}
	};
}();

var tbsfader1=function(){var id='tt1';var top=3;var left=3;var maxw=900;var speed=3;var timer=20;var endalpha=95;var alpha=0;var tt1,t,c,b,h;var ie=document.all?true:false;return{show:function(v,w){if(tt1==null){tt1=document.getElementById(v);tt1.style.opacity=0;tt1.style.filter='alpha(opacity=0)'}tt1.style.display='block';tt1.style.width=w?w+'px':'auto';if(!w&&ie){w='1000px';tt1.style.display='none';tt1.style.width=tt1.offsetWidth;tt1.style.display='block'}if(tt1.offsetWidth>maxw){tt1.style.width=maxw+'px'}h=parseInt(tt1.offsetHeight)+top;clearInterval(tt1.timer);tt1.timer=setInterval(function(){tbsfader1.fade(1)},timer)},fade:function(d){var a=alpha;if((a!=endalpha&&d==1)||(a!=0&&d==-1)){var i=speed;if(endalpha-a<speed&&d==1){i=endalpha-a}else if(alpha<speed&&d==-1){i=a}alpha=a+(i*d);tt1.style.opacity=alpha*.01;tt1.style.filter='alpha(opacity='+alpha+')'}else{clearInterval(tt1.timer);if(d==-1){tt1.style.display='none'}}},hide:function(){clearInterval(tt1.timer);tt1.timer=setInterval(function(){tbsfader1.fade(-1)},timer)}}}();var tbsfader2=function(){var id='tt2';var top=3;var left=3;var maxw=900;var speed=3;var timer=20;var endalpha=95;var alpha=0;var tt2,t,c,b,h;var ie=document.all?true:false;return{show:function(v,w){if(tt2==null){tt2=document.getElementById(v);tt2.style.opacity=0;tt2.style.filter='alpha(opacity=0)'}tt2.style.display='block';tt2.style.width=w?w+'px':'auto';if(!w&&ie){w='1000px';tt2.style.display='none';tt2.style.width=tt2.offsetWidth;tt2.style.display='block'}if(tt2.offsetWidth>maxw){tt2.style.width=maxw+'px'}h=parseInt(tt2.offsetHeight)+top;clearInterval(tt2.timer);tt2.timer=setInterval(function(){tbsfader2.fade(1)},timer)},fade:function(d){var a=alpha;if((a!=endalpha&&d==1)||(a!=0&&d==-1)){var i=speed;if(endalpha-a<speed&&d==1){i=endalpha-a}else if(alpha<speed&&d==-1){i=a}alpha=a+(i*d);tt2.style.opacity=alpha*.01;tt2.style.filter='alpha(opacity='+alpha+')'}else{clearInterval(tt2.timer);if(d==-1){tt2.style.display='none'}}},hide:function(){clearInterval(tt2.timer);tt2.timer=setInterval(function(){tbsfader2.fade(-1)},timer)}}}();
/*** End of tbsfader *******************************************************************/


function openNav() {
 var e = document.getElementById('mainnav');
 if (e) {
	 e.className = 'opennav';
 }
}
function closeNav() {
 var e = document.getElementById('mainnav');
 e.className = 'closenav';
}
function buildTop() {
	//alert('buildTop() ');
	var flashvars = {};
	flashvars.path = path;
	flashvars.xmlPath = path+'xml/';
	flashvars.imagePath = path+'images/';
	flashvars.swfPath = path+'images/swf/';
	flashvars.section = section;
	
	var params = {};
	params.allowscriptaccess = "always";
	params.wmode = "transparent";
	var attributes = {};
	attributes.id = "mainnavflash";	
	swfobject.embedSWF(flashvars.swfPath + "nav.swf?v=0.01", "mainnavflash", "100%", "100%", "9.0.0", false, flashvars, params, attributes);
}
function buildCommonProductBar() {
	//alert('buildTop() ');
	if (section == '4' && subsection == "1") {		
		var e = document.getElementById('commonprodbarflash');
		e.style.display = 'none';
		e = document.getElementById('productbarh1');
		e.style.display = 'none';
		return;
	}
	var flashvars_cpb = {};
	flashvars_cpb.path = path;
	flashvars_cpb.xmlPath = path+'xml/';
	flashvars_cpb.imagePath = path+'images/';
	flashvars_cpb.swfPath = path+'images/swf/';
	flashvars_cpb.section = section;
	
	var params_cpb = {};
	params_cpb.allowscriptaccess = "always";
	params_cpb.wmode = "transparent";
	var attributes_cpb = {};
	attributes_cpb.id = "commonprodbarflash";
	swfobject.embedSWF(flashvars_cpb.swfPath + "commonprodbar.swf?v=0.01", "commonprodbarflash", "948", "160", "9.0.0", false, flashvars_cpb, params_cpb, attributes_cpb);
}
function buildHomeScreen() {
	// buildHomeScreen is for only Home swf.
	//alert('buildTop() ');
	var flashvars_hb = {};
	flashvars_hb.path = path;
	flashvars_hb.xmlPath = path+'xml/';
	flashvars_hb.imagePath = path+'images/';
	flashvars_hb.swfPath = path+'images/swf/';
	flashvars_hb.section = section;
	
	var params_hb = {};
	params_hb.allowscriptaccess = "always";
	params_hb.wmode = "transparent";
	var attributes_hb = {};
	attributes_hb.id = "mainscreen";
	swfobject.embedSWF(flashvars_hb.swfPath + "homescreen.swf?v=0.01", "mainscreen", "1000", "373", "9.0.0", false, flashvars_hb, params_hb, attributes_hb);
}
function buildSubLevelScreen() {
	try {
		var flashvars_sb = {};
		flashvars_sb.path = path;
		flashvars_sb.xmlPath = path+'xml/';
		flashvars_sb.imagePath = path+'images/';
		flashvars_sb.swfPath = path+'images/swf/';
		flashvars_sb.section = section;
		if (numsection) {
			flashvars_sb.numsection = numsection;
		}
		var params_sb = {};
		params_sb.allowscriptaccess = "always";
		params_sb.wmode = "transparent";
		var attributes_sb = {};
		attributes_sb.id = "mainscreen";
		swfobject.embedSWF(flashvars_sb.swfPath + "subscreen.swf?v=0.01", "mainscreen", "1000", "373", "9.0.0", false, flashvars_sb, params_sb, attributes_sb);
	} catch (e) {}
}
function buildMainScreen() {
	if (section != "0") {
		var tmpHtml = '';
		if (section.indexOf('.') > -1 ) {
			var sectionAry  = section.split('.')
			section = parseInt(sectionAry[0]);
			subsection = parseInt(sectionAry[1]);	
			if (subsection == NaN) { subsection = null;}	
		} else {
			section = parseInt(section);
			subsection = null;
		}
		if (subsection) {
			tmpHtml += '<img src="../images/screen/screen_'+ section +'_' + subsection + '.jpg" />';
			document.getElementById('mainscreen').innerHTML = tmpHtml;
			return;
		} else {
			if (section != "6") {
				buildSubLevelScreen();
			} else {
				tmpHtml += '<img src="../images/screen/screen_'+ section +'.jpg" />';
				document.getElementById('mainscreen').innerHTML = tmpHtml;
				return;
			}
			return;
		}		
	}
	buildHomeScreen();
}

function buildSideBar() {
	var tmpHtml = '';
	tmpHtml += '  <div class="widget first" id="sb-first"></div>';
	tmpHtml += '  <div class="widget" id="sb-contact">';
	tmpHtml += '    <h1><a href="../customer-service/online-enquiry.html?action=contactus" title="Ask GOOD VIEW." class="heading"><span>Ask Good View.</span></a></h1>';
	tmpHtml += '    <p>For fast, convenient and dedicated technical support, just send us an email.</p>';
	tmpHtml += '    <p><span class="email">sales@goodview.com.cn</span><br/><br/></p>';
	tmpHtml += '    <p><b>Hong Kong Office:</b></p>';
	tmpHtml += '    <p>Tel:    +852 2727 4484</p>';
	tmpHtml += '    <p>Fax:    +852 2772 7094 <br/>';
	tmpHtml += '    <p><b>China Factory:</b></p>';
	tmpHtml += '    <p>Tel:    +86 (769) 8541 1083</p>';
	tmpHtml += '    <p>Fax:    +86 (769) 8554 3255</p>';
	tmpHtml += '  </div>';
	tmpHtml += '  <!-- End of sb-contact -->';
	tmpHtml += '  <div class="widget" id="sb-downloads">';
	tmpHtml += '    <h1><a href="../about-us/downloads.html#slideshow" title="View our slideshow." class="heading"><span>View our slideshow.</span></a></h1>';
	tmpHtml += '    <p>Our slideshow contains up-to-date and substantial information about GOOD VIEW. Get quick understanding about us in the slideshow.</p>';
	tmpHtml += '  </div>';
	tmpHtml += '  <!-- End of sb-downloads -->  ';
	tmpHtml += '  <div class="widget" id="sb-catalogue">';
	tmpHtml += '    <h1><a href="../customer-service/get-the-catalogue.html#catalogue" title="Get the catalogue." class="heading"><span>Get the catalogue.</span></a></h1>';
	tmpHtml += '    <p>You may feel free to request a printed catalogue by post. Please fill in the form including your postal address.</p>';
	tmpHtml += '  </div>';
	tmpHtml += '  <!-- End of sb-catalogue -->';
	tmpHtml += '  <div class="widget" id="sb-visitus">';
	tmpHtml += '    <h1><a href="../customer-service/online-enquiry.html?action=visitus" title="Like to visit us?" class="heading"><span>Like to visit us?</span></a></h1>';
	tmpHtml += '    <p>To witness each production process, our modern equipment and the talented personnel, just make a prior appointment. We\'ll arrange an exclusive car travel for you directly to our manufacturing base.</p>';
	tmpHtml += '  </div>';
	tmpHtml += '  <!-- End of sb-visitus -->';
	tmpHtml += '  <div class="widget last" id="sb-last"></div>';
	var e = document.getElementById('sidebar');
	if (e) {
		e.innerHTML = tmpHtml;
	}
}
function buildShareBox() {
	var imagePath = '';
	if (section != "0") {
		// for home
		imagePath = '../';
	} 
	var tmpHtml = '';	
	tmpHtml += '<a href="javascript:closeShare();" onmouseover="javascript:closeShare();" class="shareback"></a>';
	tmpHtml += '<div class="sociableinner">';
	tmpHtml += '<a href="javascript:closeShare();" class="sociable_close">X</a>';
	tmpHtml += '<h1 class="sociable_tagline">';
	tmpHtml += 'Share GOOD VIEW with your friends!</h1>';
	tmpHtml += '<p><a title="Digg" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.goodview.com.cn" target="_blank" rel="nofollow"><img class="sociable-hovers" alt="Digg" title="Digg" src="' + imagePath + 'images/common/sociable_icon_digg.png"/></a><a title="del.icio.us" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.goodview.com.cn" target="_blank" rel="nofollow"><img class="sociable-hovers" alt="del.icio.us" title="del.icio.us" src="' + imagePath + 'images/common/sociable_icon_delicious.png"/></a><a title="Facebook" href="http://www.facebook.com/share.php?u=http%3A//www.goodview.com.cn&amp;t=GOOD VIEW IND CO LTD" target="_blank" rel="nofollow"><img class="sociable-hovers" alt="Facebook" title="Facebook" src="' + imagePath + 'images/common/sociable_icon_facebook.png"/></a><a title="Google" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.goodview.com.cn" target="_blank" rel="nofollow"><img class="sociable-hovers" alt="Google" title="Google" src="' + imagePath + 'images/common/sociable_icon_google.png"/></a><a title="Technorati" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.goodview.com.cn" target="_blank" rel="nofollow"><img class="sociable-hovers" alt="Technorati" title="Technorati" src="' + imagePath + 'images/common/sociable_icon_technorati.png"/></a><a title="TwitThis" href="http://twitter.com/home?status=http%3A%2F%2Fwww.goodview.com.cn" target="_blank" rel="nofollow"><img class="sociable-hovers" alt="TwitThis" title="TwitThis" src="' + imagePath + 'images/common/sociable_icon_twitter.png"/></a></p></div>';
	var e = document.getElementById('sharewebsite');
	if (e) {
		e.innerHTML = tmpHtml;
	}
}

function showContent() {	
	if (section != "0") {
		if (!ie) {
			tbsfader.show('post-content','601');
		}
	} else {			
		if (!isIE6) {
			var aTimer1 = window.setTimeout("tbsfader.show('threeboxesbox1','290')", 800);
			var aTimer2 = window.setTimeout("tbsfader1.show('threeboxesbox2','290')",1000);
			var aTimer3 = window.setTimeout("tbsfader2.show('threeboxesbox3','290')",1200);			
		}
	}
	
}
function preloadimages() { 
 if (document.images) { preload_image_object = new Image(); 
 image_url = []; image_url[0] = path+'images/common/sb-contact_h1_on.png';
 image_url[1] = path+'images/common/sb-downloads_h1_on.png'; image_url[2] = path+'images/common/sb-catalogue_h1_on.png'; image_url[3] = path+'images/common/sb-visitus_h1_on.png'; 
 var i = 0; for(i=0; i<=3; i++) preload_image_object.src = image_url[i];} 
}
function generic()
{
	if(section=="0"){if(ie&&!isIE6){var e=document.getElementById('threeboxesbox1');e.style.filter='alpha(opacity=0)';e=document.getElementById('threeboxesbox2');e.style.filter='alpha(opacity=0)';e=document.getElementById('threeboxesbox3');e.style.filter='alpha(opacity=0)'}else{var e=document.getElementById('threeboxesbox1');e.style.opacity=0;e=document.getElementById('threeboxesbox2');e.style.opacity=0;e=document.getElementById('threeboxesbox3');e.style.opacity=0}}else{if(!ie){var e=document.getElementById('post-content');e.style.opacity=0}}
	buildTop();
	buildMainScreen();
	buildSideBar();
	buildCommonProductBar();
	preloadimages();
	showContent();
	buildShareBox();	
};

//setup onload function
if(typeof window.addEventListener != 'undefined')
{
    //.. gecko, safari, konqueror and standard
    window.addEventListener('load', generic, false);
}
else if(typeof document.addEventListener != 'undefined')
{
    //.. opera 
    document.addEventListener('load', generic, false);
}
else if(typeof window.attachEvent != 'undefined')
{
    //.. win/ie
    window.attachEvent('onload', generic);
}

//** remove this condition to degrade older browsers
else
{
    //.. mac/ie5 and anything else that gets this far
    
    //if there's an existing onload function
    if(typeof window.onload == 'function')
    {
        //store it
        var existing = onload;
        
        //add new onload handler
        window.onload = function()
        {
            //call existing onload function
            existing();
            
            //call generic onload function
            generic();
        };
    }
    else
    {
        //setup onload function
        window.onload = generic;
    }
}


/*** Contact us Form  *******************************************************************/
function validateEmail(address) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;  
   if(reg.test(address) == false) {      
      return false;
   }
   return true;
}
function resetAllErr() {
	var e = document.getElementById('usernameerr');
	e.className = "missinghide";
	e = document.getElementById('emailerr');
	e.className = "missinghide";
	e = document.getElementById('telerr');
	e.className = "missinghide";	
	e = document.getElementById('countryerr');
	e.className = "missinghide";	
	e = document.getElementById('subjecterr');
	e.className = "missinghide";	
	e = document.getElementById('msgerr');
	e.className = "missinghide";	
}
function resetAllErr2() {
	var e = document.getElementById('usernameerr');
	e.className = "missinghide";
	e = document.getElementById('emailerr');
	e.className = "missinghide";
	e = document.getElementById('telerr');
	e.className = "missinghide";	
	e = document.getElementById('add1err');
	e.className = "missinghide";
	e = document.getElementById('cityerr');
	e.className = "missinghide";
	e = document.getElementById('countryerr');
	e.className = "missinghide";
}
function showError(elemStr) {
	var e = document.getElementById(elemStr);
	e.className = "missing";	
}
function get_time()
{
	var d = new Date();
	var t_date = d.getDate();     
	var t_mon = 1+d.getMonth();     
	var t_year = d.getFullYear();
	var c_hour = d.getHours();
	var c_min = d.getMinutes();
	var c_sec = d.getSeconds();
   var t = t_year +"-"+ t_mon +"-" + t_date + " " + c_hour + ":" + c_min + ":" + c_sec;
   return t;
}
function checking(){
	boolid=true;
	boolpwd=true;
	resetAllErr();
	if (document.formcontact.username.value=="") {
	   	showError('usernameerr');
		 document.formcontact.username.focus();
		 return false;
	}
	if (document.formcontact.email.value=="" || !validateEmail(document.formcontact.email.value)) {
   	   	 showError('emailerr');
		 document.formcontact.email.focus();
		 return false;
	}
	if (document.formcontact.tel.value=="") {
	   	   	showError('telerr');
		 document.formcontact.tel.focus();
		 return false;
	}
	if (document.formcontact.country.value=="") {
	   	   	showError('countryerr');
		 document.formcontact.country.focus();
		 return false;
	}
//	if (document.formcontact.subject.value=="") {
//	   	   	showError('subjecterr');
//		 document.formcontact.subject.focus();
//		 return false;
//	}
	if (document.formcontact.msg.value=="") {
	   	   	showError('msgerr');
		 document.formcontact.msg.focus();
		 return false;
	}
	if (boolid && boolpwd) {
		document.formcontact.clienttime.value = get_time();		
		document.formcontact.submit();
	}
}
/** Checking 2 is for validate get mailed catalogue **/
function checking2(){
	boolid=true;
	boolpwd=true;
	resetAllErr2();
	if (document.formcontact.username.value=="") {
	   	showError('usernameerr');
		 document.formcontact.username.focus();
		 return false;
	}
	if (document.formcontact.email.value=="" || !validateEmail(document.formcontact.email.value)) {
   	   	 showError('emailerr');
		 document.formcontact.email.focus();
		 return false;
	}
	if (document.formcontact.tel.value=="") {
	   	   	showError('telerr');
		 document.formcontact.tel.focus();
		 return false;
	}
	if (document.formcontact.add1.value=="") {
	   	   	showError('add1err');
		 document.formcontact.add1.focus();
		 return false;
	}
	if (document.formcontact.city.value=="") {
	   	   	showError('cityerr');
		 document.formcontact.city.focus();
		 return false;
	}
	if (document.formcontact.country.value=="") {
	   	   	showError('countryerr');
		 document.formcontact.country.focus();
		 return false;
	}
	
	if (boolid && boolpwd) {
		document.formcontact.clienttime.value = get_time();	
		document.formcontact.submit();
	}
}

/*** End of Contact us Form  *******************************************************************/
//if (isIE && document.execCommand)	document.execCommand('BackgroundImageCache', false, true);

function GetParam(name)
{
	var start=location.search.indexOf("?"+name+"=");
	if (start<0) start=location.search.indexOf("&"+name+"=");
 	if (start<0) return '';
 	start += name.length+2;
 	var end=location.search.indexOf("&",start)-1;
 	if (end<0) end=location.search.length;
 	var result=location.search.substring(start,end);
 	var result='';
 	for(var i=start;i<=end;i++)
 	{
 		var c=location.search.charAt(i);
 		result=result+(c=='+'?' ':c);
 	}
 	//alert(unescape(result));
 	return unescape(result);
}
var isSharewebsiteOpen = false;
function addBookmark() {
	var e = document.getElementById("sharewebsite");
	e.style.display = 'block';
	isSharewebsiteOpen = true;
}
function closeShare() {
	var e = document.getElementById("sharewebsite");
	e.style.display = 'none';
	isSharewebsiteOpen = false;
}
