// EXTERNAL WINDOW SCRIPT

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;

// IMAGE PRELOAD SCRIPT

if (document.images)
{
  pic1= new Image(150,262); 
  pic1.src="images/logo.gif"; 

  pic2= new Image(146,54); 
  pic2.src="images/euobj.jpg"; 

  pic3= new Image(146,36); 
  pic3.src="images/tcbc_logo.gif"; 

  pic4= new Image(284,25); 
  pic4.src="images/phone.gif"; 

  pic5= new Image(3000,748); 
  pic5.src="images/bg.gif";

  pic6= new Image(80,15); 
  pic6.src="images/icon_xhtml.gif";

  pic7= new Image(80,15); 
  pic7.src="images/icon_xhtml.gif";

  pic8= new Image(80,15); 
  pic8.src="images/icon_css.gif";

  pic9= new Image(80,15); 
  pic9.src="images/icon_firefox.gif";

  pic10= new Image(200,60); 
  pic10.src="images/priNav_tab.gif";

  pic11= new Image(200,60); 
  pic11.src="images/priNav_hover.gif";

  pic12= new Image(150,100); 
  pic12.src="images/secNav_hover.gif";

  pic13= new Image(160,40); 
  pic13.src="images/product_box_down.gif";

  pic14= new Image(160,40); 
  pic14.src="images/product_box_up.gif";
}
//-->

// GENERAL FORM SCRIPTS

function goTo( url ) {
	window.location = url;
}

function hideField( fieldId ) {
	document.getElementById( fieldId ).style.display = "none";
}

function isEmailAddress( field ) {
	if ( field == null ) { return false; }
	var emailRegex = /^[a-zA-Z0-9_%-]+(\.[a-zA-Z0-9_%-]+)*@[a-zA-Z0-9_%-]+(\.[a-zA-Z0-9_%-]+)+$/;
	return field.value.match( emailRegex ) != null;
}

function isEmpty( field ) {
	return field != null ? ( field.value.length <= 0 || field.value == null ) : true;
}

function isAlpha( field ) {
	if ( field == null ) { return false; }
	var alphaRegex = /^[a-zA-Z_%-]*$/;
	return field.match( alphaRegex ) != null;
}

function isAlphaNumeric( field ) {
	if ( field == null ) { return false; }
	var alphaNumericRegex = /^[a-zA-Z0-9_%-]*$/;
	return field.match( alphaNumericRegex ) != null;
}

function isNumeric( field ) {
	if ( field == null ) { return false; }
	var numericRegex = /^[0-9]*$/;
	return field.match( numericRegex ) != null;
}

function isTextField( field ) {
	return field != null ? ( field.type == "text" || field.type == "textarea" ) : false;
}

function showField( fieldId ) {
	document.getElementById( fieldId ).style.display = "block";
}

function stripNonNumeric( field ) {
	return field != null ? field.value.replace( /[\D]/g, '' ) : null;
}

function stripWhiteSpace( field ) {
	return field != null ? field.value.replace( /\s*/g, '' ) : null;
}

function toggleShowField( fieldId ) {
	var field = document.getElementById( fieldId );
	if ( field.style.display == "none" ) {
		field.style.display = "block";
	} else if ( field.style.display == "block" ) {
		field.style.display = "none";
	}
}

function trim( field ) {
	return field != null ? field.value.replace( /^\s*|\s*$/g, '' ) : null;
}

function trimFields( form ) {
	if ( form != null ) {
			with( form ) {
			for ( x in form.elements ) {
				var element = form.elements[x];
				if ( isTextField( element ) && !isEmpty( element ) ) {
					element.value = trim( element );
				}
			}
		}
	}
}

// Change text size function

function resizeText(multiplier) {  
if (document.body.style.fontSize == "") {  
document.body.style.fontSize = "1.0em"; }  
document.body.style.fontSize = parseFloat(document.body.style.fontSize) + (multiplier * 0.2) + "em"; } 

function otherTitle() {
	var otherTitle = document.getElementById( 'other_title_span' );
	var title = document.getElementById( 'title' );
	otherTitle.style.display = title.value == "Other" ? "block" : "none";
}

// TABLE STRIPE FUNCTION

