// added this for the pop

var myPOPRequest = getXMLHttpRequestPOP();

function getXMLHttpRequestPOP() 
{
	// var activeXVersions = ["Msxml2.DOMDocument.6.0","Msxml2.DOMDocument.3.0","Msxml2.XMLHTTP","Microsoft.XMLHTTP"];
    var activeXVersions = ["Msxml2.XMLHTTP","Microsoft.XMLHTTP"];
	try {
		return new XMLHttpRequest;
	} catch (e) {
		for (var i=0; i < activeXVersions.length; i++) {
			try {
				return new ActiveXObject(activeXVersions[i]);
			} catch (e) {}
		}
	}
	return null;
}

function callPOPjax(url,method,data,callBack) {
	// Assign default values if not passed
	var method = (method == null) ? "GET" : method; // Default method
	var data = (data == null) ? '' : data;  // Default POST data
	var callBack = (callBack == null) ? handleAjaxResponsePOP : callBack; //Default callBack function
	
	// Cache breaker
	var myRandom= parseInt(Math.random()*99999999);
	if (url.indexOf('?') == -1) {
		var rUrl = url + '?rand=' + myRandom;
	} else {
		var rUrl = url + '&rand=' + myRandom;
	}
	
	myPOPRequest.open(method, rUrl, true);
	// Set the content type in the POST request 
	myPOPRequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"); 
	if (method == 'POST') {
		myPOPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	}
	myPOPRequest.onreadystatechange  = callBack;
	
	
	myPOPRequest.send (data);
}

/*
function displayID() {
	try {
		console.debug('readyState=' + myPOPRequest.readyState);
	} catch (err) {}
	if (myPOPRequest.readyState == 4) {
		if (myPOPRequest.status == 200) {
			document.getElementById('hi').innerHTML= myPOPRequest.responseText;
		} else {

		}
	}
}
*/
//  Default callback handler
function handleAjaxResponsePOP() {
	try {
		console.debug('readyState=' + myPOPRequest.readyState);
	} catch (err) {}
	if (myPOPRequest.readyState == 4) {
		if (myPOPRequest.status == 200) {
			alert('Server response: ' + myPOPRequest.responseText);
		} else {
			alert ('An error occurred: ' + myPOPRequest.statusText);
		}
	}
}


// end added this for the pop
function launchWLpop(a)
{	
	popCall('&mode=pop');
}



function launchWL(a)
{	
	ajaxCall(a);
}

function popCall(a)
{
	var mystring = "/modules/Wishlist/wl.php?" + Math.random() + a;
	callPOPjax(mystring,"POST",null,displaywlpop);
}

function ajaxCall(a)
{
	var mystring = "/modules/Wishlist/wl.php?" + Math.random() + a;
	callKNEXjax(mystring,"POST",null,displaywl);
}

function displaywl() {
	document.getElementById("wlarray").innerHTML = "<center style='margin-top:10px;color:#339900;'><img src='/images/Wishlist/ajax-loader.gif' border=0><br>LOADING PLEASE WAIT</center>";
	if (myKNEXRequest.readyState == 4) {
		if (myKNEXRequest.status == 200) {
			document.getElementById('wlarray').innerHTML= myKNEXRequest.responseText;
		} else {

		}
	}
}

function displaywlpop() {
	document.getElementById("wlpop").innerHTML = "<center style='margin-top:10px;color:#339900;'><img src='/images/Wishlist/ajax-loader.gif' border=0><br>LOADING PLEASE WAIT</center>";

	if (myPOPRequest.readyState == 4) {
		
		if (myPOPRequest.status == 200) {
			document.getElementById('wlpop').innerHTML= myPOPRequest.responseText;
		}
		
		
		
		
		
	}
}

// form validation
function validateemail(){

var myfirstname = document.emailform.myfirstname.value;
var myemailaddress = document.emailform.myemailaddress.value;
var recipient1 = document.emailform.recipient1.value;
var recipient2 = document.emailform.recipient2.value;
var recipient3 = document.emailform.recipient3.value;
var recipient4 = document.emailform.recipient4.value;
var recipient5 = document.emailform.recipient5.value;

var mystring = "&myemailaddress=" + myemailaddress + "&myfirstname=" + myfirstname + "&recipient1=" + recipient1 + "&recipient2=" + recipient2 + "&recipient3=" + recipient3 + "&recipient4=" + recipient4 + "&recipient5=" + recipient5;

var origstring = "&mode=send&sub=Y";

launchWL(origstring + mystring);


}

launchWL('');
launchWLpop('');