//load xml content into main page
function loadXMLDoc(boxid, type, customwidth, customheight){
	var xmlhttp;
	var imglistplayerid = "img"+boxid+"player";
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function(){
  		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			if(type == 0){
				document.getElementById("data0").innerHTML=xmlhttp.responseText;
				new dk_slideplayer("#"+imglistplayerid,{width:"622px",height:"315px",fontsize:"12px",time:"2000"});
			}else if(type == 1){
				document.getElementById("data1").innerHTML=xmlhttp.responseText;
			}else if(type == 2){
				document.getElementById("data2").innerHTML=xmlhttp.responseText;
			}else if(type == 3){
				document.getElementById("data3").innerHTML=xmlhttp.responseText;
				new dk_slideplayer("#"+imglistplayerid,{width:"622px",height:"472px",fontsize:"12px",time:"2000"});
			}else if(type == 5){
				document.getElementById("data5").innerHTML=xmlhttp.responseText;
			}else if(type == 6){
				document.getElementById("data6").innerHTML=xmlhttp.responseText;
			}
			else if(type == 7){
				document.getElementById("data7mm").innerHTML=xmlhttp.responseText;
				var updatedcswidth = parseInt(customwidth) - 2;
				var updatedcsheight = parseInt(customheight) - 2;
				new dk_slideplayer("#"+imglistplayerid,{width:+updatedcswidth+"px",height:+updatedcsheight+"px",fontsize:"12px",time:"2000"});
			}
			flowplayer("player", "./js/flowplayer/flowplayer-3.2.7.swf", {
    			clip:  {
        			autoPlay: false,
					autoBuffering: true,
        			bufferLength: 10,
					onFinish:function() {
        				this.getPlugin("play").css({opacity:0})
        			}
    			}
			});			
			
    	}
  	}
	xmlhttp.open("GET","fetch.php?box="+boxid+"&action=1",true);
	xmlhttp.send();
}

function loadXMLDocContent(xmlitemid, boxid, type){
	var char = xmlitemid.substring(xmlitemid.length-1, xmlitemid.length);	
	var imglistplayerid = "img"+boxid+char+"player";
	var xmlhttp;
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function(){
  		if (xmlhttp.readyState==4 && xmlhttp.status==200){
    		if(type == 0){
				document.getElementById("data0").innerHTML=xmlhttp.responseText;
			}else if(type == 1){
				document.getElementById("data1").innerHTML="<div>"+xmlhttp.responseText+"</div>";
				document.getElementById("data1").innerHTML+="<div style='z-index:9999;position:absolute;top:0;left:0;width:30px;height:30px;background:url(./img/fancy_nav_left.png) no-repeat;cursor:pointer;' onclick='loadXMLDoc(\""+boxid+"\", \""+type+"\", \"0\", \"0\");'></div>";
				new dk_slideplayer("#"+imglistplayerid,{width:"622px",height:"315px",fontsize:"12px",time:"2000"});
				
			}else if(type == 2){
				
				document.getElementById("data2").innerHTML="<div>"+xmlhttp.responseText+"</div>";
				document.getElementById("data2").innerHTML+="<div style='z-index:9999;position:absolute;top:0;left:0;width:30px;height:30px;background:url(./img/fancy_nav_left.png) no-repeat;cursor:pointer;' onclick='loadXMLDoc(\""+boxid+"\", \""+type+"\", \"0\", \"0\");'></div>";
				new dk_slideplayer("#"+imglistplayerid,{width:"622px",height:"472px",fontsize:"12px",time:"2000"});
				
			}else if(type == 3){
				document.getElementById("data3").innerHTML=xmlhttp.responseText;
			}else if(type == 5){
				document.getElementById("data5").innerHTML=xmlhttp.responseText;
			}else if(type == 6){
				document.getElementById("data6").innerHTML=xmlhttp.responseText;
			}
			flowplayer("player", "./js/flowplayer/flowplayer-3.2.7.swf", {
    			clip:  {
        			autoPlay: false,
					autoBuffering: true,
        			bufferLength: 10,
					onFinish:function() {
        				this.getPlugin("play").css({opacity:0})
					}
    			}
			});
    	}
  	}
	xmlhttp.open("GET","fetch.php?box="+boxid+"&action=2&xmlitemid="+xmlitemid,true);
	xmlhttp.send();
}

//========================================

