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

function setonlineExhibition(id){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
        
        //org code before 20091218
        //alert ("Your browser does not support AJAX!");
        
        //add by zheng on 20091218
        alert (langObj['Your browser does not support AJAX!']);
        
		return;
	}
	var url="exhibitionoperation.php";
	var param = "";
	param += "id="+id;
	param += "&op=on";
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", param.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(param);
}

function setofflineExhibition(id){
xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
        
        //org code before 20091218
        //alert ("Your browser does not support AJAX!");
        
        //add by zheng on 20091218
        alert (langObj['Your browser does not support AJAX!']);
        
		return;
	}
	var url="exhibitionoperation.php";
	var param = "";
	param += "id="+id;
	param += "&op=off";
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", param.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(param);
}
function delExhibition(id){
var conf=confirm("你確定要刪除此藝廊嗎？");
if(conf==1){
xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
        
        //org code before 20091218
        //alert ("Your browser does not support AJAX!");
        
        //add by zheng on 20091218
        alert (langObj['Your browser does not support AJAX!']);
        
		return;
	}
	var url="exhibitionoperation.php";
	var param = "";
	param += "id="+id;
	param += "&op=del";
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", param.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(param);

}
}
/*function nnewExhibition()
{

document.getElementById("edit").value="0";
document.getElementById("nw").value="1";
document.galleryedit.submit();


}*/
function editgallery(id){
window.location='galleryedit.php?op=edita&id='+id;
}
function newExhibition(){
window.location='galleryedit.php?op=newa&id=';
}
function updateExhibition(){
var yr=document.getElementById("exedyr").value;
var mn=document.getElementById("exedmn").value;
var dd=document.getElementById("exeddd").value;
var flagenddate=datecheck(yr,mn,dd);
if(flagenddate !=1){
alert('請輸入正確日期');
document.getElementById("exedyr").focus();
return false;
}
var yr=document.getElementById("exstyr").value;
var mn=document.getElementById("exstmn").value;
var dd=document.getElementById("exstdd").value;
var flagstartdate=datecheck(yr,mn,dd);
if(flagstartdate !=1){
alert('請輸入正確日期');
document.getElementById("exstyr").focus();
return false;
}

if(testtitle()){
document.getElementById("edit").value="1";
document.getElementById("nw").value="0";
document.getElementById("delt").value="0";
document.getElementById("online").value="0";
document.getElementById("offline").value="0";
document.galleryedit.submit();
}
}
function datecheck(yr,mn,dd){
var  dateStr=dd+"/"+mn+"/"+yr;

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?

if (matchArray == null) {
//alert("Please enter your birth date as dd/mm/yyyy. Your  selection reads:"+dateStr );
return 0;
}

day = matchArray[1]; // p@rse date into variables
month = matchArray[3];
year = matchArray[5];

if (month < 1 || month > 12) { // check month range
//alert("Month must be between 1 and 12.");
return 0;
}

if (day < 1 || day > 31) {
//alert("Day must be between 1 and 31.");
return 0;
}

if ((month==4 || month==6 || month==9 || month==11) && day==31) {
//alert("Month "+month+" doesn`t have 31 days!");
return 0;
}

if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day > 29 || (day==29 && !isleap)) {
//alert("February " + year + " doesn`t have " + day +  "days!");
return 0;
}
}
return 1; // date is valid


}
function cancelExhibition()
{
if((document.getElementById("exhibitionTitle").value=="" || document.getElementById("exhibitiontitlecontent").value=="" ) && document.getElementById("svda").value==1)
{
id=document.getElementById("exid").value;
saveExhibition(id);
}
else
window.location="gallery.php";
}
function stateChanged(){
    if (xmlHttp.readyState==4 || xmlHttp.readyState==200){
        var ss=xmlHttp.responseText;
        
        //alert(ss);  // org code before 20091222
        
        alert(langObj[ss]);  // add by zheng on 20091222
        
        window.location="gallery.php";
    }
}
function GetXmlHttpObject(){
var xmlHttp=null;
try{
    xmlHttp=new XMLHttpRequest();
    }
catch (e){
    try{
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
    catch (e){
	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
    }

return xmlHttp;
}
function openartist(id){
//id="'"+id+"'";
window.location="intropage.php?id="+document.getElementById(id).value;
}
function changehistory()
{
window.location="gallery.php?his="+document.getElementById("mainselect").value;
}
function gethistory()
{
window.location="setexhibitionorder.php?his="+document.getElementById("mainselect").value;
}
function chooseartist(){
//alert(document.getElementById("artname").value);
xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
        
        //org code before 20091218
        //alert ("Your browser does not support AJAX!");
        
        //add by zheng on 20091218
        alert (langObj['Your browser does not support AJAX!']);
        
		return;
	}
	var url="getfolder.php";
	var param = "";
	param += "id="+document.getElementById("artname").value;
	param += "&exid="+document.getElementById("exid").value;
//alert(param);
	
	xmlHttp.onreadystatechange=setfolder;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", param.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(param);
}
function setfolder(){
if (xmlHttp.readyState==4 || xmlHttp.readyState==200){
    var ss=xmlHttp.responseText;
//alert(ss);
document.getElementById("folderch").innerHTML=ss;
  // document.getElementById("folderch").innerHtml=ss;
   
    }
}

function testtitle(){
	/*if(document.getElementById("exhibitiontitlecontent").value.length > 280){
		alert("Please limit this length within 280 characters");
		document.getElementById("exhibitiontitlecontent").focus();
		document.getElementById("exhibitiontitlecontent").select();
		return false;
	}*/
	return true;
}

function setpermission(eid,pid,fl)
{	
//alert(eid+pid+fl);
document.getElementById("svda").value=1;

    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        
        // org code before 20091218
        //alert ("Your browser does not support AJAX!");
        
        //add by zheng on 20091218
        alert (langObj['Your browser does not support AJAX!']);
             
        return;
    }
 
 	
 	var url="publishgallery.php";
 	var param="eid=" + eid + "&pid=" + pid+ "&fl=" + fl;
	//alert('before');
 	//xmlHttp.ds=eid;
 	//alert('aftere');
	xmlHttp.onreadystatechange=setoptval;
 	xmlHttp.open("POST",url,true);
 	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 	xmlHttp.setRequestHeader("Content-length", param.length);
 	xmlHttp.setRequestHeader("Connection", "close");
 	xmlHttp.send(param);
}
function saveExhibition(id){
var yr=document.getElementById("exedyr").value;
var mn=document.getElementById("exedmn").value;
var dd=document.getElementById("exeddd").value;
var flagenddate=datecheck(yr,mn,dd);
if(flagenddate !=1){
    
    // org code before 20091221
    //alert('Please Enter Valid Date');
    
    alert(langObj['Please Enter Valid Date']); // add by zheng on 20091221
      
    document.getElementById("exedyr").focus();
    return false;
}
var yr=document.getElementById("exstyr").value;
var mn=document.getElementById("exstmn").value;
var dd=document.getElementById("exstdd").value;
var flagstartdate=datecheck(yr,mn,dd);
if(flagstartdate !=1){
    
    // org code before 20091221
    //alert('Please Enter Valid Date');
    
    alert(langObj['Please Enter Valid Date']); // add by zheng on 20091221    
    
document.getElementById("exstyr").focus();
return false;
}

if(testtitle()){
document.getElementById("edit").value="0";
document.getElementById("nw").value="1";
document.getElementById("exid").value=id;
document.galleryedit.submit();
}


}

