//Create a boolean variable to check for a valid Internet Explorer instance.
	var xmlhttpajx = false;
	//Check if we are using IE.
	try {
	//If the Javascript version is greater than 5.
		xmlhttpajx = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	//If not, then use the older active x object.
		try {
		//If we are using Internet Explorer.
			xmlhttpajx = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
		//Else we must be using a non-IE browser.
			xmlhttpajx = false;
		}
	}
	//If we are using a non-IE browser, create a javascript instance of the object.
	if (!xmlhttpajx && typeof XMLHttpRequest != 'undefined') {
		xmlhttpajx = new XMLHttpRequest();
	}
function serverRequest(serverPage, objID)
{
	// This is the function to call with serverPage as the page to dynamically call and objId is the div id
	var obj = document.getElementById(objID);
	try
	{
		xmlhttpajx.open("GET", serverPage,true);
		xmlhttpajx.onreadystatechange = function()
		{
			if (xmlhttpajx.readyState==4)
			{
				obj.innerHTML = xmlhttpajx.responseText;
			}
			else
			{
				document.getElementById(objID).innerHTML = "<img name='imageField' src='"+IMG_SERVER+"/images/loading.gif'/>";
			}
		}
		xmlhttpajx.send(null);
	}
	catch(e)
	{
	}
}
function add_friend(visitor,mid,script)
{
	if(mid == '0'){
		call_login(script);
		return false;
	}
	try
	{
		var serverPage = SERVER_PATH + '/ssi/ajax/add-friend.php?visitor=' + visitor ;
		xmlhttpajx.open("GET", serverPage,true);
		var loader = document.getElementById('loading_'+visitor);
		xmlhttpajx.onreadystatechange = function()
		{
			if (xmlhttpajx.readyState==4)
			{
				var spid = document.getElementById('wish-' + visitor + '-1');
				spid.className = 'on';
				if(xmlhttpajx.responseText=='added'){
					
					loader.innerHTML = '<span class="voted" style="padding-top:2px;padding-left:20px;">Added in friend list</sapn>';	
				}else if(xmlhttpajx.responseText=='already_added'){
					loader.innerHTML = '<span class="voted" style="padding-top:2px;padding-left:20px;">Already in friend list</sapn>';	
				}
				loader.style.display='';
			}
			else
			{
				loader.style.display='';
				loader.innerHTML = '<img src="' + IMG_SERVER + '/images/rating/rating_loading.gif" alt="loading" />';	;	
			}
		}
		xmlhttpajx.send(null);
	}
	catch(e)
	{
	}
}
function loginRequest(serverPage,whr, objID)
{
	// This is the function to call with serverPage as the page to dynamically call and objId is the div id
	var obj = document.getElementById(objID);
	try
	{
		xmlhttpajx.open("GET", serverPage,true);
		xmlhttpajx.onreadystatechange = function()
		{
			if (xmlhttpajx.readyState==4)
			{
				if(xmlhttpajx.responseText=='SuccessLogin'){
					if(whr == 'Purchase')
						document.frm.submit();
					else{
						
						document.location.href = whr;
						
						document.getElementById('top_login_container').innerHTML = "<table width='100%'><tr><td align='center'><a href='"+IMG_SERVER+"/member/my-account.php'><img src='"+IMG_SERVER+"/images/login.png' border='0'></a></td></tr><tr><td align='center'>My Account</td></tr></table>"
						DimPopup.Close("LoginPopup");
					}

				}else{
					obj.innerHTML = xmlhttpajx.responseText;
				}
			}
			else
			{
				obj.innerHTML = "<table width='100%' cellspacing='0' cellpadding='0'><tr><td  width='100%' valign='middle' align='center' style='width:400px;' class='large'><img name='imageField' src='"+IMG_SERVER+"/images/spinner-big.gif'/> </td></tr></table>";
			}
		}
		xmlhttpajx.send(null);
	}
	catch(e)
	{
		alert(e)
	}
}


function regRequest(serverPage, objID)
{
	
	// This is the function to call with serverPage as the page to dynamically call and objId is the div id
	var obj = document.getElementById(objID);
	try
	{
		xmlhttpajx.open("GET", serverPage,true);
		xmlhttpajx.onreadystatechange = function()
		{
			if (xmlhttpajx.readyState==4)
			{
				if(xmlhttpajx.responseText=='Process'){
					document.frm.submit();
				}else{
					obj.innerHTML = xmlhttpajx.responseText;
				}
			}
			else
			{
				obj.innerHTML = "<table width='100%' cellspacing='0' cellpadding='0'><tr><td  width='100%' valign='middle' align='center' style='width:400px;' class='large'><img name='imageField' src='"+IMG_SERVER+"/images/spinner-big.gif'/> </td></tr></table>";
			}
		}
		xmlhttpajx.send(null);
	}
	catch(e)
	{
	}
}

function upDateList(type,id,loggedIn,script)
{
	if(loggedIn == '0'){
		call_login(script);
		return false;
	}
	try
	{
		if(type == '1'){
			var spid = document.getElementById('wish-' + id + '-1');
		}else if(type == '2'){
			var spid = document.getElementById('wish-' + id + '-2');
		}else if(type == '3'){
			document.location.href=SERVER_PATH + '/product/product-detail.php?pid=' +id;
		}
		if(spid.className == 'on'){
			var serverPage = SERVER_PATH + '/ssi/ajax/update-list.php?class=on&id=' + id + '&type=' + type
		}else{
			var serverPage = SERVER_PATH + '/ssi/ajax/update-list.php?class=off&id=' + id + '&type=' + type
		}
		//alert(serverPage);
		xmlhttpajx.open("GET", serverPage,true);
		var loader = document.getElementById('loading_'+id);
		xmlhttpajx.onreadystatechange = function()
		{
			if (xmlhttpajx.readyState==4)
			{
				if(xmlhttpajx.responseText=='error'){
					loader.innerHTML = '<span class="voted" style="padding-top:2px;">Error in update</sapn>';	
				}else{
					//alert(xmlhttpajx.responseText);
					if(type == '1' && spid.className == 'on')
						loader.innerHTML = '<div class="removed">Remove purchase</div>';
					else if(type == '1' && spid.className == 'off')
						loader.innerHTML = '<div class="added">Add to purchase</div>';
					else if(type == '2' && spid.className == 'on')
						loader.innerHTML = '<div class="removed">Remove Wish List</div>';
					else if(type == '2' && spid.className == 'off')
						loader.innerHTML = '<div class="added">Add to Wish list</div>';
					if(spid.className == 'on'){
						spid.className = 'off';
					}else{
						spid.className = 'on';
					}
					if(type == '1' || type =='2'){
						//loader.innerHTML = '<span class="voted" style="padding-top:2px;">Added to Purchase List</sapn>';	
					}
					
					/*
					else{
						var spid = document.getElementById('wish-' + id + '-3');
						spid.className = 'on';
						if(xmlhttpajx.responseText =='already_favourate')
							loader.innerHTML = '<span class="voted" style="padding-top:2px;">Already Favourate</sapn>';
						else
							loader.innerHTML = '<span class="voted" style="padding-top:2px;">Added to Favourate</sapn>';
					}
					*/
				}
				//loader.innerHTML = '';
				loader.style.display='';
			}
			else
			{
				//alert(xmlhttpajx.responseText);
				loader.style.display='';
				loader.innerHTML = '<img src="' + IMG_SERVER + '/images/rating/rating_loading.gif" alt="loading" />';	;	
			}
		}
		xmlhttpajx.send(null);
	}
	catch(e)
	{
	}
}

