function checkImage(img)
{
	if(img.indexOf("?")>=0) return(false);
	
	msg=sjax_load("/checkImage.php?img="+img);

	if(msg=="")
	{
		images=document.getElementsByTagName("img");
		for(x=0;x<images.length;x++)
		{
			if(images[x].src.indexOf(img)>=0)
			{
				images[x].src = img + "?t=" + x;
			}
		}
	}
	else
	{
		if(confirm(msg+"\n\nReload this page?")) self.location = self.location;
	}
}

function toggle_lock(id,table,div,code)
{
	var msg=sjax_load('/lock.php?f1='+id+'&f2='+table);
	if(msg!="") alert(msg);
	show_code(div,code,"prod&edit=edit");
}


function show_code(div,code,mode)
{
	var pause=5000;
	var msg=document.getElementById('pause_message');
	if(msg!=undefined && msg.innerHTML.indexOf('You are out of lookup credits')==0)
	{
		pause=1000;
	}
	if(mode.indexOf("edit=edit")>0)
	{
		pause=1;
	}
	setTimeout("ajax_load('"+div+"','/lookup.php','extra=x&code="+code+"&mode="+mode+"')",pause);
}

function helpValidate()
{
	content = "You have the ability to ACCEPT or DELETE the proposed change to this code "
	        + "You will receive 1 lookup credit for each item you accept or delete. Please "
            + "take this seriously. If you accept and delete things in an inapropriate way "
            + "your access will be reduced and you will no longer be able to accept, delete "
            + "or update any information onthis system.<br><br>"
            + "You DO NOT need to examine the content of each entry for complete accuracy. "
            + "You should check the WEB SITE link to make sure it is correct. For the other items "
            + "such as PRODUCT, DESCRIPTOIN and CATEGORY you only need to be sure the entry is "
            + "reasonable. No bad language or references to web sites. You can't be expected to "
            + "know what every product is. Just make sure the information seems correct."
            + "<br><br>Basically, just do your best to help keep our data clean and useful to others."
            + "<br><br><br><img src='/icon/16_accept.png'> If the content looks correct, click this icon to accept the change."
            + "<br><br><img src='/icon/16_delete.png'> If the content looks wrong or inapropriate, click this icon to delete it."
	show_dialog("Help Keep Our Data Clean",content);
}

function helpPending()
{
	content = "You are the person that entered this pending item. You will receive your credits "
	        + "as soon as this change is validated by another user. This can take several days but "
            + "should never take more than a week."
            + "<br><br>"
            + "We are sorry that you must wait though this delay, but it is the best way we know of "
            + "to keep our data somewhat clean. Once you have entered enough updates and they have been "
            + "approved, your access will be increased and you will no longer need to wait for your "
            + "changes to be approved."
            + "<br><br>"
            + "Until that time, we hope you understand. Thank you for updating our information!"
            + "<br><br><br><br><img src='/icon/16_delete.png'> "
            + "If you made a mistake while entering your change, you are welcome to delete your own "
            + "entry. You will not receive any credits or a penelty for this deletion. You may then "
            + "make a new entry if you wish (or not).";
	show_dialog("Your Change Is Pending",content);
}

function acceptValue(mode,id,field,pend,blank,field2,pend2,no_conf,exec_after)
{
	var o=document.getElementById("upc_"+mode+"_"+field+"_o").innerHTML;
	var p=document.getElementById("upc_"+mode+"_"+field+"_p").innerHTML;
	if(o=="" || blank)
	{
		o="\nreplacing a previously blank entry";
	}
	else
	{
		o="\nreplacing the old value of\n\t"+o;
	}
	if(exec_after==undefined) 
	{
		exec_after="";
	}
	if(no_conf==undefined || no_conf!=1)
	{
		go=confirm("You are about to accept the new value of\n\t"+p+o+".");
	}
	else
	{
		go=true;
	}
	if(go)
	{
		ajax_load("upc_"+mode+"_"+field,"/upc_save_changes.php","mode="+mode+"&dispvalue="+escape(pend)+"&action=accept&id="+id+"&field="+field2+"&value="+escape(pend2),exec_after);
	}
}

function deleteValue(mode,id,field,pend,sd)
{
	var p=document.getElementById("upc_"+mode+"_"+field+"_p").innerHTML;

	if(sd!=undefined)
	{
		reason="self delete";
		if(!confirm("You are about to delete a value you entered\n\t"+p)) return(false);
	}
	else
	{
		reason=prompt("You are about to delete the value\n\t"+p+"\n\n\nPlease give a short reason for this deletion.");
	}
	if(reason==null)
	{
		// Do nothing, the user canceled the deletion.
	}
	if(reason.length<3)
	{
		alert("Please give a bit more information about this deletion.\n\nSome short examples:\n\tabsene\n\tgarbage\n\tadvertisement\n\twrong info\n\nJust put something to let the enterer know why their entry was removed.")
	}
	else
	{
		ajax_load("upc_"+mode+"_"+field,"/upc_save_changes.php","mode="+mode+"&action=delete&id="+id+"&field="+field+"&value="+escape(pend)+"&reason="+escape(reason));
	}
}

function saveValue(mode,id,field)
{
	var v=document.getElementById("upc_"+mode+"_"+field+"_input").value;
	if(field=="category")
	{
		ajax_load("upc_"+mode+"_cat_path","/upc_save_changes.php","mode="+mode+"&id="+id+"&field="+field+"&value="+escape(v));
	}
	else
	{
		ajax_load("upc_"+mode+"_"+field,"/upc_save_changes.php","mode="+mode+"&id="+id+"&field="+field+"&value="+escape(v));
	}
}

function acceptImage(id,check,exec_after)
{
	if(confirm("You are about to accept the new image."))
	{
		if(exec_after==undefined)
		{
			ajax_load("image","/accept_image.php","code="+id+"&file="+check);
		}
		else
		{
			ajax_load("image","/accept_image.php","code="+id+"&file="+check,exec_after);
		}
	}
}

function deleteImage(id,check,exec_after)
{
	if(confirm("You are about to delete the new image."))
	{
		if(exec_after==undefined)
		{
			ajax_load("image","/delete_image.php","code="+id+"&file="+check);
		}
		else
		{
			ajax_load("image","/delete_image.php","code="+id+"&file="+check,exec_after);
		}
	}
}


