// JavaScript Document
//Event.observe(window, 'load', init, false);

function updateMe(index, value)
{
	if(value==true)
		value=1;
	else if(value==false)
		value=0;

	new Ajax.Request('/_site_admin/manage-privacy.htm', {
  	method: 'get',
	parameters: {ajax: 1, value: value, index: index},
	onSuccess: 
		function(t){ 
				}
  	});	
}

function setCursor(obj, cursor)
{	
	//options: default, wait
	//alert(cursor);
	obj.style.cursor = cursor;
}


function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [ myWidth, myHeight ];

}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}




function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/-(w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}


function displayWaitScreen(state) {
	if(state==1) {
		var posx = (getWindowSize()[0]/2);
		var tempy = (getWindowSize()[1]/2)-150;
		var scrolly=getScrollXY()[1];
		var posy = scrolly + tempy;
		var loadingObj=document.getElementById('loading');

		//setup the loading screen
		loadingObj.innerHTML = 
'<table width="300px" border="0" align="center" cellpadding="10" cellspacing="0" bgcolor="#FFFFFF" class="home_snapp_border"><tr><td><table width="240" height="240" border="0" align="center" cellpadding="0" cellspacing="0" background="/images/images_all/images_buttons/popup_animation.gif"><tr><td align="center" valign="top" >&nbsp;</td></tr></table><table align="center" border="0" cellpadding="5" cellspacing="0" width="100%"><tr><td align="center" valign="top" ><strong><font color="#33CC33" size="6" face="Trebuchet MS, Arial">please wait </font></strong></td</tr></table><table width="100%" border="0" align="center" cellpadding="5" cellspacing="0"><tr><td align="center" valign="top"><p><strong><font color="#33CC33" size="3" face="Trebuchet MS, Arial">Your search results will display shortly!</font></strong></p></td></tr></table></td></tr></table>';
		
		
if (navigator.appName == "Microsoft Internet Explorer") {
   loadingObj.style.pixelTop = posy;
   }
else {
   loadingObj.style.top = posy+'px';
   }
		Element.show('loading');	
	} else
	if(state==0)
		Element.hide('loading');
}


function _blog_move(action,posid,web_address,id,columns) {
	
	//setCursor('wait');
	
	new Ajax.Request('right_positioncontent.php', {
  	method: 'get',
	parameters: {action: action, posid: posid, web_address: web_address, id: id, columns: columns},
	onSuccess: 
		function(t){ 
				var result=t.responseText;
				$('itemPositionList').innerHTML = result;
				//setCursor('default');
				}

  	});	

}



//"add","'.$listid.'","'.$amazon_id.'", "'.$user.'","'.$small_image_URL.'","'.$itemCat.'","'.$item_title_encode.'","'.$byLineencode.'"
function ItemAction(action, listnum, amazon_id, small_image_URL, itemCat, item_title_encode, byLineencode) {
		
	if(action=='add') {
		ajax_Addsubmit(action, amazon_id, small_image_URL, itemCat, item_title_encode, byLineencode, listnum);
	}
	if(action=='delete') {
		ajax_Deletesubmit(action, amazon_id, listnum);
	}
}

function _ajax_listAction(action, listnum, itemnum, type) {

	if(action=='delete') {
		_ajax_listDelete(listnum, itemnum, type);
	}
}


function _ajax_listDelete(listnum, itemnum, type) {
	new Ajax.Request('_ajaxListActions.php', {
  	method: 'get',
	parameters: {action: "delete", listid: listnum, itemid: itemnum, type: type},
	onSuccess: 
	
	function(t){ 
			var result=t.responseText;

			if(result=="deleted") {
				Element.hide('custom_'+listnum+'_'+itemnum);
				
			}
	}

	
	
  	});			
	
}


function ajax_Deletesubmit(action, amazon_id, listnum) {

	new Ajax.Request('ajaxItemActions.php', {
  	method: 'get',
	parameters: {action: action, azid: amazon_id, listid: listnum},
	onSuccess: 
	
	function(t){ 
			var result=t.responseText;
			//thisrow = document.getElementById(amazon_id);
			if(result=="deleted") {
				//thisrow.innerHTML = "deleted";
				//alert('deleted');
				Element.hide('delete'+amazon_id);
				
			}
	}
	
	
	
  	});			
	
}

function ajax_Addsubmit(action, amazon_id, small_image_URL, itemCat, item_title_encode, byLineencode, listnum) {

	new Ajax.Request('ajaxItemActions.php', {
  	method: 'get',
	parameters: {action: action, azid: amazon_id, pictureURL: small_image_URL, productCat: itemCat, productTitle: item_title_encode, productInfo: byLineencode, listid: listnum},
	onSuccess: 
	
	function(t){ 
			var result=t.responseText;
			thisrow = document.getElementById(amazon_id);
			if(result=="duplicate") {
				thisrow.innerHTML = "Added!";	
			}
			
			if(result=="inserted") {
				thisrow.innerHTML = "Added!";	
			}
	}
	
	
	
  	});			
	
}

function printAddStatus() {
	document.getElementById('addStatus').innerHTML = "Added!";
}

function addComplete(t, obj){
	//alert(t+' '+obj);
	var result=t.responseText;
	//if(result=="duplicate")
	if(result=="duplicate")
		//printAddStatus();
		alert('You already have this item in your list!');
		
	if(result=="inserted")
		//printAddStatus();
		alert('inserted');
}


function doamazonsubmit(e,category,pagenum, listnum) {
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	if(KeyID==13)
   		ajax_submit(category, pagenum, listnum)
}

function ajax_submit(category, pagenum, listnum) {
	displayWaitScreen(1);
	var searchterms = $('keywordsearch').value;
	new Ajax.Request('ajax_amazonSearch.php', {
  	method: 'get',
  	parameters: {keywords: searchterms, category: category, pagenum: pagenum, listid: listnum},
	onSuccess:searchComplete
  	});
	
}



function searchComplete(t, obj){
	document.getElementById('results').innerHTML = t.responseText;
	displayWaitScreen(0);
}