/********************************************************************************************/
/* AHAH functions by Phil Ballard                                                           */
/* This code is intended for study purposes.                                                */
/* You may use these functions as you wish, for commercial or non-commercial applications,  */
/* but please note that the author offers no guarantees to their usefulness, suitability or */
/* correctness, and accepts no liability for any losses caused by their use.                */
/********************************************************************************************/

function hideStatusBox()
{
var _1f = document.getElementById('StatusMessageBlockID');
if(_1f&&_1f.parentNode){
return _1f.parentNode.removeChild(_1f);
}
}

function callAHAH(url, pageElement, callMessage, errorMessage) {
     document.getElementById(pageElement).innerHTML = callMessage;
     try {
     req = new XMLHttpRequest(); /* e.g. Firefox */
     } catch(e) {
       try {
       req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
       } catch (e) {
         try {
         req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
         } catch (E) {
          req = false;
         } 
       } 
     }
     req.onreadystatechange = function() {responseAHAH(pageElement, errorMessage);};
     req.open("GET",url,true);
     req.send(null);
  }

function responseAHAH(pageElement, errorMessage) {
   var output = '';
   if(req.readyState == 4) {
      if(req.status == 200) {
         output = req.responseText;
         document.getElementById(pageElement).innerHTML = output;
	 	 hideStatusBox();
         } else {
         document.getElementById(pageElement).innerHTML = errorMessage+"\n"+output;
	 	hideStatusBox();
         }
      }
  }


/*new code added*/

var req;
function callPage(pageUrl, divElementId, loadinglMessage, pageErrorMessage) {
     //document.getElementById(divElementId).innerHTML = loadinglMessage;
	 //alert(pageUrl);
     try {
     req = new XMLHttpRequest(); /* e.g. Firefox */
     } catch(e) {
       try {
       req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
       } catch (e) {
         try {
         req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
         } catch (E) {
          req = false;
         } 
       } 
     }
     req.onreadystatechange = function() {responsefromServer(divElementId, pageErrorMessage);};
     req.open("GET",pageUrl,true);
     req.send(null);
  }

function responsefromServer(divElementId, pageErrorMessage) {
   var output = '';
   if(req.readyState == 4) {
      if(req.status == 200) {
         output = req.responseText;
         document.getElementById(divElementId).innerHTML = output;
		 hideStatusBox();
         } else {
         document.getElementById(divElementId).innerHTML = pageErrorMessage+"\n"+output;
		 hideStatusBox();
         }
      }
  }
  