function setoptval()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState==200)
{
	var ss=xmlHttp.responseText;
	var myvars=ss.split("#");
  // alert(myvars[0]+"  "+myvars[1]);
setdisplay(myvars[1]);

}
}
function changepriority(exid,fdid,val,direction){

//val=document.getElementById(id).value;
  xmlHttp=GetXmlHttpObject()
 if (xmlHttp==null)
 {
    
    // org code before 20091218
    //alert ("Your browser does not support AJAX!");
    
    //add by zheng on 20091218
    alert (langObj['Your browser does not support AJAX!']);
        
    return;
 }
 
 	
 	var url="setpriorityexhibition.php";
 	var param="exid=" + exid + "&fdid=" + fdid+ "&val=" + val+"&direction=" + direction;
 	xmlHttp.myvar1=exid;
 	xmlHttp.onreadystatechange=displaychange;
 	xmlHttp.open("POST",url,true);
 	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 	xmlHttp.setRequestHeader("Content-length", param.length);
 	xmlHttp.setRequestHeader("Connection", "close");
 	xmlHttp.send(param);
}

function changepriorityexhibition(exid,val,dt,direction){
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
    
        // org code before 20091218
        //alert ("Your browser does not support AJAX!");
        
        //add by zheng on 20091218
        alert (langObj['Your browser does not support AJAX!']);
            
    	return;
	}

	var url="setorderexhibition.php";
	var param="exid=" + exid + "&val=" + val+ "&direction=" + direction+ "&dt=" + dt;
	xmlHttp.myvar1=dt;
	xmlHttp.onreadystatechange=displaychangeexhi;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", param.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(param);

}

