// add by zheng on 20091221
document.write('<script src="js/lang.js"></'+'script>'); 

/*
 * This block of code is reposible for changing the online and offline mode of a photo.
 * Author : Indranil Basu.
 */
function OnOffPhoto(photoId,photoOnOff){
	xmlHttp = GetXmlHttpObject();

	if (xmlHttp == null){
		
        // org code before 20091221
        //alert ("Your browser does not support AJAX!");
        
        alert(langObj['Your browser does not support AJAX!']); // add by zheng on 20091221
        
		return;
	}

	var url="photoOnOff.php";
	var param = "";
	param += "photoId=" + photoId;
	param += "&photoOnOff=" + photoOnOff;
	

	//xmlHttp.onreadystatechange = PhotOnOffResult;
	xmlHttp.open("POST",url,false);

	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", param.length);
	xmlHttp.setRequestHeader("Connection", "close");

	xmlHttp.send(param);
	
    if(xmlHttp.status==200) PhotOnOffResult();	
}
function PhotOnOffResult(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState==200){
    	var poor = xmlHttp.responseText;
		var photodetails = poor.split("^");
		var func = 'OnOffPhoto('+photodetails[0]+', ' + ((photodetails[1] == "Offline")? 0:1) + ')';
		if(poor != "Photo update failed!"){
			document.getElementById("btnOnOffPhoto"+photodetails[0]).value = langObj[photodetails[1]];
			document.getElementById("btnOnOffPhoto"+photodetails[0]).setAttribute('onclick',func);
            // org code before 20091221
            //alert("Photo is updated!");
            
            alert(langObj['Photo is updated!']);
                        
		}
		else
			//alert(poor); // org code before 20091225
            alert(langObj[poor]);	// add by zheng on 20091225		
	}
}
/*
 * The block of code ends here.
 */



function deletePhoto(photoId){
    var conf=confirm("你確定要刪除此作品嗎？");
    if(conf)	
    {	
    	xmlHttp = GetXmlHttpObject();
    
    	if (xmlHttp == null){
    	   
    		// org code before 20091221
            //alert ("Your browser does not support AJAX!");
            
            alert (langObj['Your browser does not support AJAX!']);// add by zheng on 20091221;        
    
    		return;
    	}
    
    	var url="photoOnOff.php";
    	var param = "";
    	param += "photoId=" + photoId;
    	param += "&type=" + "delete";
    	
//    	xmlHttp.onreadystatechange = PhotoDeleteResult;
    	xmlHttp.open("POST",url,false);
    
    	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    	xmlHttp.setRequestHeader("Content-length", param.length);
    	xmlHttp.setRequestHeader("Connection", "close");
    
    	xmlHttp.send(param);
    	
        if(xmlHttp.status==200) PhotoDeleteResult(photoId);    	
    }	
}
function PhotoDeleteResult(id){
	if (xmlHttp.readyState==4 || xmlHttp.readyState==200){
    	var pdr = xmlHttp.responseText;
    	
    	if(pdr == "Artist Product Photo Deletion Completed!")
    	{
    	    var tbody = document.getElementById("tbody"+id);
            tbody.parentNode.removeChild(tbody);     
    	}
    	else
    	   alert(langObj[pdr]);
    		
		//alert(pdr);  // org code before 20091225
		//alert(langObj[pdr]);
		//window.location = 'intropage.php?id=' + document.getElementById('hidddartistId').value;
	}
}


function editPhoto(photoId, artistId){
	window.location = "artistproductedit.php?id=" + photoId + "&artist_id=" + artistId;
}

function newPhoto(artistId){
	window.location = "artistproductedit.php?artist_id=" + artistId;
}

