/*!
 *
 * 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(){	
	if(isEnglish){
		document.location = loc.replace("/jp/","/eng/");
	} else {
		document.location = loc.replace("/eng/","/jp/");
	}
}


function tbs_Animate_menu(){
$("#navmenuh a").removeAttr("title"); // flickering bug fix
$("#navmenuh ul ").css({display: "none"}); // Opera Fix
$("#navmenuh li").hover(function(){
	$(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(200);
},function(){
	$(this).find('ul:first').css({visibility: "hidden"});
});
}


function buildTop() {
//	alert('buildTop() is called');
tmpHtml = '';
tmpHtml += '  <li><a href="'+path+'about/about.html">About DIGITEX</a>';
tmpHtml += '    <ul>';
tmpHtml += '  <li><a class="current" href="'+path+'about/managementphilosophy.html">Management Philosophy</a></li>';
tmpHtml += '  <li><a href="'+path+'about/qualityphilosophy.html">Quality Philosophy</a></li>';
tmpHtml += '  <li><a href="'+path+'about/tobethebestpartner.html">To Be The Best Partner</a></li>';
tmpHtml += '  <li><a href="'+path+'about/betterthantheleader.html">Better than the Leader</a></li>';
tmpHtml += '  <li><a href="'+path+'about/internationalpartners.html">International Partners</a></li>';
tmpHtml += '  <li><a href="'+path+'about/certification.html">Certification</a></li>';
tmpHtml += '  <li><a href="'+path+'about/contactus.html">Contact us</a></li>';
tmpHtml += '  <li class="last">&nbsp;</li>';
tmpHtml += '</ul>';
tmpHtml += '  </li>';
tmpHtml += '  <li><a href="'+path+'product/product.html">Product</a>';
tmpHtml += '<ul>';
tmpHtml += '      <li><a href="'+path+'product/printers.html">Printers</a></li>';
tmpHtml += '      <li><a href="'+path+'product/ink.html">Inks</a></li>';
tmpHtml += '      <li><a href="'+path+'product/media.html">Media</a></li>';
tmpHtml += '      <li><a href="'+path+'product/spareparts.html">Spare Parts</a></li>';
tmpHtml += '  	  <li class="last">&nbsp;</li>';
tmpHtml += '    </ul>';
tmpHtml += '  </li>';
tmpHtml += '  <li><a href="'+path+'support/technicalsupport.html">Technical Support</a>';
tmpHtml += '	</li>';
tmpHtml += '  <li><a href="'+path+'dgcommunities/communities.html">Communities</a></li>';
$("#navmenuh").html(tmpHtml);
if (!isIE6) { tbs_Animate_menu(); }
return;
}
function buildBread() {
	if (section == '1') {
		var tmpHtml = '';
		tmpHtml += '<a href="../about/about.html">About DIGITEX</a> \\ ';
		for (var i=0; i < quicknav.length; i++) {
			if (subsection == i) {
				tmpHtml += quicknav[i].caption;
				break;
			} else if (subsection == null ) {
				tmpHtml += quicknav[0].caption;
				break;
			}
		}
		var e = document.getElementById('bread');
		if (e) {
			e.innerHTML = tmpHtml;
			return
		}
	} else if (section == '2') {		
		var tmpHtml = '';
		tmpHtml += '<a href="../product/product.html">Product</a> \\&nbsp;&nbsp;';
		for (var i=0; i < productnav.length; i++) {			
			if (subsection-1 == i) {				
				tmpHtml += '<a href="../product/'+ productnav[i].link +'">'+productnav[i].caption+'</a>';
				if (productnav[i].subnav) {
					for (var j=0; j < 1+productnav[i].subnav.length; j++) {
						if (subsubsection-1 == j) {
							tmpHtml += ' \\&nbsp;&nbsp;' + productnav[i].subnav[j].caption;
							
						}
					}
				}
			}
		}
		var e = document.getElementById('bread');
		if (e) {
			e.innerHTML = tmpHtml;
			return
		}
	}
}
function buildFeatureBar() {
	//alert('buildFeatureBar() ');
	var flashvars_feab = {};
	flashvars_feab.path = path;
	flashvars_feab.xmlPath = path+'xml/';
	flashvars_feab.imagePath = path+'images/';
	flashvars_feab.swfPath = path+'images/swf/';
	flashvars_feab.section = section;
	
	var params_feab = {};
	params_feab.allowscriptaccess = "always";
	params_feab.wmode = "transparent";
	var attributes_feab = {};
	attributes_feab.id = "featurebarflash";
	swfobject.embedSWF(flashvars_feab.swfPath + "featurebar.swf?v=0.01", "featurebar", "936", "110", "9.0.0", false, flashvars_feab, params_feab, attributes_feab);
}
function buildHomeScreen() {
	// buildHomeScreen is for only Home swf.
	//alert('buildHomeScreen() ');
	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;}	
			subsubsection = parseInt(sectionAry[2]);	
			if (subsubsection == NaN) { subsubsection = null;}	
		} else {
			section = parseInt(section);
			subsection = null;
		}
		if (subsection) {
			if (section != '2') {
			tmpHtml += '<img src="../images/screen/screen_'+ section + '.jpg" />';
			} else {
				if (((section == '2') && (subsection == '1') && (subsubsection == '1')) ||
				((section == '2') && (subsection == '1') && (subsubsection == '2')) ||
				((section == '2') && (subsection == '1') && (subsubsection == '3')) ||
				((section == '2') && (subsection == '2') && (subsubsection == '1')) ||
				((section == '2') && (subsection == '2') && (subsubsection == '2')) ||
				((section == '2') && (subsection == '2') && (subsubsection == '3')) ||
				((section == '2') && (subsection == '4') && (subsubsection == '1')) ||
				((section == '2') && (subsection == '4') && (subsubsection == '2')) ||
				((section == '2') && (subsection == '4') && (subsubsection == '3'))) {
					tmpHtml += '<img src="../images/screen/screen_'+ section +'_' + subsection + '_'+ subsubsection + '.jpg" />';
				} else {
					tmpHtml += '<img src="../images/screen/screen_'+ section +'_' + subsection + '.jpg" />';
				}
			}
			document.getElementById('mainscreen').innerHTML = tmpHtml;
			return;
		} else {
			tmpHtml += '<img src="../images/screen/screen_'+ section + '.jpg" />';
			document.getElementById('mainscreen').innerHTML = tmpHtml;
			return;
		}		
	}
	buildHomeScreen();
}

function buildQuickNav() {
var tmpHtml = '';
var i = 0;

var isCurrentStr = ''; var found=false;
tmpHtml += '<div class="quicknav" id="quicknav"><div class="quicknavinner">';
tmpHtml += '<h1><a href="about.html" title="About DIGITEX" class="heading"><span>About DIGITEX</span></a></h1>';
tmpHtml += '<ul>';
for (var i=0; i < quicknav.length; i++) {
	if (subsection == i) {
		isCurrentStr = ' class="current"'; 
	} else {
		isCurrentStr = '';		
	}	
	tmpHtml += '  <li><a title="'+quicknav[i].caption+'" href="'+quicknav[i].link +'"'+isCurrentStr+'>'+ quicknav[i].caption+'</a></li>';
}
tmpHtml += '</ul>';
tmpHtml += '  </div></div>';
tmpHtml += '  <!-- End of quicknav -->';	
var e = document.getElementById('sidebar1');
if (e) {
	e.innerHTML = tmpHtml;
}
}

function buildSideBar() {
	if (section == '1') {
		buildQuickNav();
		return;
	}
	/* type1 , no sidebar */
	if (section == '2' && subsection== null) {
		// product
		$('#content').removeClass('grid_6');
		$('#content').removeClass('column');
		$('#content').css({'width':'922px'});
		return;
	}
	if (section == '3' && subsection == null) {
		$('#content').removeClass('grid_6');
		$('#content').removeClass('column');
		return;
	}
	if (section == '2' && subsection == '3') {
		// spare parts
		$('#content').removeClass('grid_6');
		$('#content').removeClass('column');		
		return;
	}	
	if (section == '3' && subsection == '2') {
		// download
		$('#content').removeClass('grid_6');
		$('#content').removeClass('column');
		return;
	}	
	if (section == '2' && level != '3') {
		return;
	}	
