// ==================================================================================================================================== 
/* SysFileType1.0  */

// Copyright (c) 2009. Syscraft Information System 
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//   * Redistributions of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//   * Redistributions in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//   * Neither the name of Syscraft Information Systems Incorporated nor the names of its
//     contributors may be used to endorse or promote products derived from this
//     software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

/*******************************************************************************
 SysFileType1.0
 This file handles the form file type with progress bar and thum facility
 *******************************************************************************/
// ==================================================================================================================================== 


// <!-- ========================================== START TO GET DOCUMENT WITH =====================================-->
  var docWidth = 0, docHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    docWidth = window.innerWidth;
    docHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    docWidth = document.documentElement.clientWidth;
    docHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    docWidth = document.body.clientWidth;
    docHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + docWidth );
  //window.alert( 'Height = ' + docHeight );
  //alert(docHeight);
//  <!-- ========================================== START TO GET DOCUMENT WITH =====================================-->




// <!-- ========================================== START Browser Information =====================================-->
var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName  = navigator.appName;
var fullVersion  = ''+parseFloat(navigator.appVersion); 
var majorVersion = parseInt(navigator.appVersion,10);
var nameOffset,verOffset,ix;

// In MSIE, the true version is after "MSIE" in userAgent
if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
 //browserName = "Microsoft Internet Explorer";
 browserName = "IE";
 fullVersion = nAgt.substring(verOffset+5);
}
// In Opera, the true version is after "Opera" 
else if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
 browserName = "Opera";
 fullVersion = nAgt.substring(verOffset+6);
}
// In Chrome, the true version is after "Chrome" 
else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
 browserName = "Chrome";
 fullVersion = nAgt.substring(verOffset+7);
}
// In Safari, the true version is after "Safari" 
else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
 browserName = "Safari";
 fullVersion = nAgt.substring(verOffset+7);
}
// In Firefox, the true version is after "Firefox" 
else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
 browserName = "Firefox";
 fullVersion = nAgt.substring(verOffset+8);
}
// In most other browsers, "name/version" is at the end of userAgent 
else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) 
{
 browserName = nAgt.substring(nameOffset,verOffset);
 fullVersion = nAgt.substring(verOffset+1);
 if (browserName.toLowerCase()==browserName.toUpperCase()) {
  browserName = navigator.appName;
 }
}
// trim the fullVersion string at semicolon/space if present
if ((ix=fullVersion.indexOf(";"))!=-1) fullVersion=fullVersion.substring(0,ix);
if ((ix=fullVersion.indexOf(" "))!=-1) fullVersion=fullVersion.substring(0,ix);

majorVersion = parseInt(''+fullVersion,10);
if (isNaN(majorVersion)) {
 fullVersion  = ''+parseFloat(navigator.appVersion); 
 majorVersion = parseInt(navigator.appVersion,10);
}
/*
document.write('Browser name  = '+browserName+'<br>');
document.write('Full version  = '+fullVersion+'<br>');
document.write('Major version = '+majorVersion+'<br>');
document.write('navigator.appName = '+navigator.appName+'<br>');
document.write('navigator.userAgent = '+navigator.userAgent+'<br>');
*/
// <!-- ========================================== END Browser Information =====================================-->







