var ie6;
var ie7;
var liveDomain = "isite-design.co.uk";
var theHost = document.location.hostname;

/*
function ajax_foo(){
	
	ajax = create_ajax();
	
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4 && ajax.status==200){
			response = ajax.responseText;
			response = ajax.responseXML;
		}
	}
	
	run_ajax(ajax,"POST","/_ajax/foo.php","foo="+bar);
	
}
*/

function load_function(){
	newwindow_links();
	browser_fixes();
	defaultText();
}

function include(filename)
{
	var theHead = document.getElementsByTagName("head")[0];
	
	var theScript = document.createElement("script");
	theScript.src = filename;
	theScript.type = "text/javascript";
	
	theHead.appendChild(theScript);
}

function create_ajax(){
	if (window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
	}
	else{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlhttp;
}

function run_ajax(obj,type,url,vars){
	if (type == "GET"){
		obj.open(type,url+"?"+vars);
		obj.send();
	}
	else{
		obj.open(type,url,true);
		obj.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		obj.send(vars);
	}
}

function newwindow_links(){
	var e = new Array();
	var i;
	e = document.getElementsByTagName("a");
	for(i=0;i<e.length;i++){
		if(e[i].className.indexOf("newwindow") > -1){
			e[i].target="_blank";
		}
	}
}

function follow_link(element){
	for(i = 0;element.childNodes[i]; i++ ){
	    if(element.childNodes[i].tagName == 'A'){ 
			window.location = element.childNodes[i].href; 
		}
	}
}

function add_control_rollovers(){

	var theTDs = getElementsByClassName("controls");
	
	for (i=0;i<theTDs.length;i++){
		var theImgs = theTDs[i].getElementsByTagName("img");
		for (j=0;j<theImgs.length;j++){
			img_name = theImgs[j].alt;
			theImgs[j].setAttribute("onmouseover","this.src='/_images/admin/controls/"+img_name+"_over.png'");
			theImgs[j].setAttribute("onmouseout","this.src='/_images/admin/controls/"+img_name+".png'");
		}
	}
	
}

function getElementsByClassName(class1){
	
	theElements = document.getElementsByTagName("*");
	
	theReturn = new Array();
	
	for (i=0;i<theElements.length;i++){
		if (theElements[i].className.indexOf(class1) > -1){
			theReturn.push(theElements[i]);
		}
	}
	
	return theReturn;
	
}

function browser_fixes(){
	if (ie6){
		var theInputs = document.getElementsByTagName("input");
		for (i=0;i<theInputs.length;i++){
			if (theInputs[i].type == "button" || theInputs[i].type == "submit"){
				theInputs[i].className += " ie6_button";
			}
		}
	}
}

function validate_email(str)
{
	apos = str.indexOf("@");
	dotpos = str.lastIndexOf(".");
	if (apos < 1 || dotpos - apos < 2){
		return false;
	}
	else{
		return true;
	}
}

function defaultText(){

	$(document).ready(function()
	{
	    $(".defaultText").focus(function(srcc)
	    {
	        if ($(this).val() == $(this)[0].title)
	        {
	            $(this).removeClass("defaultTextActive");
	            $(this).val("");
	        }
	    });
	    
	    $(".defaultText").blur(function()
	    {
	        if ($(this).val() == "")
	        {
	            $(this).addClass("defaultTextActive");
	            $(this).val($(this)[0].title);
	        }
	    });
	    
	    $(".defaultText").blur();  
		
		$("form").submit(function() {
			$(".defaultText").each(function() {
				if($(this).val() == this.title) {
					$(this).val("");
				}
			});
		});  
	});

}
