var countItemSelected = 0;
var keys = new Array(
				'rare',
				'promo',
				'premiumgoodies',
				'prepaid',
				'scav',
				'collection',
				'fashionplace',
				'blingbling',
				'rapunzelhair',
				'beautybeyond',
				'room',
				'bakery',
				'magic',
				'dolly'
			);

function canSubmit(element) {
	if (element.checked == true)
		countItemSelected++;
	else
		countItemSelected--;
}

function multiple_submit() {
	if (countItemSelected == 0) {
		alert('No items selected!');
		return false;
	} else {
		if (document.getElementById('Multiple_SubmitBtn_div1') != null)
			document.getElementById('Multiple_SubmitBtn_div1').style.display = 'none';
		if (document.getElementById('Multiple_SubmitBtn_div2') != null)
			document.getElementById('Multiple_SubmitBtn_div2').style.display = 'none';
		if (document.getElementById('multipleloading1') != null) {
			document.getElementById('multipleloading1').style.display = 'block';
		}
		//document.multipleItemForm.submit();

		if (document.getElementById('multipleloading2') != null) {
			document.getElementById('multipleloading2').style.display = 'block';
		}
		return true;
	}
}

function showPrice(sendCbxId, sendSelectDiv, selectedSendCbx) {
	/* check = false;
	dis = true;
	if (selectedSendCbx.checked == true) {
		check = true;
		dis = false;
	}
	for (i=0; i<keys.length; i++) {
		tempCbx = document.getElementById(keys[i]+'_'+sendCbxId);
		if (tempCbx != null) {
			tempCbx.checked = check;
			canSubmit(tempCbx);*/
			canSubmit(selectedSendCbx);
			fm_showPrice2(keys[i]+'_'+sendSelectDiv);
		/* }
	} */
}

function fm_showPrice2(divName) {
	if(document.getElementById(divName + '_div') && document.getElementById(divName + '_input')) {
		var divObj = document.getElementById(divName + '_div');
		var inputObj = document.getElementById(divName + '_input');



		//now change the objects so they're visible & enabled.
		if(divObj.style.display == 'inline') {
			divObj.style.display = 'none';
			inputObj.setAttribute('disabled', 'true');
		}
		else {
			divObj.style.display = 'inline';
			inputObj.disabled = false;
		}
	}
}//end fm_showPrice()

function updateSendSelect(sendSelectId, sendSelect) {
	var index = sendSelect.selectedIndex;
	if (sendSelect != null) {
		for (i=0; i<keys.length; i++) {
			temp = document.getElementById(keys[i]+'_'+sendSelectId);
			if (temp != null) {
				temp.selectedIndex = index;
			}
		}
	}
}

function notForSale(elem, id, showat, tempShowAt) {
	xmlhttp = GetXmlHttpObject();
	//if the browser does not supporting XMLHTTP
	if (xmlhttp==null)
	{
		alert ('Your browser does not support XMLHTTP!');
		return;
	}

	today = new Date(); rand=today.getTime();
	isChecked = elem.checked;

	if (isChecked == true)
		action = 'notforsale';
	else
		action = 'forsale';
	var url = 'ajax_functions/ajax_items_enhancement.html?cache_bust='+rand+'&action='+action+'&id='+id;

	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4) {
			res = xmlhttp.responseText;
			if (res == 'notforsale') {
				for (i=0; i<keys.length; i++) {
					sellOrBuyContainer = document.getElementById(keys[i]+'_sellOrBuyContainer_'+id);
					if (sellOrBuyContainer != null) {
						document.getElementById(keys[i]+'_notforsale_'+id+'_cbx').checked = true;
						sellOrBuyContainer.style.display = 'none';
						document.getElementById(keys[i]+'_'+showat+'_img').style.display = 'inline';
						document.getElementById(keys[i]+'_'+showat).style.display = 'inline';
						document.getElementById(keys[i]+'_'+showat+'_loading').style.display = 'none';
					}
				}
			} else if (res == 'forsale') {
				for (i=0; i<keys.length; i++) {
					sellOrBuyContainer = document.getElementById(keys[i]+'_sellOrBuyContainer_'+id);
					if (sellOrBuyContainer != null) {
						document.getElementById(keys[i]+'_notforsale_'+id+'_cbx').checked = false;
						sellOrBuyContainer.style.display = 'inline';
						document.getElementById(keys[i]+'_'+showat+'_img').style.display = 'none';
						document.getElementById(keys[i]+'_'+showat).style.display = 'none';
						document.getElementById(keys[i]+'_'+showat+'_loading').style.display = 'none';
					}
				}
			}
		} else {
			for (i=0; i<keys.length; i++) {
				temp = document.getElementById(keys[i]+'_'+tempShowAt+'_loading');
				if (temp != null) {
					temp.style.display = 'inline';
				}
			}
		}
	}

	xmlhttp.open("GET", url,true);
	xmlhttp.send(null);
}

