
var WebRoot = 'http://www.wmn.ph';

function search_wish(searchURL, val)
{
	if(val != '')
	{
		var myURL = searchURL+'/keyword/'+escape_chars(val);
		location.href = myURL;
	}
}

function change_input_type(oldObject, oType)
{
	var newObject = document.createElement('input');
	newObject.type = oType;

	if(oldObject.size) newObject.size = oldObject.size;
	if(oldObject.value) newObject.value = oldObject.value;
	if(oldObject.name) newObject.name = oldObject.name;
	if(oldObject.maxlength) newObject.maxlength = oldObject.maxlength;
	if(oldObject.id) newObject.id = oldObject.id;
	if(oldObject.className) newObject.className = oldObject.className;	
	oldObject.parentNode.replaceChild(newObject,oldObject);		
	newObject.value='';
	newObject.focus();
	document.getElementById('password').focus();
	return newObject;
}

function addtolist(ItemID, UserName)
{
	if(ItemID && UserName)
	{
		var answer = confirm('Are you sure you want to Add this item?');
		if(answer)
		{	
			xmlHttps=GetXmlHttpObject();
			div_id = 'div_process';				
			sndReq(WebRoot+"/wishlist/process.php", "add_tolist=1&itemid="+ItemID+"&username="+UserName);
		}
	}
	else alert('Please Login');
}

function deletetolist(WishID)
{
	if(WishID)
	{
		var answer = confirm('Are you sure you want to delete?');
		if(answer)
		{			
			xmlHttps=GetXmlHttpObject();
			div_id = 'div_process';
			sndReq(WebRoot+"/wishlist/process.php", "delete_tolist=1&wish="+WishID);
		}
	}
	else alert('Please select a wish to delete');
}

function edit_display(UserID, display)
{
	if(UserID)
	{
		xmlHttps=GetXmlHttpObject();
		div_id = 'div_process';
		if(display.checked) $flg_display = 1;
		else  $flg_display = 0;
		
		sndReq(WebRoot+"/wishlist/process.php", "edit_display=1&userid="+UserID+"&display="+$flg_display);
	}
	else alert('Please Login');
}

function changeThemes(ThemeId, UserName)
{
	if(ThemeId && UserName)
	{
		xmlHttps=GetXmlHttpObject();
		div_id = 'div_process';				
		sndReq(WebRoot+"/wishlist/process.php", "change_theme=1&themeid="+ThemeId+"&username="+UserName);
	}
	else alert('Please Login');
}

function escape_chars(str) {	
	str=str.replace(/\&/g,'');
	str=str.replace(/\?/g,'');
	str=str.replace(/\#/g,'');
	return str;
}

function sndReq(file, action)
{		
	xmlHttps.open('get', file + '?' + action);		
	xmlHttps.onreadystatechange = handleResponse;		
	xmlHttps.send(null);
}

function handleResponse()
{		
	if(xmlHttps.readyState == 4)
	{
		//var response = http.responseText;
		document.getElementById(div_id).innerHTML = xmlHttps.responseText;
	}
}

function stateChanged() 
{ 
	if(xmlHttps.readyState!=4 || xmlHttps.readyState!="complete")
	{
		/*document.getElementById("txtCatcher").innerHTML = "Loading...<img src='webpics/images/load.gif'>";*/
	}
	if (xmlHttps.readyState==4 || xmlHttps.readyState=="complete")
 	{ 
 		/*document.getElementById("txtCatcher").innerHTML=xmlHttps.responseText */
 	} 
}

function GetXmlHttpObject()
{
	var xmlHttps=null;
	try
 	{
 		// Firefox, Opera 8.0+, Safari
 		xmlHttps=new XMLHttpRequest();
 	}
	catch (e)
 	{
 		//Internet Explorer
 		try
  		{
  			xmlHttps=new ActiveXObject("Msxml2.XMLHTTP");
  		}
 		catch (e)
  		{
  			xmlHttps=new ActiveXObject("Microsoft.XMLHTTP");
  		}
 	}
	return xmlHttps;
}


function addtolist_main(ItemID, UserName)
{
	if(ItemID && UserName)
	{
		var answer = confirm('Are you sure you want to Add this item?');
		if(answer)
		{	
			xmlHttps=GetXmlHttpObject();
			div_id = 'div_process';				
			sndReq(WebRoot+":81/wishlist/process.php", "add_tolist_main=1&itemid="+ItemID+"&username="+UserName);
		}
	}
	else alert('Please Login');
}
