function checkPage(country,language) {
	var hashes = location.hash;
	hashes = hashes.split('#').join("");
	if(hashes > 0) {
		view_product(hashes,country,language);
	}
}

function view_product(id,country,language) 
{
	//alert(id+' '+country+' '+language);
	if(document.getElementById('products-selected').style.display == "none") {
		Effect.BlindDown('products-selected');
	}
	section_file = 'products.php';
	type = 'view_product';
	var options = {
		method : 'post',
		parameters : 'type='+type+'&id='+id+'&country='+country+'&language='+language,
		// Handle successful response
		onSuccess: function(response) 
		{
			document.getElementById('products-selected').innerHTML = response.responseText;
			Effect.ScrollTo('products-selected');
			window.location.hash = id;

		}
	};
	new Ajax.Request('Includes/functions/'+section_file, options);
}

function refresh_product_image(id,type) 
{
	section_file = 'products.php';
	var options = {
		method : 'post',
		parameters : 'type='+type+'&id='+id,
		// Handle successful response
		onSuccess: function(response) 
		{
			document.getElementById('products-selected-details').innerHTML = response.responseText;
		}
	};
	new Ajax.Request('Includes/functions/'+section_file, options);
}

function wishlist(type,id,username) 
{
	section_file = 'wishlist.php';
	var options = {
		method : 'post',
		parameters : 'type='+type+'&id='+id+'&username='+username,
		// Handle successful response
		onSuccess: function(response) 
		{
			var message = response.responseText;
			if(type == 'addWishlistItem' || type == 'removeWishlistItem') {
				if(message == "authfailed") {
					wishlist('notConnected',0);
					
					if(getStyle('wishlist','display') == "none") {
						wishlistButton();
						setTimeout("wishlistButton()", 3000);
					}
				} else {
					wishlist('loadWishlist',message);
					if(getStyle('wishlist','display') == "none") {
						wishlistButton();
						setTimeout("wishlistButton()", 3000);
					}
				}
			} else if(type == 'notConnected') {
				document.getElementById('wishlist-content').innerHTML = message;
				FB.XFBML.Host.parseDomTree();
			} else if (type != 'setWishlistTab') {
				document.getElementById('wishlist-content').innerHTML = message;
				FB.XFBML.Host.parseDomTree();
			}
		}
	};
	new Ajax.Request('Includes/functions/'+section_file, options);
}

function wishlistButton() {
	
	if(getStyle('wishlist','display') == "none") {
			document.getElementById('wishlist-tab').innerHTML = "HIDE YOUR WISHLIST";
	} else {
			document.getElementById('wishlist-tab').innerHTML = "VIEW YOUR WISHLIST";
	}
	
	Effect.toggle('wishlist', 'blind');
	var x = document.getElementById('wishlist');
	
	wishlist('setWishlistTab',getStyle('wishlist','display')) 
}

function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function loadWalMart(url) {
	//var id = url.replace('http://www.walmart.com/catalog/product.do?product_id=', '')
	hcwalmart = window.open(url,'popup','menubar=no,width=755,height=450,toolbar=no,scrollbars=yes');
	setTimeout("hcwalmart.scrollTo(0, 160);", 3000);
}

function scrollProject() {
	Effect.ScrollTo('products-selected');
}

function updates(id,type) {
	var section_file = 'updates.php';
	if(type == 'add_comment') {
		var cn = 'add_comment';
	}
	var opt = {
	        method: 'post',
	        postBody: Form.serialize($(''+cn+'')) + '&id='+id+'&type='+type,
	        onSuccess: function(response) 
			{
	        	var msg = response.responseText;
	
				if(type == 'add_comment') {
					if(msg == 0) {
						document.getElementById('comments-server-message').innerHTML = 'You did not fill out all of the fields correctly.';
					} else {
						document.getElementById('comments_container_'+id).innerHTML = msg;
					}
				}
	        }
	    }
	new Ajax.Request('Includes/functions/'+section_file, opt);
}
var comment_check = true;
function comments(id,type,action) {
if(comment_check) {
	comment_check = false;

	var section_file = 'comments.php';
	if(action == 'add_comment') {
		var cn = 'add_comment';
	}
	var opt = {
	        method: 'post',
	        postBody: Form.serialize($(''+cn+'')) + '&id='+id+'&type='+type+'&action='+action,
	        onSuccess: function(response) 
			{
	        	var msg = response.responseText;
	
				if(action == 'add_comment') {
					if(msg == 0) {
						document.getElementById('comments-server-message').innerHTML = 'You did not fill out all of the fields correctly.';
					} else {
						document.getElementById('comments_container_'+id).innerHTML = msg;
					}
					document.add_comment.comment_body.value = '';
					comment_check = true;
					jQuery('#add_comment #add_comment_comment_reply').val(0);
				}
	        }
	    }
	new Ajax.Request('Includes/functions/'+section_file, opt);
}
}

function contact(type) {
	var section_file = 'contact.php';
	if(type == 'sendemail') {
		var cn = 'form_contact';
	}
	var opt = {
	        method: 'post',
	        postBody: Form.serialize($(''+cn+'')) + '&type='+type,
	        onSuccess: function(response) 
			{
	        	var msg = response.responseText;
	
				if(type == 'sendemail') {
					if(msg == 0) {
						document.getElementById('contact-server-message').innerHTML = 'You did not fill out all of the fields correctly.';
					} else {
						document.getElementById('contact-server-message').innerHTML = 'Your e-mail has been sent.';
						document.form_contact.contact_subject.value = '';
					}
				}
	        }
	    }
	new Ajax.Request('Includes/functions/'+section_file, opt);
}




function startCallback() {
	Element.show('uploadStatus');
	Element.hide('uploadForm');
	return true;
}

function completeCallback(response) {
	Element.hide('uploadStatus');
	Element.show('uploadForm');
	document.form_add_item.reset();
	//alert(response);
	//Effect.toggle('add_item', 'blind');
	//view_list(3);
	//update_sort(3);	
}

AIM = {

    frame : function(c) {

        var n = 'f' + Math.floor(Math.random() * 99999);
        var d = document.createElement('DIV');
        d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
        document.body.appendChild(d);

        var i = document.getElementById(n);
        if (c && typeof(c.onComplete) == 'function') {
            i.onComplete = c.onComplete;
        }

        return n;
    },

    form : function(f, name) {
        f.setAttribute('target', name);
    },

    submit : function(f, c) {
		//alert("submit");
        AIM.form(f, AIM.frame(c));
        if (c && typeof(c.onStart) == 'function') {
            return c.onStart();
        } else {
            return true;
        }
    },

    loaded : function(id) {
        var i = document.getElementById(id);
        if (i.contentDocument) {
            var d = i.contentDocument;
        } else if (i.contentWindow) {
            var d = i.contentWindow.document;
        } else {
            var d = window.frames[id].document;
        }
        if (d.location.href == "about:blank") {
            return;
        }

        if (typeof(i.onComplete) == 'function') {
            i.onComplete(d.body.innerHTML);
        }
    }

}