/* This Function is for Tab Panels */
function activeTab(tab)
	{   
if(tab == 1) // If your tabs are more, then you can use 'switch' condition instead of 'if' condition for better practice
{
callPage('/myaccount/mainaccount.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 2){
displayStatusBox('Loading...');
callPage('/myaccount/shipnameadd.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 3){
displayStatusBox('Loading...');
callPage('/myaccount/cemail.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 4){
displayStatusBox('Loading...');
callPage('/myaccount/cepwd.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 5){
displayStatusBox('Loading...');
callPage('/myaccount/cecancel.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 6){
displayStatusBox('Loading...');
callPage('/myaccount/breadcrum.php?show=1', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 7){
displayStatusBox('Loading...');
callPage('/myaccount/breadcrum.php?show=2', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 8){
displayStatusBox('Loading...');
callPage('/myaccount/breadcrum.php?show=3', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 9){
displayStatusBox('Loading...');
callPage('/myaccount/breadcrum.php?show=4', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 10){
displayStatusBox('Loading...');
callPage('/myaccount/creditcard.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 11){
displayStatusBox('Loading...');
callPage('/myaccount/quality.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 12){
displayStatusBox('Loading...');
callPage('/myaccount/index.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 13){
displayStatusBox('Loading...');
callPage('/myaccount/mainaccountfb.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 14){
displayStatusBox('Loading...');
callPage('/myaccount/shipnameadd_fb.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 15){
displayStatusBox('Loading...');
callPage('/myaccount/homecat_fb.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 16){
displayStatusBox('Loading...');
callPage('/myaccount/link_fb.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 17){
displayStatusBox('Loading...');
callPage('/myaccount/cecancel_fb.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 18){
displayStatusBox('Loading...');
callPage('/myaccount/breadcrum.php?show=18', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 19){
displayStatusBox('Loading...');
callPage('/myaccount/breadcrum.php?show=19', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 20){
displayStatusBox('Loading...');
callPage('/myaccount/cepwdfb.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 21){
//displayStatusBox('Loading...');
callPage('/fb/home.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 22){
displayStatusBox('Loading...');
callPage('/fb/friends.php', 'friendss', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 24){
displayStatusBox('Loading...');
callPage('/myaccount/pauseaccount.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 25){
displayStatusBox('Loading...');
callPage('/myaccount/breadcrum.php?show=20', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 26){
displayStatusBox('Loading...');
callPage('/myaccount/learn.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 27){
displayStatusBox('Loading...');
callPage('/myaccount/breadcrum.php?show=21', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 28){
displayStatusBox('Loading...');
callPage('/myaccount/learnnew.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 29){
displayStatusBox('Loading...');
callPage('/fb/dynamic-home.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 30){
displayStatusBox('Loading...');
callPage('/fb/dynamic-friends.php', 'friends', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 31){
displayStatusBox('Loading...');
callPage('/myaccount/takeatour1.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 32){
displayStatusBox('Loading...');
callPage('/myaccount/takeatour2.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 33){
displayStatusBox('Loading...');
callPage('/myaccount/takeatour3.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 34){
displayStatusBox('Loading...');
callPage('/myaccount/takeatour4.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 35){
displayStatusBox('Loading...');
callPage('/myaccount/takeatour5.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 36){
displayStatusBox('Loading...');
callPage('/myaccount/takeatour6.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 37){
displayStatusBox('Loading...');
callPage('/myaccount/takeatour7.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 38){
displayStatusBox('Loading...');
callPage('/myaccount/takeatour8.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}else if(tab == 39){
displayStatusBox('Loading...');
callPage('/myaccount/newindex.php', 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}


	}

function activeTabPage(tab,pageid)
{
if(tab == 23){
displayStatusBox('Loading...');
callPage('/myaccount/billinghistory.php?page_no='+pageid, 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}
}

function activeTabPagefb(tab,pageid)
{
if(tab == 25){
displayStatusBox('Loading...');
callPage('/myaccount/billinghistoryfb.php?page_no='+pageid, 'change', '<img src=\"images/loading.gif\" /> Content is loading, Please Wait...', 'Error in Loading page <img src=\"images/error_caution.gif\" />');
}
}

/*new code*/

   var http_request = false;
   function makeRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      http_request.onreadystatechange = alertContents;
      http_request.open('GET', url + parameters, true);
      http_request.send(null);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
			if(result!="" && result!=1 && result!=2 && result!=3 && result!=4 && result!=18 && result!=19 && result!=20 && result!=25){
            document.getElementById('myspan').innerHTML = result; 
			}else if(result==1){
			activeTab(6);
			}else if(result==2){
			activeTab(7);
			}else if(result==3){
			activeTab(8);
			}else if(result==4){
			activeTab(9);
			}else if(result==18){
			activeTab(18);
			}else if(result==19){
			activeTab(19);
			}else if(result==20){
			activeTab(20);
			}else if(result==25){
			window.parent.location.href='http://apps.new.facebook.com/bookins/?r=ul&lnk=/myaccount/aboutmefb.php?step=linkfbsucc';
			exit;
			activeTab(25);
			}
			hideStatusBox()
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function get(obj) {
	displayStatusBox('Loading...');
      var poststr = "&txtFirstName=" + encodeURI( document.frmshipment.txtFirstName.value ) +
                    "&txtLastName=" + encodeURI( document.frmshipment.txtLastName.value ) +
                    "&txtSStreetAddress=" + encodeURI( escape(document.frmshipment.txtSStreetAddress.value) ) +
                    "&txtSStreetAddress1=" + encodeURI( escape(document.frmshipment.txtSStreetAddress1.value) ) +
                    "&txtSCity=" + encodeURI( document.frmshipment.txtSCity.value ) +
                    "&selSState=" + encodeURI( document.frmshipment.selSState.value ) +
                    "&txtSZip=" + encodeURI( document.frmshipment.txtSZip.value );

      makeRequest('/myaccount/get.php?form=shipname', poststr);
   }

   function getfb(obj) {
	displayStatusBox('Loading...');
      var poststr = "&txtFirstName=" + encodeURI( document.frmshipment.txtFirstName.value ) +
                    "&txtLastName=" + encodeURI( document.frmshipment.txtLastName.value ) +
                    "&txtSStreetAddress=" + encodeURI( escape(document.frmshipment.txtSStreetAddress.value) ) +
                    "&txtSStreetAddress1=" + encodeURI( escape(document.frmshipment.txtSStreetAddress1.value) ) +
                    "&txtSCity=" + encodeURI( document.frmshipment.txtSCity.value ) +
                    "&selSState=" + encodeURI( document.frmshipment.selSState.value ) +
                    "&txtSZip=" + encodeURI( document.frmshipment.txtSZip.value );
      makeRequest('/myaccount/get.php?form=shipname&fb=1', poststr);
   }


   function gethomecate(obj) {
	displayStatusBox('Loading...');
      var poststr = "&books=" + encodeURI( document.frmshipment.books.value ) +
                    "&dvds=" + encodeURI( document.frmshipment.dvds.value );

      makeRequest('/myaccount/get.php?form=homecat', poststr);
   }

function getemail(obj) {

displayStatusBox('Loading...');

var poststr = "&txtEmail=" + encodeURI(document.frmshipment.txtEmail.value) +
			"&txtNewEmail=" + encodeURI(document.frmshipment.txtNewEmail.value) +
			"&txtPassword=" + encodeURI(document.frmshipment.txtPassword.value);


makeRequest('/myaccount/get.php?form=cemail', poststr);
}


function getpwd(obj) {

displayStatusBox('Loading...');

var poststr = "&txtPwd=" + encodeURI(document.frmshipment.txtPwd.value) +
			"&txtNewPwd=" + encodeURI(document.frmshipment.txtNewPwd.value) +
			"&txtPassword=" + encodeURI(document.frmshipment.txtPassword.value);

makeRequest('/myaccount/get.php?form=pwd', poststr);
}

function getcancel(obj) {

displayStatusBox('Loading...');

var poststr = "&txtreason=" + encodeURI(document.frmshipment.txtreason.options[document.frmshipment.txtreason.selectedIndex].value) +
			"&txtthoughts=" + encodeURI(document.frmshipment.txtthoughts.value);

makeRequest('/myaccount/get.php?form=cancel', poststr);
}

function getcancelfb(obj) {

displayStatusBox('Loading...');

var poststr = "&txtreason=" + encodeURI(document.frmshipment.txtreason.options[document.frmshipment.txtreason.selectedIndex].value) +
			"&txtthoughts=" + encodeURI(document.frmshipment.txtthoughts.value);

makeRequest('/myaccount/get.php?form=cancelfb', poststr);
}

function getlink(obj) {
displayStatusBox('Loading...');

for (var i=0; i < document.frmshipment.siteval.length; i++)
   {
   if (document.frmshipment.siteval[i].checked)
      {
      var site_val = document.frmshipment.siteval[i].value;
      }
   }

var poststr = "&txtUserName=" + encodeURI( document.frmshipment.txtUserName.value ) +
			"&txtPwd=" + encodeURI( document.frmshipment.txtPwd.value ) +
			"&txtBUserName=" + encodeURI( escape(document.frmshipment.txtBUserName.value) ) +
			"&txtBPwd=" + encodeURI( escape(document.frmshipment.txtBPwd.value) ) +
			"&site_val=" + encodeURI( site_val );

makeRequest('/myaccount/get.php?form=linkfb', poststr);
}

