function toggle(whichOne) {
	
	if (document.getElementById(whichOne).style.display == 'none'){
		document.getElementById(whichOne).style.display = '';
		//document.getElementById('container').id = 'container_work' ;
	} else {
		document.getElementById(whichOne).style.display = 'none';
		//document.getElementById('container_work').id = 'container' ;
	}
}

function kill(whichOne) {
	var obj = document.getElementById(whichOne);
	obj.innerHTML = "";
}

//rollover function

function rollover(imgId,replaceImg) {
	//alert(replaceImg) ;
	document.images[imgId].src = replaceImg.src ;
}

function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}

function createRequestObject() {
	var req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
    
    return req ;
}

var http = createRequestObject(); // We create the HTTP Object 

/*== TITLE ===================================================================*/
function handleTitleHttpResponse() {
	if (http.readyState == 4) {
		if (http.responseText.indexOf('invalid') == -1) {
			document.getElementById("admin_title").innerHTML = '<a href="javascript:swapTitle();">'+http.responseText+'</a>' ;
		}
	}
}

function swapTitle(){
	var header = document.getElementById("admin_title") ;
	var title  = header.firstChild.firstChild.nodeValue ;
	var nodeID = document.getElementById("nodeID").firstChild.nodeValue ;
	
	header.innerHTML = '<form name="edit_title" method="" action="" style="margin:0; padding:0;"><input type="hidden" id="formID" value="'+nodeID+'" /><input type="text" id="new_title" value=\"'+title+'\" class="admin_title_edit" style="" /><input type="button" value="Save" onclick="editTitle();" style="font-size:11px;" /></form>' ;
}

function editTitle(){
	var nodeID = document.getElementById("formID").value ;
	var title  = document.getElementById("new_title").value ;
	
	var url = "/cms/action/edit_title.php?sectionName="+nodeID+"&title="; // The server-side script
	
	http.open("GET", url + escape(title), true) ;
	http.onreadystatechange = handleTitleHttpResponse ;
	http.send(null) ;
}

/*============================================================================*/


/*========= CONTACT US FORM VALIDATION =======================================*/
function chkvalid()
{
	
	if(document.forms.contactusform.first_name.value.length==0) {
		alert("Please enter your first name");
		document.forms.contactusform.first_name.focus();
		return false;
	}
	if(document.forms.contactusform.last_name.value.length==0) {
		alert("Please enter your last name");
		document.forms.contactusform.last_name.focus();
		return false;
	}
	if(document.forms.contactusform.company.value.length==0) {
		alert("Please enter your company");
		document.forms.contactusform.company.focus();
		return false;
	}
	if(document.forms.contactusform.position.value.length==0) {
		alert("Please enter your position");
		document.forms.contactusform.position.focus();
		return false;
	}
	if(document.forms.contactusform.email_address.value.length==0) {
		alert("Please enter your email address");
		document.forms.contactusform.email_address.focus();
		return false;
	}
	if(document.forms.contactusform.home_phone.value.length==0 && document.forms.contactusform.work_phone.value.length==0 && document.forms.contactusform.cell_phone.value.length==0) {
		alert("Please enter a phone number");
		document.forms.contactusform.home_phone.focus();
		return false;
	}
	if(document.forms.contactusform.best_time.options[document.getElementById("best_time").selectedIndex].text == "--Select Option--") {
		alert("Please enter the best time to contact");
		document.forms.contactusform.best_time.focus();
		return false;
	}
	if(document.forms.contactusform.address.value.length==0) {
		alert("Please enter an address");
		document.forms.contactusform.address.focus();
		return false;
	}
	if(document.forms.contactusform.city.value.length==0) {
		alert("Please enter a city");
		document.forms.contactusform.city.focus();
		return false;
	}
	if(document.forms.contactusform.state.options[document.getElementById("state").selectedIndex].text == "--") {
		alert("Please enter a state");
		document.forms.contactusform.state.focus();
		return false;
	}
	if(document.forms.contactusform.zip.value.length==0) {
		alert("Please enter a zip code");
		document.forms.contactusform.zip.focus();
		return false;
	}			
}