//load xml content into vertical page
function loadXMLDocVerticalContent6square(xmlitemid, xmlitemtype, boxid){
	//var xmlitemfullid = "vp-sixsm"+xmlitemid+"-"+xmlitemtype;	
	var imglistplayerid = "img"+boxid+xmlitemid+xmlitemtype+"player";
	var displayid = "show-"+xmlitemtype+"-"+boxid;
	var xmlhttp;
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function(){
  		if (xmlhttp.readyState==4 && xmlhttp.status==200){
    		document.getElementById(displayid).innerHTML='<div>'+xmlhttp.responseText+'</div>';
			document.getElementById(displayid).innerHTML+='<div style="z-index:9999;position:absolute;top:0;left:0;width:30px;height:30px;background:url(./img/fancy_nav_left.png) no-repeat;cursor:pointer;" onclick="loadXMLDocVertical6square(\''+boxid+'\', \''+xmlitemtype+'\');"></div>';
			new dk_slideplayer("#"+imglistplayerid,{width:"622px",height:"315px",fontsize:"12px",time:"3000"});
			flowplayer("player", "./js/flowplayer/flowplayer-3.2.7.swf", {
    			clip:  {
        			autoPlay: false,
					autoBuffering: true,
        			bufferLength: 10,
					onFinish:function() {
        				this.getPlugin("play").css({opacity:0})
        			}
   				}
			});
    	}
  	}
	xmlhttp.open("GET","fetch.php?box="+boxid+"&action=3&xmlitemid="+xmlitemid+"&xmlitemtype="+xmlitemtype,true);
	xmlhttp.send();
}

//load 6 square box back
function loadXMLDocVertical6square(boxid, xmlitemtype){
	var xmlhttp;
	var displayid = "show-"+xmlitemtype+"-"+boxid;
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			document.getElementById(displayid).innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","fetch.php?box="+boxid+"&action=4&xmlitemtype="+xmlitemtype,true);
	xmlhttp.send();
}

//load xml content into vertical page
function loadXMLDocVerticalContent9square(xmlitemid, xmlitemtype, boxid){
	//var xmlitemfullid = "vp-ninesm"+xmlitemid+"-"+xmlitemtype;	
	var imglistplayerid = "img"+boxid+xmlitemid+xmlitemtype+"player";
	var displayid = "show-"+xmlitemtype+"-"+boxid;
	var xmlhttp;
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function(){
  		if (xmlhttp.readyState==4 && xmlhttp.status==200){
    		document.getElementById(displayid).innerHTML='<div>'+xmlhttp.responseText+'</div>';
			document.getElementById(displayid).innerHTML+='<div style="z-index:9999;position:absolute;top:0;left:0;width:30px;height:30px;background:url(./img/fancy_nav_left.png) no-repeat;cursor:pointer;" onclick="loadXMLDocVertical9square(\''+boxid+'\', \''+xmlitemtype+'\');"></div>';
			
			new dk_slideplayer("#"+imglistplayerid,{width:"622px",height:"472px",fontsize:"12px",time:"3000"});
			flowplayer("player", "./js/flowplayer/flowplayer-3.2.7.swf", {
    			clip:  {
        			autoPlay: false,
					autoBuffering: true,
        			bufferLength: 10,
					onFinish:function() {
        				this.getPlugin("play").css({opacity:0})
        			}
    			}
			});
    	}
  	}
	xmlhttp.open("GET","fetch.php?box="+boxid+"&action=5&xmlitemid="+xmlitemid+"&xmlitemtype="+xmlitemtype,true);
	xmlhttp.send();
}

//load 9 square box back
function loadXMLDocVertical9square(boxid, xmlitemtype){
	var xmlhttp;
	var displayid = "show-"+xmlitemtype+"-"+boxid;
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			document.getElementById(displayid).innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","fetch.php?box="+boxid+"&action=6&xmlitemtype="+xmlitemtype,true);
	xmlhttp.send();
}

//========================================

//functions to get specific variable from dynamic URL
function gup( name ){
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

//funciton to create the new pop-up window for vertical page
function verticalPreviewPopup(url) {
    popupWindow = window.open(
	url,"previewPopup","height=900,width=1400,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=no");
}
//funciton to create the new pop-up window for main page
function mainPreviewPopup(url) {
    popupWindow = window.open(
	url,"previewPopup","height=900,width=1400,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=no");
}

//funciton to create the new pop-up window
function newPopup(url) {
    popupWindow = window.open(
	url,"newPopup","height=750,width=1000,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=no");
}

function confirmproceed(){
	var answer = confirm ("Are you sure to proceed?")
	if (answer)
		return true;
	else
		return false;
}

function confirmproceedcreatehiddenvp(){
	var vphiddenfiletitle = document.getElementById("vphiddenfiletitle").value;
	var filetitlecheck = false; var confirmcheck = false;
	
	if(vphiddenfiletitle == ""){
		filetitlecheck = false;
		alert("Pleaes specify a name for file title");
	}else{
		filetitlecheck = true;
		var answer = confirm ("Are you sure to proceed?")
		if (answer)
			confirmcheck = true;
		else
			confirmcheck = false;
	}
	
	if(filetitlecheck == true && confirmcheck == true){
		return true;
	}else{
		return false;	
	}
}