var stripe = function() {
  var tables = document.getElementsByTagName("table");  

  for(var x=0;x!=tables.length;x++){
    var table = tables[x];
    if (! table) { return; }
    
    var tbodies = table.getElementsByTagName("tbody");
    
    for (var h = 0; h < tbodies.length; h++) {
      var even = true;
      var trs = tbodies[h].getElementsByTagName("tr");
      
      for (var i = 0; i < trs.length; i++) {
        
        if(even)
          trs[i].className += " even";
        
        even = !even;
      }
    }
  }
}

window.onload = stripe;

// Simple JavaScript Rotating Banner Using jQuery
// www.mclelun.com
var jqb_vCurrent = 0;
var jqb_vTotal = 0;
var jqb_vDuration = 5000;
var jqb_intInterval = 0;
var jqb_vGo = 1;
var jqb_vIsPause = false;
var jqb_tmp = 20;
var jqb_title;
var jqb_imgW = 460;
var jqb_imgH = 250;

jQuery(document).ready(function() {	
	jqb_vTotal = $(".jqb_slides").children().size() -1;
	$(".jqb_info").text($(".jqb_slide").attr("title"));	
	jqb_intInterval = setInterval(jqb_fnLoop, jqb_vDuration);
			
	//Horizontal
	$("#jqb_object").find(".jqb_slide").each(function(i) { 
		jqb_tmp = ((i - 1)*jqb_imgW) - ((jqb_vCurrent -1)*jqb_imgW);
		$(this).animate({"left": jqb_tmp+"px"}, 500);
	});
	
	/*
	//Vertical
	$("#jqb_object").find(".jqb_slide").each(function(i) { 
		jqb_tmp = ((i - 1)*jqb_imgH) - ((jqb_vCurrent -1)*jqb_imgH);
		$(this).animate({"top": jqb_tmp+"px"}, 500);
	});
	*/
	
	$("#btn_pauseplay").click(function() {
		if(jqb_vIsPause){
			jqb_fnChange();
			jqb_vIsPause = false;
			$("#btn_pauseplay").removeClass("jqb_btn_play");
			$("#btn_pauseplay").addClass("jqb_btn_pause");
		} else {
			clearInterval(jqb_intInterval);
			jqb_vIsPause = true;
			$("#btn_pauseplay").removeClass("jqb_btn_pause");
			$("#btn_pauseplay").addClass("jqb_btn_play");
		}
	});
	$("#btn_prev").click(function() {
		jqb_vGo = -1;
		jqb_fnChange();
	});
		
	$("#btn_next").click(function() {
		jqb_vGo = 1;
		jqb_fnChange();
	});
});

function jqb_fnChange(){
	clearInterval(jqb_intInterval);
	jqb_intInterval = setInterval(jqb_fnLoop, jqb_vDuration);
	$([window, document]).focusin(function(){
if(jqb_vIsPause == true) {
jqb_intInterval = setInterval(jqb_fnLoop, jqb_vDuration);
jqb_vIsPause = false;
}
}).focusout(function(){
clearInterval(jqb_intInterval);
jqb_vIsPause = true;
});
	jqb_fnLoop();
}

function jqb_fnLoop(){
	if(jqb_vGo == 1){
		jqb_vCurrent == jqb_vTotal ? jqb_vCurrent = 0 : jqb_vCurrent++;
	} else {
		jqb_vCurrent == 0 ? jqb_vCurrent = jqb_vTotal : jqb_vCurrent--;
	}
	
			
	$("#jqb_object").find(".jqb_slide").each(function(i) { 
		if(i == jqb_vCurrent){
			jqb_title = $(this).attr("title");
			$(".jqb_info").animate({ opacity: 'hide', "left": "-50px"}, 250,function(){
				$(".jqb_info").text(jqb_title).animate({ opacity: 'show', "left": "0px"}, 500);
			});
		} 
			
			
		//Horizontal Scrolling
		jqb_tmp = ((i - 1)*jqb_imgW) - ((jqb_vCurrent -1)*jqb_imgW);
		$(this).animate({"left": jqb_tmp+"px"}, 500);
		
		
		/*
		//Vertical Scrolling
		jqb_tmp = ((i - 1)*jqb_imgH) - ((jqb_vCurrent -1)*jqb_imgH);
		$(this).animate({"top": jqb_tmp+"px"}, 500);
		*/
		
		/*
		//Fade In & Fade Out
		if(i == jqb_vCurrent){
			$(".jqb_info").text($(this).attr("title"));
			$(this).animate({ opacity: 'show', height: 'show' }, 500);
		} else {
			$(this).animate({ opacity: 'hide', height: 'hide' }, 500);
		}
		*/
		
	});


}
