var preloadImages = new Array("/images/radio.jpg","/images/radio-checked.jpg","/images/radio-hover.jpg","/images/checkbox.jpg","/images/checkbox-checked.jpg")    
 
function loadImages() {   
     for (i = 0; i < preloadImages.length; i++) {   
         var preImages = new Image()  
         preImages.src = preloadImages[i]  
	}
}


function checkDomainName(){

	var dstring = document.getElementById('domain').value;
	if (dstring.match(/[^a-zA-Z0-9]/) || dstring == ""){
		
		document.getElementById('domainalert').innerHTML = "<h3>Sorry that is not a valid domain name</h3><p>Domain names can only contain letter or numbers";
		document.getElementById('domainalert').parentNode.style.display = 'block';
		return false;
	}
	else{
		document.getElementById('domainalert').innerHTML = "<h3>Thank You, Checking...</h3>";
		return true;
	}


}
function checkEmailAddress(){

	var dstring = document.getElementById('email').value;
	if (dstring.match(/[^a-zA-Z0-9]/) || dstring == ""){
		
		document.getElementById('emailalert').innerHTML = "<h3>Sorry that is not a valid email address</h3><p>Emails can only contain letter or numbers";
		document.getElementById('emailalert').parentNode.style.display = 'block';
		return false;
	}
	else{
		document.getElementById('emailalert').innerHTML = "<h3>Thank You, Checking...</h3>";
		return true;
	}


}

function checkRadios(name,exclude){
	var inputs = document.getElementsByTagName('input');
		for (var c = 0; c < inputs.length; c++){
			if (inputs[c].type == 'radio' && inputs[c].name == name && inputs[c].id != exclude){
				var check = inputs[c].getAttributeNode("checked"); 
				inputs[c].removeAttribute('checked');
				var num = inputs[c].id.substring(5);
				document.getElementById('rad'+num).setAttribute('class','radradio');
			}
		}
}

function styleInputs(){

	var types = new Array('input','textarea','select');
	var st = 1;
	for (var d = 0; d < types.length; d++){
		var inputs = document.getElementsByTagName(types[d]);
		
		for (var c = 0; c < inputs.length; c++){
			if (inputs[c].type == 'image'){
				inputs[c].style.width = "auto";
				inputs[c].style.height = "auto";
				inputs[c].style.minHeight = "0";
				inputs[c].className += " input-image";
				inputs[c].value = "Submit Form";
				inputs[c].alt = "Submit Form";
			}
			if (inputs[c].type != 'image' && inputs[c].type != 'checkbox' && inputs[c].type != 'radio'){		
				inputs[c].style.border = "#dddddd solid 1px";
				inputs[c].style.borderTopColor = "#a5a5a5";
				//inputs[c].style.background = "url(/images/input-shadow.gif) scroll repeat-x top left";
				if (types[d] == 'input'){ 
					if (inputs[c].className != 'nohighlight'){
						inputs[c].onfocus = function(){
							this.style.backgroundColor = "#F8F8EF";}		
						inputs[c].onblur = function(){
							this.style.backgroundColor = "#fff";}		
					}
				}
			}
			
			if (inputs[c].type == 'radio'){
				inputs[c].setAttribute('id','radio'+st)
				inputs[c].style.display = "none";
				var checkname = inputs[c].getAttribute('name');
				var rad = document.createElement('img');
				rad.setAttribute('class','radradio');
				rad.className = 'radradio';
				rad.setAttribute('src','/images/clear.gif')
				if(inputs[c].checked){
					rad.setAttribute('class','radradio-checked');
					rad.className = 'radradio-checked';
				}
				rad.setAttribute('id','rad'+st);
				rad.setAttribute('onclick',"this.setAttribute('class','radradio-checked');checkRadios('"+checkname+"','radio"+st+"');document.getElementById('radio"+st+"').setAttribute('checked','1')");
				rad.setAttribute('onmouseover',"if(this.className == 'radradio'){this.setAttribute('class','radradio-hover');}");
				rad.setAttribute('onmouseout',"if(this.className == 'radradio-hover'){this.setAttribute('class','radradio');}");
				inputs[c].parentNode.insertBefore(rad,inputs[c]);
				
				st++;	
			}
			if (inputs[c].type == 'checkbox'){
				inputs[c].setAttribute('id','checkbox'+st)
				inputs[c].style.display = "none";
				var checkname = inputs[c].getAttribute('name');
				var rad = document.createElement('img');
				rad.setAttribute('class','radcheckbox');
				rad.className = 'radcheckbox';
				rad.setAttribute('src','/images/clear.gif')
				if(inputs[c].checked){
					rad.setAttribute('class','radcheckbox-checked');
					rad.className = 'radcheckbox-checked';
				}
				rad.setAttribute('id','rad'+st);
				rad.setAttribute('onclick',"if (this.className != 'radcheckbox-checked'){ this.setAttribute('class','radcheckbox-checked');document.getElementById('checkbox"+st+"').setAttribute('checked','1');}else{this.setAttribute('class','radcheckbox');document.getElementById('checkbox"+st+"').removeAttribute('checked');}");
				rad.setAttribute('onmouseover',"if(this.className == 'radradio'){this.setAttribute('class','radcheckbox-hover');}");
				rad.setAttribute('onmouseout',"if(this.className == 'radradio-hover'){this.setAttribute('class','radrcheckbox');}");
				inputs[c].parentNode.insertBefore(rad,inputs[c]);
				
				st++;	
			}
			
			
			if(st > 1){
				loadImages();
			}
		}
	}
}

function styleTables(){
	
	var tables = document.getElementsByTagName('table');
		
		for (var i = 0; i < tables.length; i++){
	
			if (tables[i].className.match(/\btype-a\b/) || tables[i].className.match(/\btype-b\b/)){
				var rows = 	tables[i].getElementsByTagName('tr');
	
				var c = -1;
				
				for (var r = 0; r < rows.length; r++){
					var row = rows[r];
					if(c > -1){
						row.onmouseover = function(){this.orClass = this.className;this.className += " hover";}
						row.onmouseout = function(){this.className = this.orClass;}
					}else{
						row.className += " tanheader"
					}
					
					if(c == 1){
						row.className += " highlighted";
						c = 0;
					}else{
						c += 1;	
					}
					
						
				}
			}
		
		}
}

function styleList(){
	
	var list = document.getElementsByTagName('ul');
		
		for (var i = 0; i < list.length; i++){
	
			if (list[i].className.match(/\blist-b\b/)){
				var rows = 	list[i].getElementsByTagName('li');
	
				var c = 1;
				
				for (var r = 0; r < rows.length; r++){
					var row = rows[r];
										
					if(c == 1){
						row.className += " highlighted";;
						c = 0;
					}else{
						c += 1;	
					}
						
				}
			}
		
		}
}

function styleGoBar(){
	var divs = document.getElementsByTagName('div');
		
		for (var c = 0; c < divs.length; c++){
			
			if (divs[c].className.match(/\bgo-bar\b/)){
				divs[c].onmouseover = function(){this.orClass = this.className;this.className += " hover";}
				divs[c].onmouseout = function(){this.className = this.orClass;}
			}
		
		}
}

function dtbInit(){
	styleInputs();
	styleTables();
	styleList();
	styleGoBar();
	
}