//	alert('buildSideBar()' + subsection + '_'  + subsubsection);
	if(typeof(subsubsection) == "undefined"){ 
		return;
	}
	var rand = Math.floor(Math.random() * 5 + 0.5);
	var tmpHtml = '';
	tmpHtml += ' <div class="widget" id="sb-brochure">';
	tmpHtml += '   <h1><a href="../support/download.html#book1" title="Download Brochure" class=""><img src="../images/common/sb_bro_'+subsection+'_'+subsubsection+'.jpg" /></a></h1>';
	tmpHtml += ' </div>';
	tmpHtml += ' <!-- End of sb-catalogue -->';
	tmpHtml += ' <div class="widget" id="sb-download">';
	tmpHtml += '   <h1><a href="../support/download.html" title="Download Center" class=""><i>Download Center</i></a></h1>';
	tmpHtml += '    <table class="basictable" style="width:220px;">';
	tmpHtml += '    <tbody>';
//	tmpHtml += '      <tr class="odd">';
//	tmpHtml += '        <td width="180"><a href="../support/download.html#">Drive</a></td>';
//	tmpHtml += '        <td width="40"><a href="../support/download.html#">pdf</a></td>';
//	tmpHtml += '      </tr>';
	tmpHtml += '      <tr class="odd">';
	tmpHtml += '        <td><a href="../support/download.html#icc">ICC Profile</a></td>';
	tmpHtml += '        <td><a href="../support/download.html#icc">pdf</a></td>';
	tmpHtml += '      </tr>';
