/***********************************************************
gUncle Development
http://www.guncle.com

ajax.js
Page that contains all common  ajax functions 
***********************************************************/

var hmajax = createRequest();
function createRequest() {
	var obj;
	var browser = navigator.appName;
	if( browser == "Microsoft Internet Explorer" ) {
		obj = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else {
		obj = new XMLHttpRequest();
	}
	return obj;
}

/***********************************************************
wishlistRemove()
ajax functions for removing a gift idea
***********************************************************/
function wishlistRemove( id,user ) {
	check = confirm("Do you really want to remove this gift idea?");
	if( check ) {
		hmajax.open('get','../ajax_wishlist.php?action=remove&id='+id+'&user='+user);
		hmajax.onreadystatechange = wishlistRemoveResponse;
		hmajax.send(null);
	}
}
function wishlistRemoveResponse() {
	if(hmajax.readyState == 4){
        var response = hmajax.responseText;
        
       	if( response ) {
	       	document.getElementById('gift_ideas').innerHTML = response;
       	}
    }
}


/***********************************************************
giftProcured()
ajax functions for checking off a gift idea
***********************************************************/
function giftProcured( id,user ) {
	hmajax.open('get','../ajax_wishlist.php?action=procure&id='+id+'&user='+user);
	hmajax.onreadystatechange = giftProcuredResponse;
	hmajax.send(null);
}
function giftProcuredResponse() {
	if(hmajax.readyState == 4){
        var response = hmajax.responseText;
        
       	if( response ) {
	       	document.getElementById('gift_ideas').innerHTML = response;
       	}
    }
}

/***********************************************************
removeProcured()
ajax functions for checking off a gift idea
***********************************************************/
function removeProcured( id,user ) {
	hmajax.open('get','../ajax_wishlist.php?action=unprocure&id='+id+'&user='+user);
	hmajax.onreadystatechange = removeProcuredResponse;
	hmajax.send(null);
}
function removeProcuredResponse() {
	if(hmajax.readyState == 4){
        var response = hmajax.responseText;
        
       	if( response ) {
	       	document.getElementById('gift_ideas').innerHTML = response;
       	}
    }
}


/***********************************************************
uploadForm()
displays / hides upload form
***********************************************************/
function showUploadForm( user,id ) {
	if( id == '' ) {
		document.getElementById('gift-upload').src = 'wishlist_upload.php?user=' + user;
		document.getElementById('gift-upload').style.display = 'block';
	}
	else {
		document.getElementById('gift-upload-' + id).src = 'wishlist_upload.php?user=' + user + '&id=' + id;
		document.getElementById('wishlist-' + id).style.display = 'none';
		document.getElementById('gift-upload-' + id).style.display = 'block';
	}
}
function hideUploadForm( id ) {
	if( id == '' ) {
		window.parent.document.getElementById('gift-upload').style.display = 'none';
		window.parent.document.getElementById('gift-upload').src = 'blank.htm';
	}
	else {
		window.parent.document.getElementById('gift-upload-' + id).style.display = 'none';
		window.parent.document.getElementById('wishlist-' + id).style.display = 'block';
		window.parent.document.getElementById('gift-upload-' + id).src = 'blank.htm';
	}
}

/***********************************************************
sizingForm()
displays / hides sizing form
***********************************************************/
function showSizingForm( user ) {
	document.getElementById('sizing-form').src = 'sizing_update.php?user=' + user;
	document.getElementById('sizing-form').style.display = 'block';
}
function hideSizingForm() {
	window.parent.document.getElementById('sizing-form').style.display = 'none';
	window.parent.document.getElementById('sizing-form').src = 'blank.htm';
}


/***********************************************************
Element()
displays / hides element
***********************************************************/
function showElement(element) {
	if( document.getElementById(element) ) {
		document.getElementById(element).style.display='block';
	}
}

function hideElement(element) {
	if( document.getElementById(element) ) {
		document.getElementById(element).style.display='none';
	}
}


/***********************************************************
* Processing()
* displays / hides processing spinner
***********************************************************/
function showProcessing(id) {
	var processing = '<img src="/images/ajax_spinner.gif" width="16" height="16" alt="Processing" /> Processing...';
	if( id > 0 ) {
		document.getElementById('processing'+id).innerHTML = processing;
	}
	else {
		document.getElementById('processing').innerHTML = processing;
	}
}

/***********************************************************
* wishlist sort functions
***********************************************************/
function saveSortOrder(order) {
	hmajax.open('get','ajax_wishlist.php?action=sort&order='+order);
	hmajax.send(null);
}