// BEGIN ALL AJAX FUNCTIONS//
if(document.location.protocol=="https:")
{
	var webAddressPrefix = "https://";
} else {
	var webAddressPrefix = "http://";
}
var webAddress = webAddressPrefix+"www.bstsolutions.com/assets/ajax/";
var xmlHttp

//BEGIN GET NEWS FUNCTION//
function getNews(str){
	var xmlHttp
	xmlHttp=GetXmlHttpObject()
	//document.getElementById("bstnewsticker").innerHTML="<img src=\"<? echo $_SESSION['baseurl']; ?>/assets/images/icon_news.gif\" alt=\"<? echo $icon_bstnews; ?>\" align=\"top\" title=\"<? echo $icon_bstnews; ?>\" /><strong>BST News:</strong>"
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}        
	var url=webAddress+"getnews.php"
	url=url+"?str="+str
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	function stateChanged() { 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			var error=xmlHttp.responseText.split(" ")
			if (error[0]=="Internal") {
				document.getElementById("bstnewsticker").innerHTML="<a href=\"press-room/?t=6\" style=\"color:#333333;\"><img src=\"assets/images/icon_news.gif\" border=\"0\" align=\"absmiddle\" /><strong>BST News:</strong></a>&nbsp;Get updated News and Press Releases.";
			} else {
				document.getElementById("bstnewsticker").innerHTML=xmlHttp.responseText
			}
		} 
	};
};

//BEGIN SEND FEEDBACK----------------------------------------------------//
function siteFeedback(a,b,c,d,e,f,g,h,i,j){
	document.getElementById("feedbackresponse").innerHTML="<img src=\"http://www.bstsolutions.com/assets/images/ajax-loader_sm.gif\" align=\"absmiddle\" />"+g;
	//alert(d)
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}        
	var url=webAddress+"sendfeedback.php"
	url=url+"?a="+a
	url=url+"&b="+b
	url=url+"&c="+c
	url=url+"&d="+d
	url=url+"&e="+e
	url=url+"&f="+f
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	function stateChanged() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			if (xmlHttp.responseText == 1) {
				document.getElementById("feedbackactivearea").innerHTML="<p>&nbsp;</p><p>&nbsp;</p><div style=\"text-align:center;\"><strong>"+i+"</strong><p>&nbsp;</p><p>&nbsp;</p><input name=\"close\" type=\"button\" onclick=\"javascript:hide('feedbackconsole');\" value=\"  "+j+"  \" /></p></div>"
			} else {
				document.getElementById("feedbackresponse").innerHTML="<span style=\"color:#990000;\"><strong>"+h+"</strong></span>"
			}
		} 
	};
};

//CHECK ADD COMMENT----------------------------------------------------//
function submitComment(a,b,c,d,e,f,g){
	document.getElementById("dbresponse").innerHTML="One moment please..."
	hide('actionButton')
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}        
	var url=webAddress+"checkcomment.php"
	url=url+"?a="+a
	url=url+"&b="+b
	url=url+"&c="+c
	url=url+"&d="+d
	url=url+"&e="+e
	url=url+"&g="+g
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	function stateChanged() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			if (xmlHttp.responseText.length > 100) {
				//window.location.href = f
				//alert('show button')
				document.getElementById("dbresponse").innerHTML=xmlHttp.responseText
			} else {
				document.getElementById("dbresponse").innerHTML=xmlHttp.responseText
				show('actionButton')
			}
		} 
	};
};

//BEGIN RECOMMEND//
function AddRecommend(a,b,c){
	var xmlHttp
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}        
	var url=webAddress+"addrecommendation.php"
	url=url+"?a="+a
	url=url+"&b="+b
	url=url+"&c="+c
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	function stateChanged() { 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			//alert(xmlHttp.responseText)
		} 
	};
};

//BEGIN FORGOT PASSWORD//
function forgotpassword(e){
	document.getElementById("dbresponse").innerHTML="One moment please..." 
	var xmlHttp
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}        
	var url=webAddress+"forgotpassword.php"
	url=url+"?e="+e
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	function stateChanged() { 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			if (xmlHttp.responseText == 0) {
				document.getElementById("dbresponse").innerHTML="<span style=\"color:#990000;\"><strong>Please enter your email address.</strong></span>"
			}
			if (xmlHttp.responseText == 1) {
			document.getElementById("dbresponse").innerHTML="<span style=\"color:#990000;\"><strong>We could not locate the email address you provided.</strong></span><br>Please try again or contact us at <a href=\"mailto:perspectives@bstsolutions.com\">mailto:perspectives@bstsolutions.com</a>" 
			//alert(xmlHttp.responseText)
			}
			if (xmlHttp.responseText == 2) {
				document.getElementById("dbresponse").innerHTML="<span style=\"color:#990000;\"><strong>Your password has been sent to email address you provided.</strong></span><br>Once you have retrieved your Login information, <a href=\"index.php\">click here</a> to Log In."
			}
		} 
	};
};