//	tmpHtml += '      <tr class="odd">';
//	tmpHtml += '        <td><a href="../support/download.html#">User Guide</a></td>';
//	tmpHtml += '        <td><a href="../support/download.html#">pdf</a></td>';
//	tmpHtml += '      </tr>';
	tmpHtml += '      <tr>';
	tmpHtml += '        <td height="21"><a href="../support/download.html#ink">Ink Conversion Guide</a></td>';
	tmpHtml += '        <td><a href="../support/download.html#ink">pdf</a></td>';
	tmpHtml += '      </tr>';
	tmpHtml += '      <tr class="odd">';
	tmpHtml += '        <td height="21"><a href="../support/download.html#msds">MSDS Report</a></td>';
	tmpHtml += '        <td><a href="../support/download.html#msds">pdf</a></td>';
	tmpHtml += '      </tr>';
	tmpHtml += '    </tbody>';
	tmpHtml += '  </table>';
	tmpHtml += '  <a href="../support/download.html" title="More Downloads" class="small button"><i>More Downloads...</i></a>';
	tmpHtml += ' </div>';
	tmpHtml += ' <!-- End of sb-downloads -->  ';
	tmpHtml += ' <div class="widget last" id="sb-last">&nbsp;</div>';
	var e = document.getElementById('sidebar2');
	if (e) {
		e.innerHTML = tmpHtml;
	}
}
function buildShareBox() {
	return;
}
function buildBottom() {
	var tmpHtml = '';
	var showHideDiv = '';
	if (section == 3) {
		showHideDiv = ' style="display:none;" ';
	}
	tmpHtml += '	<div class="backtotop"><a href="#root"><i>Back to Top</i></a></div>';
	tmpHtml += '	<ul class="foursupportboxes" '+ showHideDiv +'>';
	tmpHtml += '    	<li class="foursupportboxes-single blog_button">';
	tmpHtml += '        	<a href="'+path+'dgcommunities/communities.html"><i>DG blog</i></a>';
	tmpHtml += '    	</li>';
	tmpHtml += '    	<li class="foursupportboxes-single fb_button">';
	tmpHtml += '        	<a href="http://www.facebook.com/pages/Digitex-Printing-Technologies-Co-Ltd/102630743106585?v=app_2373072738" target="_blank"><i>facebook</i></a>';
	tmpHtml += '    	</li>';
	tmpHtml += '		<li class="foursupportboxes-single yt_button">';
	tmpHtml += '        	<a href="http://www.youtube.com/user/digitextechnology" target="_blank"><i>youtube</i></a>';
	tmpHtml += '    	</li>';
	tmpHtml += '        <li class="foursupportboxes-single download_button">';
	tmpHtml += '        	<a href="'+path+'support/download.html#download"><i>download</i></a>';
	tmpHtml += '    	</li>';
	tmpHtml += '    </ul> <!-- end of foursupportboxes -->';
	tmpHtml += '	<div id="copyright">';
	tmpHtml += '		<p>Copyright &copy; <a href="../index.html" title="home">Digitex Printing Technologies Co., Ltd</a> All rights reserved.<br />Powered by <a href="http://tiebusa.com" title="TIEBUSA DESIGN" target="_blank">TIEBUSA DESIGN</a>.</p>';
	tmpHtml += '	</div>';
	tmpHtml += '    <div id="footernav">';
	tmpHtml += '    <a target="_self" href="'+path+'home/sitemap.html" title="sitemap">Sitemap</a> |';
	tmpHtml += '    <a target="_self" href="'+path+'about/contactus.html" title="Contact Us">Contact Us</a> |';
	tmpHtml += '    <a target="_self" href="'+path+'dgcommunities/category/news/" title="News">News</a> |';
	tmpHtml += '    <a target="_self" href="'+path+'dgcommunities/warranty-registration/" title="Warranty Registration">Warranty Registration</a>';
	tmpHtml += '    <br /><a target="_self" href="'+path+'home/disclaimer.html" title="News">Disclaimer</a> |';
	tmpHtml += '    <a target="_self" href="'+path+'home/privacy.html" title="Privacy">Privacy</a> |';
	tmpHtml += '    <a target="_self" href="'+path+'home/copyright.html" title="Warranty Registration">Copyright</a>';
	tmpHtml += '    </div>';
	$("#footer").html(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() { 
return;
 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];} 
}