function notForSale2(id, showat, tempShowAt) {
	xmlhttp = GetXmlHttpObject();
	//if the browser does not supporting XMLHTTP
	if (xmlhttp==null)
	{
		alert ('Your browser does not support XMLHTTP!');
		return;
	}

	today = new Date(); rand=today.getTime();
	isChecked = document.getElementById('notforsale_'+id+'_cbx').checked;

	if (isChecked == true)
		action = 'notforsale';
	else
		action = 'forsale';
	var url = 'ajax_functions/ajax_items_enhancement.html?cache_bust='+rand+'&action='+action+'&id='+id;

	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4) {
			res = xmlhttp.responseText;
			if (res == 'notforsale') {
				document.getElementById('sellOrBuyContainer_'+id).style.display = 'none';
				/* document.getElementById(showat).innerHTML = '<img src="http://www.cartoondollemporium.com/cdeprofile/profile/notforsale.gif" />'; */
				document.getElementById(showat).style.display = 'inline';
				document.getElementById(showat+'_img').style.display = 'inline';
				document.getElementById(showat+'_loading').style.display = 'none';
			} else if (res == 'forsale') {
				document.getElementById('sellOrBuyContainer_'+id).style.display = 'inline';
				//document.getElementById('notforsaletitle_'+id).innerHTML = 'Not For Sale';
				//document.getElementById('sellOrBuyContainer_'+id).style.display = 'inline';
				//document.getElementById('notforsalecbx'+id).innerHTML = '<input name="notforsale_'+id+'" type="checkbox" onClick="notForSale(\'notforsale\', \''+id+'\', \'notforsaleprocess_'+id+'\', \'notforsaleprocess_'+id+'\')" value="'+id+'" id="notforsale_'+id+'_cbx" />';
				//document.getElementById('notforsale_'+id+'_cbx').checked = false;
				//document.getElementById(showat).innerHTML = '';
				document.getElementById(showat).style.display = 'none';
				document.getElementById(showat+'_img').style.display = 'none';
				document.getElementById(showat+'_loading').style.display = 'none';
			}

		} else {
			document.getElementById(showat+'_loading').style.display = 'inline';
		}
	}

	xmlhttp.open("GET", url,true);
	xmlhttp.send(null);
}

