// JavaScript Document for pulling the customer data
// show the services
var xmlHttp
var strDashMatrix
var workElement

function confirmDelete(theURL) {
	 var where_to= confirm("This action cannot be undone. Are you sure you want to delete?\r\nClick \"OK\" to Delete, or \"CANCEL\" to cancel.");
	 if (where_to== true)
	 {
	   window.location = theURL;
	 }
}

function loadSecCode() {
	var dashMatrix = document.getElementById("Dasher").innerHTML;
	var url= dashMatrix + "includes/ajax/functions/getSecCode.asp?sid=" + Math.random() + "&DashMatrix=" + dashMatrix;
	strDashMatrix = dashMatrix
	workElement = "SecCode";
	xmlHttp=GetXmlHttpObject(postbackDisplay)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)	
}

function validateJobApp() {
	if(document.JobApp.authorize.checked == true) {
		return true;
	} else {
		alert("You must check to authorize");
		return false;
	}
}

function processLogin() {
	var dashMatrix = document.getElementById("Dasher").innerHTML;
	var FormID = document.login.formid.value;
	if(FormID == "partner") {
		document.login.action = "http://www.lesaint.com/members/login.asp?MemberLogin=true";//http://waretech.lesaint.com/ILSTPM/BypassUserSignon.aspx";
	} else {
		document.login.action = "supplierform";
	}
	document.login.submit();
}

function swapLogin(theVar) {
	var dashMatrix = document.getElementById("Dasher").innerHTML;
	
	if(theVar == "partner") {
		document.getElementById("login_supplier").innerHTML = '<img src="' + dashMatrix + 'public/images/ttab_supplierlogin_off.gif">';
		document.getElementById("login_partner").innerHTML = '<img src="' + dashMatrix + 'public/images/ttab_partnerlogin_on2.gif">';
		document.getElementById("formid").value = "partner";
		document.getElementById("formfieldspartner").style.display = "block";
		document.getElementById("formfieldssupplier").style.display = "none";
	} else if(theVar == "supplier") {
		document.getElementById("login_supplier").innerHTML = '<img src="' + dashMatrix + 'public/images/ttab_supplierlogin_on.gif">';
		document.getElementById("login_partner").innerHTML = '<img src="' + dashMatrix + 'public/images/ttab_partnerlogin_off.gif">';
		document.getElementById("formid").value = "supplier";
		document.getElementById("formfieldspartner").style.display = "none";
		document.getElementById("formfieldssupplier").style.display = "block";
	}
}

function updateText(theDiv, theMessage) {
	if(theMessage != "") {
		document.getElementById(theDiv).innerHTML = theMessage;
	} else {
		document.getElementById(theDiv).innerHTML = "[Your name]";
	}
}

function valFeedback() {
	if(document.TheForm.Name.value == "") {
		alert("Please enter your Name.");
		document.TheForm.Name.focus();
		return false;
	} else {
		return true;
	}
}


function SendToAColleague() {

//	var divx = document.getElementById('HoverMenuHolder');
	//document.getElementById("HoverShadow").style.bottom = 0 - document.documentElement.scrollTop + 'px';
	//alert(document.documentElement.scrollTop);
//	divx.style.top = 50 + document.documentElement.scrollTop + 'px';

	document.getElementById("HoverShadow").style.display = "block";
	document.getElementById("HoverMenuHolder").style.display = "block";

//	document.getElementById("ShareForm").innerHTML=xmlHttp.responseText 
	
/*	var DashMatrix = document.getElementById("Dasher").innerHTML;
	var pageURL = document.getElementById("ThePager").innerHTML;
	
	var url = DashMatrix + "includes/ajax/pullPageForm.asp?sid=" + Math.random() + "&DashMatrix=" + DashMatrix;
	strDashMatrix = DashMatrix;
	xmlHttp=GetXmlHttpObject(postbackSender)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)
*/
}
function closeHoverForm() {
	document.getElementById("HoverShadow").style.display = "none";
	document.getElementById("HoverMenuHolder").style.display = "none";	
}

function sendHoverForm() {
	var DashMatrix = document.getElementById("Dasher").innerHTML;
	var FromEmail = document.getElementById("FromEmail").value;
	var FromName = document.getElementById("FromName").value;
	var ToEmail = document.getElementById("ToEmail").value;
	var ToName = document.getElementById("ToName").value;
	var ThePageURL = document.getElementById("SendPageURL").value;
	var pNote = document.getElementById("PersonalNote").value;
	
	var url = DashMatrix + "includes/ajax/SendEmailForm.asp?PersonalNote=" + pNote + "&SendPageURL=" + ThePageURL + "&FName=" + FromName + "&FEmail=" + FromEmail + "&TName=" + ToName + "&TEmail=" + ToEmail + "&sid=" + Math.random();
	strDashMatrix = DashMatrix;
	workElement = "CenterStage";
	xmlHttp=GetXmlHttpObject(postbackDisplayTimer)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)

}
function postbackDisplayTimer() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById(workElement).style.display = "block";
		document.getElementById(workElement).innerHTML=xmlHttp.responseText 
		// UpdateCartCount();
		setTimeout("closeHoverForm()", 2000);
	} 
} 