/* use for social Widget */
function relative_time(_0x8401x1){var _0x8401x2=_0x8401x1["\x73\x70\x6C\x69\x74"]("\x20");_0x8401x1=_0x8401x2[1]+"\x20"+_0x8401x2[2]+"\x2C\x20"+_0x8401x2[5]+"\x20"+_0x8401x2[3];var _0x8401x3=Date["\x70\x61\x72\x73\x65"](_0x8401x1);var _0x8401x4=(arguments["\x6C\x65\x6E\x67\x74\x68"]>1)?arguments[1]: new Date();var _0x8401x5=parseInt((_0x8401x4["\x67\x65\x74\x54\x69\x6D\x65"]()-_0x8401x3)/1000);_0x8401x5=_0x8401x5+(_0x8401x4["\x67\x65\x74\x54\x69\x6D\x65\x7A\x6F\x6E\x65\x4F\x66\x66\x73\x65\x74"]()*60);var _0x8401x6="";if(_0x8401x5<60){_0x8401x6="\x61\x20\x6D\x69\x6E\x75\x74\x65\x20\x61\x67\x6F";} else {if(_0x8401x5<120){_0x8401x6="\x63\x6F\x75\x70\x6C\x65\x20\x6F\x66\x20\x6D\x69\x6E\x75\x74\x65\x73\x20\x61\x67\x6F";} else {if(_0x8401x5<(45*60)){_0x8401x6=(parseInt(_0x8401x5/60)).toString()+"\x20\x6D\x69\x6E\x75\x74\x65\x73\x20\x61\x67\x6F";} else {if(_0x8401x5<(90*60)){_0x8401x6="\x61\x6E\x20\x68\x6F\x75\x72\x20\x61\x67\x6F";} else {if(_0x8401x5<(24*60*60)){_0x8401x6=""+(parseInt(_0x8401x5/3600)).toString()+"\x20\x68\x6F\x75\x72\x73\x20\x61\x67\x6F";} else {if(_0x8401x5<(48*60*60)){_0x8401x6="\x31\x20\x64\x61\x79\x20\x61\x67\x6F";} else {_0x8401x6=(parseInt(_0x8401x5/86400)).toString()+"\x20\x64\x61\x79\x73\x20\x61\x67\x6F";} ;} ;} ;} ;} ;} ;return _0x8401x6;} ;
function get_youtube_feed(feedPath) {		
	$.get('proxy.php?url='+feedPath, function(d) {			
		$(d).find('item').each(function(index, item) {
			if ( index == 3 ) return false;
			
			//name the current found item this for this particular loop run
			var $item = $(this);
			var title = $item.find('title').text();
			var link = $item.find('link').text();
			var description = $item.find('description').text();
			var pubDate = $item.find('pubDate').text();
			var html = "<div class=\"entry\"><h2 class=\"postTitle\">" + title + "<\/h2>";
			html += "<em class=\"date\">" + pubDate + "</em>";
			html += "<p class=\"description\">" + description + "</p>";
			//html += "<a href=\"" + link + "\" target=\"_blank\">Read More >><\/a><\/div>";
			html += "<\/div>";
			$('#youtube').append($(html));					
		});
	}); 			
};
function get_blog_feed(feedPath) {		
	//$.get($('#diffFeeds').val(), function(d) {
	$.get('include/proxy.php?url='+feedPath, function(d) {
	//$.get('http://www.digitex.hk/eng/dgcommunities/?feed=rss2', function(d) {
		
		$(d).find('item').each(function() {
			
			//name the current found item this for this particular loop run
			var $item = $(this);
			var title = $item.find('title').text();
			var link = $item.find('link').text();
			var description = $item.find('description').text();
			var pubDate = $item.find('pubDate').text();
			var html = "<li class=\"entry\"><a href=\"" + link + "\" target=\"_blank\"><span class=\"postTitle\">" + title + "<\/span><\/a><\/li>";			
			//$('#dgblog ul').append($(html));
			$('#dgblog').append($('<ul>'+html+'</ul>'));
		});
	}); 			
};

