﻿// JScript File
// COMMAN FUNCTIONS TO ALL.
//var rootdomain = "http://www.beatmydebt.com";  //For Live


///var rootdomain = "http://beatmydebt.com";  //For Live

var strurl=window.location.href;
var strSub= strurl.substring(0,11);
if( strSub=='http://www.')
    //alert(strSub);
    var rootdomain = "http://www.beatmydebt.com"; 
 else
    var rootdomain = "http://beatmydebt.com"; 
//alert(rootdomain);
    
//var rootdomain = "http://localhost/bmd";   //For Local

//var rootdomain = "http://beta.beatmydebt.com";   //For beta
    

				
			Init=function() 
			{ 
				if (window.XMLHttpRequest) { // Non-IE browsers 
					_req = new XMLHttpRequest(); 
				} 
				else if (window.ActiveXObject){ // IE 
					_req = new ActiveXObject("Microsoft.XMLHTTP"); 
				} 
			}

			processStateChange = function() {
			    if (_req.readyState == 4) {
			        if (_req.status == 200) {
			            if (_req.responseText == "")
			                return false;
			            else {
			                //alert(_req.responseText);
			                eval(_req.responseText);
			            }
			        }
			    }
			} 			
			// TILL HERE ***************************************

			SendEligibilty = function(target) //get data 
			{
			    Init();
				var url = rootdomain+"dynamic/process.aspx?act=se" + target; 
				//alert("SendEligibilty - "+url);																					 																	
			 
				if(_req!=null) 
				{ 		
					_req.onreadystatechange = processStateChange; 
					_req.open("GET", url, true); 
					_req.send(null); 
				} 
			}

			function OnEligibiltySuccess(msg) {

			    if (msg != "") alert(msg);
			    //document.getElementById("dvCheckeligibilty").style.display = "none";
			    //document.getElementById("dvUserInfo").style.display = "block";
			    //Redirect to the eligibilty page - eligibility.htm
//			    window.location.href = rootdomain + "eligibility.htm"
window.location.href = rootdomain + "eligibility.htm"
			    return false;
			}

			function OnEligibiltyFailure(msg)
            {
                alert(msg);
                return false;
            }


            SendUserInfo = function(target) //get data 
            {
                Init();

                var url = rootdomain+"dynamic/process.aspx?act=usr" + target;
                //alert("SendUserInfo - " + url);

                if (_req != null) {
                    _req.onreadystatechange = processStateChange;
                    _req.open("GET", url, true);
                    _req.send(null);
                }
            }

            function OnUserInfoSuccess(msg) {
                
                if (msg != "")alert(msg);
                //Redirect to the thanks page - thanks.aspx
                window.location.href = rootdomain + "thanks.aspx"
                return false;
            }

            function OnUserInfoFailure(msg) {
                alert(msg);
                return false;
            }

            SendQuickEligibilty = function(target) //get data 
            {
                Init();
                var url = rootdomain + "dynamic/process.aspx?act=sequick" + target;
                //alert("SendEligibilty - " + url);

                if (_req != null) {
                    _req.onreadystatechange = processStateChange;
                    _req.open("GET", url, true);
                    _req.send(null);
                }
            }
            function OnQuickEligibiltySuccess(msg) {

                if (msg != "") alert(msg);
                //Redirect to the eligibilty page - eligibility.htm
//                window.location.href = rootdomain + "eligibility.htm"
window.location.href = rootdomain + "eligibility.htm"
                return false;
            }

            function OnQuickEligibiltyFailure(msg) {
                alert(msg);
                return false;
            }

            //SendAskQuestion mail

            SendAskQuestion = function(target) //get data 
            {
                Init();

                var url = rootdomain + "dynamic/askquestion.aspx?act=sendans" + target;
                //alert("SendAskQuestion - " + url);
                if (_req != null) {
                    _req.onreadystatechange = processStateChange;
                    _req.open("GET", url, true);
                    _req.send(null);
                }
            }

            function OnMailSuccess(msg) {

                if (msg != "") 
                //alert(msg);
                document.getElementById("dvUsrValidation").innerHTML = "<p>Mail Sent to us, we will contact you by mail in short time.</p>";
                return false;
            }

            function OnMailFailure(msg) {
                //alert(msg);
                document.getElementById("dvUsrValidation").innerHTML = "<p>Mail not Sent! may be server is busy, try again.</p>";
                return false;
            }