function checkNotForSale(action, key, id, showat, userid) {
	xmlhttp = GetXmlHttpObject();
	//if the browser does not supporting XMLHTTP
	if (xmlhttp==null)
	{
		alert ('Your browser does not support XMLHTTP!');
		return;
	}

	today = new Date(); rand=today.getTime();

	var url = 'ajax_functions/ajax_items_enhancement.html?cache_bust='+rand+'&action='+action+'&id='+id+'&userid='+userid;

	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4) {
			res = xmlhttp.responseText;
			if (res == 'notforsale') {
				for (i=0; i<keys.length; i++) {
					buyitem = document.getElementById(keys[i]+'_buyitem_'+id);
					if (buyitem != null) {
						buyitem.style.display = 'none';
						/* document.getElementById(keys[i]+'_'+showat).innerHTML = '<span id="'+keys[i]+'_checkhref_'+id+'"><img src="http://www.cartoondollemporium.com/cdeprofile/profile/notforsale.gif" /><br /><a href="javascript:void(0);" onclick="checkNotForSale(\'check\', \''+keys[i]+'\', \''+id+'\', \'notforsaleprocess_'+id+'\', \''+userid+'\');">check if for sale</a></span>'; */
						document.getElementById(keys[i]+'_'+showat).style.display = 'inline';
						document.getElementById(keys[i]+'_'+showat+'_loading').style.display = 'none';
					}
				}
				/* document.getElementById('buyitem_'+id).style.display = 'none';
				document.getElementById(showat).innerHTML = '<span id="checkhref_'+id+'"><img src="http://dev.cartoondollemporium.com/cdeprofile/profile/notforsale.gif" /><br /><a href="javascript:void(0);" onclick="checkNotForSale(\'check\', \''+id+'\', \'notforsaleprocess_'+id+'\', \''+userid+'\');">check if for sale</a></span>'; */
			} else if (res == 'forsale') {
				document.getElementById(key+'_'+showat).innerHTML = '';
				if (document.getElementById(key+'_buyitem_'+id).style.display == 'none')
					document.getElementById(key+'_buyitem_'+id).style.display = 'inline';

				fm_showPrice(key+'_item_'+id); //CALL THE SHOW PRICE METHOD FROM fleamarket.js

				if (document.getElementById(key+'_item_'+id+'_div').style.display == 'none')
					document.getElementById(key+'_idDoll'+id+'_buy').checked = false;
				if (document.getElementById(key+'_item_'+id+'_div').style.display == 'inline')
					document.getElementById(key+'_idDoll'+id+'_buy').checked = true;

				for (i=0; i<keys.length; i++) {
					if (key != keys[i]) {
						buyitem = document.getElementById(keys[i]+'_buyitem_'+id);
						if (buyitem != null) {
							if (buyitem.style.display == 'none')
								buyitem.style.display = 'inline';

							//document.getElementById(keys[i]+'_notforsaleprocess_'+id).innerHTML = '';
							document.getElementById(keys[i]+'_'+showat).style.display = 'none';
							document.getElementById(keys[i]+'_'+showat+'_loading').style.display = 'none';

							itemdivdisplay = document.getElementById(keys[i]+'_item_'+id+'_div').style.display;
							if (itemdivdisplay == 'none')
								document.getElementById(keys[i]+'_idDoll'+id+'_buy').checked = false;
							if (itemdivdisplay == 'inline')
								document.getElementById(keys[i]+'_idDoll'+id+'_buy').checked = true;
						}
					}
				}
			}
		} else {
			/* for (i=0; i<keys.length; i++) {
				checkhref = document.getElementById(keys[i]+'_checkhref_'+id);
				if (checkhref != null) {
					checkhref.innerHTML = '<div align="center"><img src="http://dev.cartoondollemporium.com/cdeprofile/images/ajax-loader-bar-circle-blue-white.gif" /><br />checking...</div>';
				}
			} */

			/* checkhref = document.getElementById(key+'_checkhref_'+id);
			if (checkhref != null) {
				checkhref.innerHTML = '<div align="center"><img src="http://www.cartoondollemporium.com/cdeprofile/images/ajax-loader-bar-circle-blue-white.gif" /><br />checking...</div>';
			} */
			for (i=0; i<keys.length; i++) {
				if (document.getElementById(keys[i]+'_'+showat) != null)
					document.getElementById(keys[i]+'_'+showat).style.display = 'none';
				if (document.getElementById(keys[i]+'_'+showat+'_loading') != null)
					document.getElementById(keys[i]+'_'+showat+'_loading').style.display = 'inline';
			}
		}
	}

	xmlhttp.open("GET", url,true);
	xmlhttp.send(null);
}

function checkNotForSale2(action, id, showat, userid) {
	xmlhttp = GetXmlHttpObject();
	//if the browser does not supporting XMLHTTP
	if (xmlhttp==null)
	{
		alert ('Your browser does not support XMLHTTP!');
		return;
	}

	today = new Date(); rand=today.getTime();

	var url = 'ajax_functions/ajax_items_enhancement.html?cache_bust='+rand+'&action='+action+'&id='+id+'&userid='+userid;

	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4) {
			res = xmlhttp.responseText;
			if (res == 'notforsale') {
				document.getElementById('buyitem_'+id).style.display = 'none';
				/* document.getElementById(showat).innerHTML = '<span id="checkhref_'+id+'"><img src="http://www.cartoondollemporium.com/cdeprofile/profile/notforsale.gif" /><br /><a href="javascript:void(0);" onclick="checkNotForSale2(\'check\', \''+id+'\', \'notforsaleprocess_'+id+'\', \''+userid+'\');">check if for sale</a></span>'; */
				document.getElementById(showat).style.display = 'inline';
				document.getElementById(showat+'_loading').style.display = 'none';
			} else if (res == 'forsale') {
				document.getElementById(showat).innerHTML = '';
				if (document.getElementById('buyitem_'+id).style.display == 'none')
					document.getElementById('buyitem_'+id).style.display = 'inline';

				fm_showPrice2('item_'+id); //CALL THE SHOW PRICE METHOD FROM fleamarket.js

				document.getElementById(showat).style.display = 'none';
				document.getElementById(showat+'_loading').style.display = 'none';

				if (document.getElementById('item_'+id+'_div').style.display == 'none')
					document.getElementById('idDoll'+id+'_buy').checked = false;
				if (document.getElementById('item_'+id+'_div').style.display == 'inline')
					document.getElementById('idDoll'+id+'_buy').checked = true;
			}
		} else {
			/* checkhref = document.getElementById('checkhref_'+id);
			if (checkhref != null) {
				checkhref.innerHTML = '<div align="center"><img src="http://www.cartoondollemporium.com/cdeprofile/images/ajax-loader-bar-circle-blue-white.gif" /><br />checking...</div>';
			} */
			document.getElementById(showat).style.display = 'none';
			document.getElementById(showat+'_loading').style.display = 'inline';
		}
	}

	xmlhttp.open("GET", url,true);
	xmlhttp.send(null);
}