function get_news_feed(feedPath) {		
	// alert('get_news_feed');
	return;
	$.get('include/proxy.php?url='+feedPath, function(d) {
		
		$(d).find('item').each(function() {
			
			//name the current found item this for this particular loop run
			var $item = $(this);
			var title = $item.find('title').text();
			var link = $item.find('link').text();
			var description = $item.find('description').text();
			var pubDate = $item.find('pubDate').text();
			var imgthumb = $item.find('content\\:encoded').text();			

			var img_src  = '';

			img_src = 'dgcommunities/wp-content/themes/dg-tbscms/images/default_post_thumb.jpg';
			//var html = "<li><a href=\"" + link + "\" ><img src=\"" +img_src  +"\" width=\"92\" height=\"64\" /> <h2>" + title + "<\/h2>"+ description +"<\/a><\/li>";			
			//var html = "<li><a href=\"" + link + "\" ><h2>" + title + "<\/h2>"+ description +"<\/a><\/li>";			
			//$('#dgblog ul').append($(html));
			$('#news').append($(html));
		});
	}); 			
};


var currentTabNum = -999;
var currentTabAry = [{tab:"#fb_tab",content:"#tabcontent-fb"},
					 {tab:"#blog_tab",content:"#tabcontent-blog"},
					 {tab:"#tw_tab",content:"#tabcontent-tw"}];
	
	
function changeTab(tabNum) {

	$(currentTabAry[currentTabNum].tab).parent().removeClass("current");
	$(currentTabAry[currentTabNum].content).css("display", "none");	
	currentTabNum = tabNum;	
	$(currentTabAry[currentTabNum].tab).parent().addClass("current");
	$(currentTabAry[currentTabNum].content).css("display", "block");

}

function buildHomeSocialWidget() {
	if (section != '0') {
		return;
	}
	
	$("#fb_tab").click(function(event){
		changeTab(currentTabNum);
	});
	$("#blog_tab").click(function(event){
		changeTab(currentTabNum);
	});
	$("#twitter_tab").click(function(event){
		changeTab(currentTabNum);
	});
	currentTabNum = Math.floor(Math.random()*3+0.5);
	currentTabNum = (currentTabNum>=2)?2:currentTabNum;
	changeTab(currentTabNum);
	
	return;
	
	// get Twitter
	$.getJSON('http://twitter.com/status/user_timeline/119994349.json?count=10&callback=?', function(data){ // total number of tweets
	$.each(data, function(index, item){
	$('#twitter').append('<div class="tweet">' + item.text + '<br /><strong>' + relative_time(item.created_at) + '</strong></div>');
	});
	});
	
	// get Flickr
	$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?ids=48080924@N03&lang=en-us&format=json&jsoncallback=?", function(data){
	$.each(data.items, function(index, item){
	if ( index == 16 ) return false;
	var sourceSquare = (item.media.m).replace("_m.jpg", "_s.jpg");
	//var sourceSquare = item.media.m;
	$("<img class='flickrimg' />").attr("src", sourceSquare).appendTo("#flickr")
	.wrap("<a href='" + item.link + "'><span></span></a>");
	});
	});
	
	get_youtube_feed("http://gdata.youtube.com/feeds/base/users/digitextechnology/uploads?alt=rss&v=2&orderby=published&client=ytapi-youtube-profile");
	//get_blog_feed("http://www.digitex.hk/eng/dgcommunities/?feed=rss2");
	//get_news_feed("http://www.digitex.hk/eng/dgcommunities/?feed=rss2%26cat=1");
	// make the tab can click
	$("#fb_tab").click(function(event){
		changeTab(currentTabNum);
	});
	$("#blog_tab").click(function(event){
		changeTab(currentTabNum);
	});
	$("#twitter_tab").click(function(event){
		changeTab(currentTabNum);
	});
	currentTabNum = Math.floor(Math.random()*3+0.5);
	currentTabNum = (currentTabNum>=2)?2:currentTabNum;
	changeTab(currentTabNum);
}

