// Function to get the AJAX object
function getXMLHttpObject(){
	var xmlHttp;
 	try {   
  		// Firefox, Opera 8.0+, Safari    
    	xmlHttp=new XMLHttpRequest();
    	return xmlHttp;    
    }catch (e){   
    	// Internet Explorer    
    	try	{      
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    		return xmlHttp;      
    	}catch (e){      
    		try {        
    			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    			return xmlHttp;        
    		}catch (e){        
    			alert("Your browser does not support AJAX!");        
    			return false;        
    		}      
    	}    
    }
}

function drillDown(menuId,catId,jobId,displayId){
	var xmlHttp = getXMLHttpObject(); 
  	try{
  		if(xmlHttp == false){
  			return;
  		}
  	}catch(e){
  		return false;
  	}
	    xmlHttp.onreadystatechange=function()
    {
      if(xmlHttp.readyState==4){
      	var response = xmlHttp.responseText;
		document.getElementById("maincontent").innerHTML=response;
      }
    }
   	var queryString = "menuId="+menuId+"&catId="+catId+"&jobId="+jobId+"&displayId="+displayId;
	xmlHttp.open("POST","/cweb/servlet/JobServlet",true);
   	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   	xmlHttp.send(queryString);
}

function apply(jobId,jobCode){
	window.location = "/cweb/careers/submit-your-resume.do?id="+jobId+"&code="+jobCode;
}

function setPreferences(){
	document.outsourceForm.demoVal.value = document.outsourceForm.demo.checked; 
	document.outsourceForm.refVal.value = document.outsourceForm.references.checked;
	document.outsourceForm.meetingVal.value = document.outsourceForm.meeting.checked;
}

function displayNextStep(){
	var nextStep;
	for(i=0;i<document.siteMapForm.siteOption.length;i++){
		if(document.siteMapForm.siteOption[i].checked == true){
			nextStep = document.siteMapForm.siteOption[i].value;
		}	
	}
	if(nextStep == "scratch"){
		document.getElementById("smapTool").style.display = 'block';
		document.getElementById("smap").style.display = 'block';
	}else if(nextStep == "existing"){
	 	document.getElementById("urlTool").style.display = 'block';
	 	document.getElementById("smap").style.display = 'block';
	 	addURL();
	}
	document.getElementById("webQuestion1").style.display = 'none';
}
function websiteQuestion1(){
	document.getElementById("smapTool").style.display = 'none';
	document.getElementById("smap").style.display = 'none';
	document.getElementById("urlTool").style.display = 'none';
	document.getElementById("webQuestion1").style.display = 'block';
}
function addURL(){
	var xmlHttp = getXMLHttpObject(); 
  	try{
  		if(xmlHttp == false){
  			return;
  		}
  	}catch(e){
  		return false;
  	}
	    xmlHttp.onreadystatechange=function()
    {
      if(xmlHttp.readyState==4){
      	var response = xmlHttp.responseText;
		document.getElementById("smap").innerHTML=response;
      }
    }
    var url = document.siteMapForm.url.value;
    document.siteMapForm.url.value = "";
   	var queryString = "url="+url;
	xmlHttp.open("POST","/cweb/servlet/SiteMapServlet",true);
   	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   	xmlHttp.send(queryString);
}

function freeRankRequest(){
	var websiteURL = document.seoRequestForm.webURL.value;
	var keywords = document.seoRequestForm.keywords.value;
	var name = document.seoRequestForm.name.value;
	var email = document.seoRequestForm.email.value;
	var xmlHttp = getXMLHttpObject(); 
  	try{
  		if(xmlHttp == false){
  			return;
  		}
  	}catch(e){
  		return false;
  	}
	    xmlHttp.onreadystatechange=function()
    {
      if(xmlHttp.readyState==4){
      	var response = xmlHttp.responseText;
		alert(response);
		var status = xmlHttp.getResponseHeader("reqSatus");
		if(status == "success"){
			document.seoRequestForm.webURL.value = "";
			document.seoRequestForm.keywords.value = "";
			document.seoRequestForm.name.value = "";
			document.seoRequestForm.email.value = "";
		}
      }
    }
   	var queryString = "webURL="+encodeURIComponent(websiteURL)+"&keywords="+encodeURIComponent(keywords)+"&name="+encodeURIComponent(name)+"&email="+encodeURIComponent(email);
	xmlHttp.open("POST","/cweb/servlet/SEORankingServlet",true);
   	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   	xmlHttp.send(queryString);
}

function outsourcingQuestion(){
	var nextStep;
	for(i=0;i<document.question.R1.length;i++){
		if(document.question.R1[i].checked == true){
			nextStep = document.question.R1[i].value;
		}	
	}
	if(nextStep == "yes"){
		window.location = "/cweb/services/outsourcing-request.do";
	}else{
		alert("Thank you for taking the time to review our capabilities. Please look into our other service areas and products to see if they might be of interest to you.");
	}		
}
// Removes leading whitespaces
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}
// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}
// Removes leading and ending whitespaces
function trim( value ) {
	return LTrim(RTrim(value));
}