//CHECK CLIENT LOGIN----------------------------------------------------//
function checkusers(u,p,r,d){
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}        
	var url=webAddress+"checkusers.php"
	url=url+"?u="+u
	url=url+"&p="+p
	url=url+"&r="+r
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	function stateChanged() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			if (xmlHttp.responseText.length == 1) {
				if (xmlHttp.responseText == 0) {
					window.location.href = "pleaseactivate.php"
				}
			} else {
				if (xmlHttp.responseText.length == 6) {
					if (d.match("item") == null) {
						window.location.href = d
					} else {
						window.location.href = d
					}
				} else {
					alert(xmlHttp.responseText);
				}
			}
		} 
	};
};

//CHECK CLIENTS IN ONYX----------------------------------------------------//
function checkonyx(f,l,e){
	document.getElementById("dbresponse").innerHTML="<img src=\"http://www.bstsolutions.com/mybst/assets/images/ajax-loader_sm.gif\" hspace=\"3\" align=\"absmiddle\" />One moment please..." 
	document.getElementById("actionButton").innerHTML="<img src=\"http://www.bstsolutions.com/mybst/assets/images/submit_button_dim.gif\" />"
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}        
	var url=webAddress+"checkonyx.php"
	url=url+"?f="+f
	url=url+"&l="+l
	url=url+"&e="+e
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	function stateChanged() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			//alert(xmlHttp.responseText)
			if (xmlHttp.responseText.length==1) {
				if (xmlHttp.responseText==0) { //Client Not Found, Continue as Registered User//
					document.getElementById("actionButton").innerHTML="<img src=\"http://www.bstsolutions.com/mybst/assets/images/submit_button_dim.gif\" />"
					document.signupform.submit()
				}
				if (xmlHttp.responseText==1) { //Client Found, but First and/or Last Name don't match//
					document.getElementById("dbresponse").innerHTML="<span style=\"color:#990000;\"><strong>BST Client email found but First and Last name do not match.</strong></span><br />Either edit and re-submit your information <span style=\"color:#990000;\"><strong>or</strong></span> <a href=\"javascript:document.signupform.submit();\">click here</a> to continue with Sign Up."
					document.getElementById("actionButton").innerHTML="<a href=\"javascript:checkonyx(document.signupform.firstname.value,document.signupform.lastname.value,document.signupform.emailaddress.value);\"><img src=\"http://www.bstsolutions.com/mybst/assets/images/submit_button.gif\" alt=\"Submit button\" title=\"Submit\" border=\"0\" /></a>"
				}
				if (xmlHttp.responseText==2) { //Client Found, Complete Match//
					document.getElementById("actionButton").innerHTML="<img src=\"images/submit_button_dim.gif\" />"
					document.signupform.submit()
				}
				if (xmlHttp.responseText==3) { //BST Staff//
					document.getElementById("actionButton").innerHTML="<img src=\"images/submit_button_dim.gif\" />"
					document.signupform.submit()
				}
			} else {
				document.getElementById("dbresponse").innerHTML=xmlHttp.responseText
				document.getElementById("actionButton").innerHTML="<a href=\"javascript:checkonyx(document.signupform.firstname.value,document.signupform.lastname.value,document.signupform.emailaddress.value);\"><img src=\"http://www.bstsolutions.com/mybst/assets/images/submit_button.gif\" alt=\"Submit button\" title=\"Submit\" border=\"0\" /></a>"
			}
		} 
	};
};
//----BEGIN CHECK STEP2----//
function checkstep2() {
	document.getElementById("dbresponse").innerHTML="One moment please..." 
	document.getElementById("actionButton").innerHTML="<a href=\"signup.php\"><img style=\"margin:0 10px 0 0;\" src=\"images/back_button.gif\" alt=\"Back\" border=\"0\" title=\"Go to Step 1\" /></a><img src=\"images/submit_button_dim.gif\" />"
	var emptyAlert = 0;
	var elem = document.getElementById('signupform').elements;
	for(var i = 0; i < elem.length; i++){
		if (elem[i].value=="") {
			if (elem[i].name == "phone2" || elem[i].name == "address2" || elem[i].name == "state" || elem[i].name == "productservice" || elem[i].name == "postalcode") {
				//Do Nothing
			} else {
				emptyAlert = 1;
			}
		}
	}
	if (emptyAlert == 1) {
		document.getElementById("dbresponse").innerHTML="<span style=\"color:#990000;\"><strong>Please complete all required fields in the form.</strong></span>"
		document.getElementById("actionButton").innerHTML="<a href=\"signup.php\"><img style=\"margin:0 10px 0 0;\" src=\"images/back_button.gif\" alt=\"Back\" border=\"0\" title=\"Go to Step 1\" /></a><a href=\"javascript:checkstep2();\"><img src=\"images/submit_button.gif\" alt=\"Submit button\" title=\"Submit\" border=\"0\" /></a>"
	} else {
		document.signupform.submit();
	}
};
//CHECK STEP 3 ----------------------------------------------------//
function checkstep3(p,c){
	document.getElementById("dbresponse").innerHTML="One moment please..." 
	document.getElementById("actionButton").innerHTML="<img src=\"images/submit_button_dim.gif\" />"
	var emptyAlert = 0;
	var elem = document.getElementById('signupform').elements;
	for(var i = 0; i < elem.length; i++){
		if (elem[i].value=="") {
			emptyAlert = 1;
		}
	}
	if (emptyAlert == 1) {
		document.getElementById("dbresponse").innerHTML="<span style=\"color:#990000;\"><strong>Please complete all fields in the form.</strong></span>";
		document.getElementById("actionButton").innerHTML="<a href=\"javascript:checkstep3(document.signupform.password.value,document.signupform.passwordconfirm.value);\"><img src=\"images/submit_button.gif\" alt=\"Submit button\" title=\"Submit\" border=\"0\" /></a>"
	} else {
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null){
			alert ("Browser does not support HTTP Request")
			return
		}        
		var url=webAddress+"smallfunctions.php"
		url=url+"?p="+p
		url=url+"&c="+c
		url=url+"&sid="+Math.random()
		xmlHttp.onreadystatechange=stateChanged 
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
		function stateChanged() {
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
				if (xmlHttp.responseText==1) {
					document.signupform.submit()
				} else {
					document.getElementById("dbresponse").innerHTML="<span style=\"color:#990000;\"><strong>Please retype your password with accuracy.</strong></span>"
					document.getElementById("actionButton").innerHTML="<a href=\"javascript:checkstep3(document.signupform.password.value,document.signupform.passwordconfirm.value);\"><img src=\"images/submit_button.gif\" alt=\"Submit button\" title=\"Submit\" border=\"0\" /></a>"
				}
			} 
		};
	}
};
//----BEGIN CHECK MANAGE ACCOUNT----//
function checkaccupdate() {
	document.getElementById("dbresponse").innerHTML="<img src=\"../assets/images/ajax-loader_sm.gif\" align=\"absmiddle\" />&nbsp;One moment please..." 
	document.getElementById("actionButton").innerHTML="<a href=\"../\"><img style=\"margin:0 10px 0 0;\" src=\"../assets/images/back_button.gif\" alt=\"Back\" border=\"0\" title=\"Back\" /></a><img src=\"../assets/images/submit_button_dim.gif\" alt=\"Submit\" title=\"Submit\" border=\"0\" />"
	var emptyAlert = 0;
	var pWord = "";
	var pWord2 = "";
	var elem = document.getElementById('signupform').elements;
	for(var i = 0; i < elem.length; i++){
		if (elem[i].value=="") {
			if (elem[i].name == "middlename" || elem[i].name == "phone2" || elem[i].name == "address2" || elem[i].name == "state" || elem[i].name == "productservice" || elem[i].name == "postalcode") {
				//Do Nothing
			} else {
				emptyAlert = 1;
			}
		}
		if (elem[i].name=="password") {
			pWord = elem[i].value;
		}
		if (elem[i].name=="confirmpassword") {
			pWord2 = elem[i].value;
		}
	}
	if (pWord != pWord2) {
		emptyAlert = 2;
	}
	if (emptyAlert == 0) {
		document.manageaccount.submit();
	}
	if (emptyAlert == 1) {
		document.getElementById("dbresponse").innerHTML="<span style=\"color:#990000;\"><strong>Please complete all fields in the form.</strong></span>"
		document.getElementById("actionButton").innerHTML="<a href=\"../\"><img style=\"margin:0 10px 0 0;\" src=\"../assets/images/back_button.gif\" alt=\"Back\" border=\"0\" title=\"Back\" /></a><a href=\"javascript:checkaccupdate();\"><img src=\"../assets/images/submit_button.gif\" alt=\"Submit\" title=\"Submit\" border=\"0\" /></a>"
	}
	if (emptyAlert == 2) {
		document.getElementById("dbresponse").innerHTML="<span style=\"color:#990000;\"><strong>Please type your password the same in both fields.</strong></span>"
		document.getElementById("actionButton").innerHTML="<a href=\"../\"><img style=\"margin:0 10px 0 0;\" src=\"../assets/images/back_button.gif\" alt=\"Back\" border=\"0\" title=\"Back\" /></a><a href=\"javascript:checkaccupdate();\"><img src=\"../assets/images/submit_button.gif\" alt=\"Submit\" title=\"Submit\" border=\"0\" /></a>"
	}
};
//DO NOT EDIT ---- REQUIRED CODE FOR ALL AJAX FUNCTIONS------------------------------------//
function GetXmlHttpObject(){
	var xmlHttp=null;
	try{
    	// Firefox, Opera 8.0+, Safari
    	xmlHttp=new XMLHttpRequest();
	}
	catch (e){
    	// Internet Explorer
    	try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
	}
	return xmlHttp;
};
// END ALL AJAX FUNCTIONS//
