function testAlert() {
	alert("I am an alert box!");
	
	//<input type="button" onClick="testAlert();" value="test!!" />
}


//-------------------------------------
function makesure(link) {
	var href;
	href = link;
	if(confirm('Are you sure?')) {
		window.location=href;
	} else {
		return false;
	}
}


//---------------------------------------------------------
function display(xxx) {
	
	//alert('shit!');
	
	if(document.getElementById(xxx).style.display == 'none') {
		document.getElementById(xxx).style.display = 'block';
	} else {
		document.getElementById(xxx).style.display = 'none';
	}
	
	return;
}



//-----------------------------------------------------------
function popup(mylink, windowname) {
	var href;
	href=mylink;
	window.open(href, windowname);
	return false;
}



//-----------------------
function onloading(divid) {
	document.getElementById("loading"+divid).style.display = "block";
}

//-----------------------
function stoploading(divid) {
	document.getElementById("loading"+divid).style.display = "none";
}


//-------------------------------------
function AJAX(){

	try {
		xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
		return xmlHttp;
		
	} catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
			return xmlHttp;
			
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				return xmlHttp;
			} catch (e) {
				alert("Your browser does not support AJAX.");
				return false;
			}
		}
	}
}

//-------------
function check_limit(proofid, limit) {

	var xmlHttp_three = AJAX();
	
	xmlHttp_three.onreadystatechange = function() {
		if(xmlHttp_three.readyState == 4){
			var xvalue = xmlHttp_three.responseText;
			if(xvalue == limit) {
				alert('Oops! You have reached the album\'s limit.');				
				stoploading(divid);
			}

			
		}
	}
	
	var queryString_three = "/ajax_cklimit.php?proofid=" + proofid;
	xmlHttp_three.open("GET",queryString_three,true);
	xmlHttp_three.send(null);
	
}



//--------------
function refreshFave(faveid, totalimg, divid) {
	
	
	
	var xmlHttp_three = AJAX();

	xmlHttp_three.onreadystatechange = function(){
		if(xmlHttp_three.readyState == 4){
			document.getElementById('refreshDiv').innerHTML = xmlHttp_three.responseText;
			
			stoploading(divid);
		}
	}

	var queryString_three = "/ajax_refresh.php?proofid=" + faveid + "&totalimg=" + totalimg;
	xmlHttp_three.open("GET",queryString_three,true);
	xmlHttp_three.send(null);
	

}

//--------------
function favethis(divid, proofid, limit, totalimg) {
	
	check_limit(proofid, limit);
	
	onloading(divid);
	
	var xmlHttp_one = AJAX();

	xmlHttp_one.onreadystatechange = function(){
		if(xmlHttp_one.readyState == 4){
			document.getElementById('ajaxDiv' + divid).innerHTML = xmlHttp_one.responseText;
			
			refreshFave(proofid, totalimg, divid);
			
			
		}
	}

	var faveimg = document.getElementById('fave-img' + divid).value;
	var queryString = "/ajax_fave.php?faveid=" + proofid + "&faveimg=" + faveimg + "&xxkey=" + divid + "&totalimg=" + totalimg;
	xmlHttp_one.open("GET",queryString,true);
	xmlHttp_one.send(null);
	
	event.preventDefault();
}

//--------------
function unfavethis(divid, proofid, totalimg) {
	
	onloading(divid);
	
	var xmlHttp_two = AJAX();

	xmlHttp_two.onreadystatechange = function(){
		if(xmlHttp_two.readyState == 4){
			document.getElementById('ajaxDiv' + divid).innerHTML = xmlHttp_two.responseText;
			
			refreshFave(proofid, totalimg, divid);
			
		
		}
	}
	
	var unfaveimg = document.getElementById('unfave-img' + divid).value;
	var queryString = "/ajax_unfave.php?unfaveid=" + proofid + "&unfaveimg=" + unfaveimg + "&unxxkey=" + divid + "&totalimg=" + totalimg;
	xmlHttp_two.open("GET",queryString,true);
	xmlHttp_two.send(null);
	
	event.preventDefault();
	
}




//------------------------------
function makesure(link, msg) {

	var href;
	
	href = link;
	
	if(confirm(msg)) {
	
		window.location=href;
		
	} else {
	
		return false;
		
	}
}
