// JavaScript Document
// <!-- ========================================== START PROGRESS BAR =================================-->
var progressbar_width = 300;	
	// =================================================================== //
	var Speed = 50;
	var Speed_1_to_25 = 50;
	var Speed_25_to_50 = 500;
	var Speed_50_to_75 = 1000;
	var Speed_75_to_100 = 1500;
	
	/* Don't change any of these variables */
	var progressbar_steps = 100;	// Total number of progress bar steps.
	var currentStep = 0;
	var dhtmlgoodies_progressPane = false;
	var dhtmlgoodies_progressBar_bg = false;
	var dhtmlgoodies_progressBar_outer = false;
	var dhtmlgoodies_progressBar_txt = false;
	var progressbarWidth;
	var timer,timer2;


	function moveProgressBar(steps){
		if(!dhtmlgoodies_progressBar_bg){
			dhtmlgoodies_progressPane = document.getElementById('dhtmlgoodies_progressPane');
			dhtmlgoodies_progressBar_bg = document.getElementById('dhtmlgoodies_progressBar_bg');
			dhtmlgoodies_progressBar_outer = document.getElementById('dhtmlgoodies_progressBar_outer');
			dhtmlgoodies_progressBar_txt = document.getElementById('dhtmlgoodies_progressBar_txt');
			//progressbarWidth = dhtmlgoodies_progressBar_bg.clientWidth;
		}

		if(!steps){
			dhtmlgoodies_progressBar_outer.style.width = progressbarWidth + 'px';
			dhtmlgoodies_progressBar_txt.innerHTML = '100%';
			//setTimeout('document.getElementById("dhtmlgoodies_progressPane").style.display="none"',50);
			document.getElementById("dhtmlgoodies_progressPane").style.display="none";
				currentStep=1;
				Speed=Speed_1_to_25;
			clearTimeout(timer);
			clearTimeout(timer2);
		}else{
			currentStep+=steps;
			if(currentStep>progressbar_steps) currentStep = progressbar_steps;	
			
			//var width = Math.ceil(progressbarWidth * (currentStep / progressbar_steps));
			var width =currentStep;
			//dhtmlgoodies_progressBar_outer.style.width = width + 'px';
			dhtmlgoodies_progressBar_outer.style.width = (width*(progressbar_width/100)) + 'px';
			//var percent = Math.ceil((currentStep / progressbar_steps)*100);
			var percent = currentStep;
			
			dhtmlgoodies_progressBar_txt.innerHTML = percent + '%';
			
			if(currentStep==progressbar_steps){
				document.getElementById("dhtmlgoodies_progressPane").style.display="none";
				//setTimeout('document.getElementById("dhtmlgoodies_progressPane").style.display="none"',50);
				currentStep=1;
				Speed=Speed_1_to_25;
				clearTimeout(timer);
				clearTimeout(timer2);
			}
		}
		
		
		
		
	}
	
	/* The function below is only needed for this demo
	
	To move the progress bar , call the function moveProgressBar() 
	
	example: 
	moveProgressBar(1)
	to move it one step.
	
	*/
	function demoProgressBar()
	{	
		
		document.getElementById("dhtmlgoodies_progressPane").style.display="block";
		document.getElementById("dhtmlgoodies_progressPane").style.display="block";
		document.getElementById("dhtmlgoodies_progressBar_bg").style.display="block";
		document.getElementById("dhtmlgoodies_progressBar_outer").style.display="block";
		document.getElementById("dhtmlgoodies_progressBar_txt").style.display="block";
			if (currentStep<25) 
			{
					Speed=Speed_1_to_25;
			}
			if (currentStep>25) 
			{
					Speed=Speed_25_to_50;
			}
			if (currentStep>50) 
			{
					Speed=Speed_50_to_75;
			}
			if (currentStep>75) 
			{
					Speed=Speed_75_to_100;
			}			
			if (currentStep>90) 
			{
				currentStep=100;
			}
		
		if(currentStep<progressbar_steps){
			moveProgressBar(1);
			timer=setTimeout('demoProgressBar()',Speed);
		}
	}
	
	function endProgress()
	{
		clearTimeout(timer);
		moveProgressBar(1);
		timer2=setTimeout('endProgress()',1);
	}
	
	//window.onload = demoProgressBar;
	
//	<!-- ========================================== END PROGRESS BAR =====================================-->



//  <!-- ========================================== START AJAX FUNCTIONS =====================================-->
function file_remove(postFileName,UploadPath,Thumb)
{	

	var xmlHttp1;
	function GetXmlHttpObject()
	{
	var xmlHttp1=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp1=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp1=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
				xmlHttp1=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp1;
	}

	function stateChanged() 
	{ 
		if (xmlHttp1.readyState==4)
		{ 
				//alert(xmlHttp1.responseText);
				//alert('HHHHHHHHHHHHH');
				//document.getElementById('detail').innerHTML=xmlHttp1.responseText;
				clearTimeout(timer);
				clearTimeout(timer2);
				currentStep=1;
				Speed=Speed_1_to_25;
				document.getElementById("dhtmlgoodies_progressPane").style.display="none";
				document.getElementById("dhtmlgoodies_progressBar_bg").style.display="none";
				document.getElementById("dhtmlgoodies_progressBar_outer").style.display="none";
				document.getElementById("dhtmlgoodies_progressBar_txt").style.display="none";
				
				document.getElementById('dhtmlgoodies_progressBar_outer').style.width='1px';
				
	   			 window.parent.removeValues((document.fileForm1)[('postFile')].value);	
				(document.fileForm1)[('inputFile')].value="";
				document.getElementById(('text')).innerHTML="";		
				document.getElementById(('text')).style.display="none";
				document.getElementById(('removeId')).style.display="none";		
				document.getElementById('fileForm').style.display='block';
				document.getElementById("dhtmlgoodies_progressPane").style.display="block";
		}
	}
	
	if (postFileName!='')
	{ 
		xmlHttp1=GetXmlHttpObject();
		if (xmlHttp1==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  } 
		var url=removeFileAction+"?postFileName="+postFileName+"&UploadPath="+UploadPath+"&Thumb="+Thumb;
		xmlHttp1.onreadystatechange=stateChanged;
		xmlHttp1.open("GET",url,true);
		xmlHttp1.send(null);
	}

} 
//  <!-- ========================================== END AJAX FUNCTIONS =====================================-->






