// JavaScript Document

var LogInUserID;
var returnvalue;
var siteName;
var x;
var queryString


$(document).ready( function() {
	$('#leftNav').find('ul').each( function() {
		$(this).find('li:last').addClass('lastLi')
	}); // Close #leftNav -> UL -> li:last
	
	$('#toggle2').text(" [+] View Specifications");
	$('#toggle4').text(" [-] Hide Specifications");	
	$("#HiddenRows").hide();
	$("#toggle3").hide();
	$("#toggle4").hide();
	$('#toggle2').click(function(){
		$('#HiddenRows').toggle();
		$("#toggle1").toggle();
		$("#toggle2").toggle();
		$("#toggle3").toggle();
		$("#toggle4").toggle();
	});
	$('#toggle4').click(function(){
		$('#HiddenRows').toggle();
		$("#toggle1").toggle();
		$("#toggle2").toggle();
		$("#toggle3").toggle();
		$("#toggle4").toggle();
	});
}); // Close document.ready


	//Gets the browser specific XmlHttpRequest Object
	function getXmlHttpRequestObject() {
		if (window.XMLHttpRequest) {
			return new XMLHttpRequest(); //Not IE
		} else if(window.ActiveXObject) {
			return new ActiveXObject("Microsoft.XMLHTTP"); //IE
		} else {
			//Display your error message here. 
			//and inform the user they might want to upgrade
			//their browser.
			alert("Your browser doesn't support the XmlHttpRequest object.");
		}
	}

	//Get our browser specific XmlHttpRequest object.
	var receiveReq = getXmlHttpRequestObject();		
	//Initiate the asyncronous request.
	function isThisUserRegistered() {
			//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
		if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
			//Setup the connection as a GET call.
			//True explicity sets the request to asyncronous (default).
			receiveReq.open("GET", queryString, true);
				//Set the function that will be called when the XmlHttpRequest objects state changes.
			receiveReq.onreadystatechange = queryLinkedTables;
			//Make the actual request.
			receiveReq.send(null);
		}			
	}
	//Called every time our XmlHttpRequest objects state changes.
	function queryLinkedTables() {
		//Check to see if the XmlHttpRequests state is finished.

			if (receiveReq.readyState == 4) {
				//Set the contents of our span element to the result of the asyncronous call.
				//parse the response for the data that is required
				str = receiveReq.responseText;
//alert(queryString);

				if (str.indexOf('0M')!=-1){
					alert("Login  successful. \n \r In future we would like to log you in immediately, but there is one more step.\n\r Please enter your email address in the Create New Account - Email Address field and follow the prompts.");
					document.getElementById("createAccountEmail").focus();
				}else if (str.indexOf('M')!=-1){
					var x=window.confirm("Login  successful. \n \r  In future we would like to log you in immediately, but there is one more step.\n\r Please sign in with your website account")
					document.getElementById("SignInEmailAddress").focus();
				}else if (str.indexOf('L')!=-1){

					var varURL = location.href;
					switch(varURL)
					{
					case "http://dev.rd.labwrench.local/?members.signIn/":
//alert("Here1");
						window.location = "http://dev.rd.labwrench.local?members.signIn/&btnSave=1&linkedinStatus=true"
						break;
					case "http://dev.rd.medwrench.local/?members.signIn/":
//alert("Here2");
						window.location = "http://dev.rd.medwrench.local?members.signIn/&btnSave=1&linkedinStatus=true"
						break;
					case "http://staging.rd.labwrench.local/?members.signIn/":
//alert("Here3");
						window.location = "http://staging.rd.labwrench.local?members.signIn/&btnSave=1&linkedinStatus=true"
						break;
					case "http://staging.rd.medwrench.local/?members.signIn/":
//alert("Here4");
						window.location = "http://staging.rd.medwrench.local?members.signIn/&btnSave=1&linkedinStatus=true"
						break;
					case "http://www.labwrench.com/?members.signIn/":
//alert("Here5");
						window.location = "http://www.labwrench.com/?members.signIn/&btnSave=1&linkedinStatus=true"
						break;
					case "http://www.medwrench.com/?members.signIn/":
//alert("Here6");
						window.location = "http://www.medwrench.com/?members.signIn/&btnSave=1&linkedinStatus=true"

					default:
//alert("Here6");
						window.location = "http://www.labx.com"
					}
					//alert(varURL);

				}else{
//alert('Here');
					var x=window.confirm("Login  successful. \n \r In future we would like to log you in immediately, but there is one more step.\n\r Please enter your email address in the Create New Account - Email Address field and follow the prompts.")
					document.getElementById("SignInEmailAddress").focus();
				}
			}
	}


function readCookie(name) {

	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		//if (c.indexOf(nameEQ) == 0) alert(c.substring(0,c.length));
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function c(name) {
	createCookie(name,"",-1);
}