if (section == '2') {
	if (!window.level) {
		window.level = 0;
		var level = 0;
	}
}
var curProdTabNum = -999
var productTabAry = [{tab:"#product_tab1",content:"#tabpage1"},
			 {tab:"#product_tab2",content:"#tabpage2"},
			 {tab:"#product_tab3",content:"#tabpage3"},
			 {tab:"#product_tab4",content:"#tabpage4"}];

function changeHeight(eStr, tabNum) {
	var heightAry = [50, 200, 1000];
	$(eStr).height(heightAry[1+tabNum]);
	$(eStr).parent().height(heightAry[1+tabNum]);
	$(eStr).parent().parent().height(heightAry[1+tabNum]);
}
	
function changeProductTab(tabNum) {
//	var tmpStr = 'curProdTabNum = '  + curProdTabNum + ' ;' +currentTabAry[curProdTabNum].tab + '\n currentTabAry[curProdTabNum].content = '+ currentTabAry[curProdTabNum].content + ' \ntabNum = '  + tabNum + '; \ncurProdTabNum = ' + curProdTabNum;

	$(productTabAry[curProdTabNum].tab).parent().removeClass("current");
	$(productTabAry[curProdTabNum].content).css("display", "none");	
	
	$(productTabAry[tabNum].tab).parent().addClass("current");
	$(productTabAry[tabNum].content).css("display", "block");
	//changeHeight(productTabAry[tabNum].content, tabNum);
	curProdTabNum = tabNum;	
	
//	tmpStr += '\n\n\curProdTabNum = '  + curProdTabNum + ' ;' +currentTabAry[curProdTabNum].tab + '\n currentTabAry[curProdTabNum].content = '+ currentTabAry[curProdTabNum].content + ' \ntabNum = '  + tabNum + '; \ncurProdTabNum = ' + curProdTabNum;
	//alert(tmpStr);
}


/*** buildProductPageTab  *******************************************************************/
function buildProductPageTab() {	
	if (section != '2') {
		return 
	}
	if (window.level != '3' ) {
		return 
	}	
// alert('buildProductPageTab is call() ');
	$(".product-tabpage").each(function() { $(this).css({display: "none"}) });
	$(".product-tabpage:first-child").css({display: "block"});
	
	// make the tab can click
	$("#product_tab1").click(function(event){
	 	if ( curProdTabNum == 0) return;
		changeProductTab(0);
	});
	$("#product_tab2").click(function(event){
		if ( curProdTabNum == 1) return;
		changeProductTab(1);
	});
	$("#product_tab3").click(function(event){
		if ( curProdTabNum == 2) return;
		changeProductTab(2);
	});
	$("#product_tab4").click(function(event){
		if ( curProdTabNum == 3) return;
		changeProductTab(3);
	});
	
	curProdTabNum = 0;
	$(productTabAry[curProdTabNum].tab).parent().addClass("current");
}

/*** 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);
}
$(document).ready(function() {						   

	buildTop();
	buildMainScreen();
	buildFeatureBar();
			
	buildBottom();
	buildHomeSocialWidget();
	buildBread();
	buildProductPageTab();
	buildSideBar();
	//preloadimages();
	
	//showContent();
});

function clearInput(field_id, term_to_clear) {
	if (document.getElementById(field_id).value == term_to_clear ) {
		document.getElementById(field_id).value = '';
	}
	else if (document.getElementById(field_id).value == '' ) {
		document.getElementById(field_id).value = term_to_clear;
	}
}