// =======================================================================================================
// 	Calendar Functions

	function showMiniCalendar(DashMatrix, theMonth, theYear, postback, clickedObject)
	{
		var url = DashMatrix + "includes/components/Calendar/miniCalendar.asp?sid=" + Math.random() + "&theMonth=" + theMonth + "&DashMatrix=" + DashMatrix + "&theYear=" + theYear + "&DivID=" + postback;
		workElement = "miniCalendarDiv"
		document.getElementById(workElement).innerHTML="Loading...";
		xmlHttp=GetXmlHttpObject(postbackDisplay)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)
		
		objElement = "miniCalendarDiv";
		obj = clickedObject;
		postbackHoverDate(obj, objElement)
	}
	function showMiniCalendarNext(DashMatrix, theMonth, theYear, postback)
	{
		var url = DashMatrix + "includes/components/Calendar/miniCalendar.asp?sid=" + Math.random() + "&theMonth=" + theMonth + "&DashMatrix=" + DashMatrix + "&theYear=" + theYear + "&DivID=" + postback;
		workElement = "miniCalendarDiv"
		xmlHttp=GetXmlHttpObject(postbackDisplay)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)
	}
	function selectThisDate(TheDate, postback)
	{
		workElement = postback;
		document.getElementById(workElement).value = TheDate;
		document.getElementById('miniCalendarDiv').style.display = 'none';
	}


function postbackHoverDate(obj, Element)
{ 
// Position the div next to the object
	objElement = Element;
	var x = 0;
	var y = 0;
	while (obj) { 
			x += obj.offsetLeft 
			y += obj.offsetTop
			obj = obj.offsetParent; 
			//x = x + 1;
			y = y - 8;
		} 
		document.getElementById(objElement).style.display = 'inline';
		document.getElementById(objElement).style.left = x+"px";
		document.getElementById(objElement).style.top = y+"px";
	//	document.getElementById("hoverpopup").moveTo(x,y);
// Write the content of the Div
} 

function postbackSender() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("ShareForm").style.display = "block";
		document.getElementById("ShareForm").innerHTML=xmlHttp.responseText 
	}
} 


function closeHover() {
	document.getElementById("theHover").style.visibility = "hidden";	
}

function showHover() {
	document.getElementById("theHover").style.visibility = "visible";	
}


function showSearch(DashMatrix, jSearchtext, jSearchppm, postback)
{ 
	if (jSearchtext.length >= "3") {
		var url=DashMatrix + "includes/ajax/search.asp?sid=" + Math.random() + "&SearchFor=" + jSearchtext + "&PPM=" + jSearchppm;
		workElement = postback;
		strDashMatrix = DashMatrix;
		xmlHttp=GetXmlHttpObject(postbackDisplay)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)
	} else {
		document.getElementById(workElement).style.display = "none";
	}
}

function addMoreMachines(DashMatrix, TheNumber, postback)
{
	var url= DashMatrix + "includes/ajax/addMoreMachines.asp?sid=" + Math.random() + "&DashMatrix=" + DashMatrix + "&MachineNum=" + TheNumber;
	strDashMatrix = DashMatrix;
	workElement = postback;
	xmlHttp=GetXmlHttpObject(postbackDisplay)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)
}

function addNums() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("thesum").innerHTML=xmlHttp.responseText 
	}
}

function postbackDisplay() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById(workElement).style.display = "block";
		document.getElementById(workElement).innerHTML=xmlHttp.responseText 
	}
} 

function MSAJAX_newobject(pageref,strVar,strValue)
{ 
var url=pageref + "?sid=" + Math.random() + "&" + strVar + "=" + strValue;
xmlHttp=GetXmlHttpObject(newobj_stateChanged)
xmlHttp.open("GET", url , true)
xmlHttp.send(null)
}

function newobj_stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("newobject").innerHTML=xmlHttp.responseText 
	}
} 

function MSAJAX_saveinfo(pageref,strDatabase,strVars,strValues)
{ 
var url=pageref + "?sid=" + Math.random() + "&db=" + strDatabase + "&Vars=" + strVars + "&Values=" + strValues;
xmlHttp=GetXmlHttpObject(saveinfo_submit)
xmlHttp.open("GET", url , true)
xmlHttp.send(null)
}

function saveinfo_submit() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("saveinfo").innerHTML=xmlHttp.responseText 
	}
} 

function GetXmlHttpObject(handler)
{ 
var objXmlHttp=null
if (navigator.userAgent.indexOf("Opera")>=0)
{	alert("This example doesn't work in Opera") 
return 
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 	var strName="Msxml2.XMLHTTP"
	if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
		strName="Microsoft.XMLHTTP"
		} 
	try
{ 
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler 
return objXmlHttp
} 
catch(e)
{ 
alert("Error. Scripting for ActiveX might be disabled") 
return 
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
	{
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler 
		return objXmlHttp
	}
} 