function searchItems(action, userid, search, showat, tempShowAt) {
	if (search != '' && search != 'enter item\'s name here..') {
		xmlhttp = GetXmlHttpObject();
		//if the browser does not supporting XMLHTTP
		if (xmlhttp==null)
		{
			alert ('Your browser does not support XMLHTTP!');
			return;
		}

		if (search == 'resetsearch')
			search = '';

		today = new Date(); rand=today.getTime();

		var url = 'ajax_functions/ajax_items_enhancement.html?cache_bust='+rand+'&action='+action+'&uid='+userid+'&search='+search;
		xmlhttp.onreadystatechange = function()
		{
			if (xmlhttp.readyState == 4) {
				if (search == '') {
					document.getElementById('resetsearch').style.display = 'none';
				} else {
					document.getElementById('resetsearch').style.display = 'block';
				}
				document.getElementById(tempShowAt).style.display = 'none';
				document.getElementById(showat).innerHTML = xmlhttp.responseText;
				if ($("itemsListContainer") != null) {
					myItemsSectionList.registerBuyItemFormEvents($("itemsListContainer"));
				}
				if ($("itemsSectionsContainer") != null) {
					registerBuyItemFormEvents($("itemsSectionsContainer"));
				}
			} else {
				document.getElementById('resetsearch').style.display = 'none';
				document.getElementById(showat).innerHTML = '';
				document.getElementById(tempShowAt).style.display = 'block';
			}
		}

		xmlhttp.open("GET", url,true);
		xmlhttp.send(null);
	}
}

function checkSearchValue(value) {
	if (value == 'enter item\'s name here..') {
		document.getElementById('searchValue').value = '';
	} else if (value == '') {
		document.getElementById('searchValue').value = 'enter item\'s name here..';
	}
}

function itemContainerPagination(action, userid, search, cat, cur_page, showat, tempShowAt) {
	if (search != 'enter item\'s name here..') {
		xmlhttp = GetXmlHttpObject();
		//if the browser does not supporting XMLHTTP
		if (xmlhttp==null)
		{
			alert ('Your browser does not support XMLHTTP!');
			return;
		}

		today = new Date(); rand=today.getTime();

		var url = 'ajax_functions/ajax_items_enhancement.html?cache_bust='+rand+'&action='+action+'&uid='+userid+'&search='+search+'&pg='+cur_page+'&category='+cat;
		xmlhttp.onreadystatechange = function()
		{
			if (xmlhttp.readyState == 4) {
				document.getElementById(showat).innerHTML = xmlhttp.responseText;
				if ($("itemsListContainer") != null) {
					myItemsSectionList.registerBuyItemFormEvents($("itemsListContainer"));
				}
				if ($("itemsSectionsContainer") != null) {
					registerBuyItemFormEvents($("itemsSectionsContainer"));
				}
			} else {
				document.getElementById(tempShowAt).innerHTML = '<div align="center"><img src="http://www.cartoondollemporium.com/cdeprofile/images/ajax-loader-bar-circle-blue-white.gif" /><br /><span style="color:#fff; font-size:10px; ">searching...</div>';
			}
		}

		xmlhttp.open("GET", url,true);
		xmlhttp.send(null);
	}
}

/* function show_pack_idea(action, cur_page, showat, tempShowAt) {
	xmlhttp = GetXmlHttpObject();
	//if the browser does not supporting XMLHTTP
	if (xmlhttp==null)
	{
		alert ('Your browser does not support XMLHTTP!');
		return;
	}

	today = new Date(); rand=today.getTime();
	show = '';
	if(document.getElementById('Pack_SortBy') != null) {
		sortby = document.getElementById('Pack_SortBy').value;
		show = '&show=1';
	} else {
		sortby = 1;
	}

	var url = 'packIdea/ajax_pack_idea.html?cache_bust='+rand+'&action='+action+'&pg='+cur_page+'&sortby='+sortby+''+show;
	//showing result

	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4) {
			document.getElementById(showat).innerHTML = xmlhttp.responseText;
		} else {
			document.getElementById(tempShowAt).innerHTML = '<div align="center"><img src="http://dev.cartoondollemporium.com/cdeprofile/images/ajax-loader-bar-circle-blue-white.gif" /><br />loading pack</div>';
		}
	}

	xmlhttp.open("GET", url,true);
	xmlhttp.send(null);
}
 */
function GetXmlHttpObject() {
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}

	if (window.ActiveXObject) {
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}

	return null;
}