﻿/*
    Ajax Support Library 
    ©2009 b2-Consultants
    info@b2-consultants.com
*/

function xmlhttpPost(strURL) {
    var xmlHttpReq = false;
    var self = this;

    if (window.XMLHttpRequest) {
        // Mozilla/Safari/IE7/IE8/Chrome
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        // IE6 and before
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage("idReturnMessage", self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(buildPostQueryString("formSendToFriend"));
}

function buildPostQueryString(formname) {
    var theForm = document.forms[formname];
    var postText = "";
    var amp = "";
    for (i = 0; i < theForm.elements.length; i++) {
        if (theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea" || theForm.elements[i].type == "hidden") {
            postText += amp + theForm.elements[i].name + "=" + encodeURIComponent(theForm.elements[i].value);
        } else if (theForm.elements[i].type == "checkbox") {
            postText += amp + theForm.elements[i].name + "=" + theForm.elements[i].checked;
        } else if (theForm.elements[i].type == "select-one") {
            postText += amp + theForm.elements[i].name + "=" + theForm.elements[i].options[theForm.elements[i].selectedIndex].text;
        }
        amp = "&";
    }
    return postText;
}

function updatepage(elementID, str) {
    obj = document.getElementById(elementID);
    obj.innerHTML = str;
}