function displaychange()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState==200)
{
    var ss=xmlHttp.responseText;
  setdisplay(xmlHttp.myvar1);

}
}


function displaychangeexhi(){

	if (xmlHttp.readyState==4 || xmlHttp.readyState==200){
		var ss=xmlHttp.responseText;
		if(ss=="Done")
		setexhidisplay(xmlHttp.myvar1);
		else
		alert("此日期無法移動");
	}
}

function setdisplay(exid,stdt){

xmlHttp=GetXmlHttpObject()
 if (xmlHttp==null)
 {
    
    // org code before 20091218
    //alert ("Your browser does not support AJAX!");
    
    //add by zheng on 20091218
    alert (langObj['Your browser does not support AJAX!']);
        
    return;
 }
 
//  	var yr=document.getElementById("exstyr").value;
// 	var mn=document.getElementById("exstmn").value;
// 	var dd=document.getElementById("exstdd").value;
//        var stdt=yr+"-"+mn+"-"+dd;

 	var url="displayfolder.php";
 	var param="id=" + exid ;
	//var param="&stdt=" + stdt ;
 	xmlHttp.onreadystatechange=displayfolder;
 	xmlHttp.open("POST",url,true);
 	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 	xmlHttp.setRequestHeader("Content-length", param.length);
 	xmlHttp.setRequestHeader("Connection", "close");
 	xmlHttp.send(param);

}
function setexhidisplay(dt){

xmlHttp=GetXmlHttpObject()
 if (xmlHttp==null)
 {
    
    // org code before 20091218
    //alert ("Your browser does not support AJAX!");
    
    //add by zheng on 20091218
    alert (langObj['Your browser does not support AJAX!']);
        
    return;
 }
 
 	
 	var url="displayexhibition.php";
 	var param="dt=" + dt ;
 	xmlHttp.onreadystatechange=displayexhibition;
 	xmlHttp.open("POST",url,true);
 	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 	xmlHttp.setRequestHeader("Content-length", param.length);
 	xmlHttp.setRequestHeader("Connection", "close");
 	xmlHttp.send(param);

}
function displayfolder(){
if (xmlHttp.readyState==4 || xmlHttp.readyState==200)
{
var ss=xmlHttp.responseText;
document.getElementById("glryResult").innerHTML=ss;

}
}
function displayexhibition(){
if (xmlHttp.readyState==4 || xmlHttp.readyState==200)
{
var ss=xmlHttp.responseText;
document.getElementById("glryResult").innerHTML=ss;

}
}
function priorityExhibition()
{
window.location="setexhibitionorder.php";
}





/*
 *
 */
function getExhibitionArtistProductDetails(artistProductsId){
	//alert(artistProductsId)
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
        
        // org code before 20091218
        //alert ("Your browser does not support AJAX!");
        
        //add by zheng on 20091218
        alert (langObj['Your browser does not support AJAX!']);
            
		return;
	}
	var url="imageGalleryArtist.php";
	var param = "";
	param += "artistProductsId="+artistProductsId;
//alert(param)
	xmlHttp.onreadystatechange=getExhibitionArtistProductDetailsResult;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", param.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(param);

}
function getExhibitionArtistProductDetailsResult(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState==200)
	{
    		var geapdr = xmlHttp.responseText;
		//alert(geapdr)
		var elem = geapdr.split("^");
		document.getElementById('divArtName').innerHTML = elem[0];
		document.getElementById('divProCont').innerHTML = elem[1];

	}
}

