/*
var startProgress = false
var startProgressMail = false
var ProgressPath = ""
var progressBar = ""
var UploadID = ""
var ListVal = ""
var TempPath = ""
*/

var GoUpload
var imgUpload = new Image();

function ProgressBar(){
	GoUpload = true
	var FileFind = false
	if(ListVal!=""){
		var FieldListVal = ListVal.split("|")
		for(i=0;i<FieldListVal.length;i++){
			FieldVal = FieldListVal[i].split(";")
			var FileName = "file:///"+Dwz_findObj(FieldVal[0]).value
			if(FileName!="file:///"){
				var FileFind = true
				FileObj(FileName,FieldVal[1],FieldVal[2],FieldVal[3],FieldVal[4]);
				FileExt = FileName.substring(FileName.lastIndexOf(".")).toLowerCase()
				if((FileExt==".gif") || (FileExt==".jpg") || (FileExt==".jpeg") || (FileExt==".png") || (FileExt==".bmp")){ 
					t=0; while(imgUpload.fileSize==-1){t+=1; if(t>1000000){break}}
				}
				VerifyFile()
			}
		}
	}
	if(!GoUpload){
		alert("Upload Aborted")
		return false
	}
		
	if(startProgress && FileFind){
		var ProgressURL
		var PosL = (screen.width/2)-150
		var PosT = (screen.height/2)-110
		if(startProgressMail){prgMail="1"}else{prgMail="0"}
		ProgressURL = ProgressPath + "AspNetMailFiles/FrameSet.aspx?ProgressBarType=" + ProgressBarType + "&UploadID=" + UploadID + "&ProgressMailBarType=" + ProgressMailBarType + "&TempPath=" + TempPath
		var v = window.open(ProgressURL,'progressBarPage','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=350,height=210,top='+PosT+',left='+PosL)
	}else if(startProgressMail){
		var ProgressURL
		var PosL = (screen.width/2)-150
		var PosT = (screen.height/2)-110
		ProgressURL = ProgressPath + "AspNetMailFiles/FrameSetMail.aspx?ProgressBarType=" + ProgressBarType + "&UploadID=" + UploadID + "&TempPath=" + TempPath + "&ProgressMailBarType=" + ProgressMailBarType
		var v = window.open(ProgressURL,'progressBarPage','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=350,height=210,top='+PosT+',left='+PosL)
	}
	
	return true;
}

function FileObj(Path,maxW,maxH,maxSize,extension){
	imgUpload = new Image();
	imgUpload.src=Path;
	imgUpload.maxW=maxW;
	imgUpload.maxH=maxH;
	imgUpload.maxSize=maxSize;
	imgUpload.extension=extension;
}

function VerifyFile(){
	var errorMsg="";
	//Verify extension
	if(imgUpload.extension!=""){
		imgUpload.extension = imgUpload.extension.toLowerCase()
		ext = imgUpload.extension.split(",")
		var ris = false
		for(g=0;g<ext.length;g++){
			thisExt = imgUpload.src.substring(imgUpload.src.length-ext[g].length)
			if(thisExt.toLowerCase()==ext[g]){
				ris = true
				break
			}
		}
		if(ris==false){
			errorMsg+="File extension allowed for this file is: "+imgUpload.extension+" Actual extension is "+imgUpload.src.substring(imgUpload.src.lastIndexOf("."))+"\n";
		}
	}
	//Verisy Size
	thisExt = imgUpload.src.substring(imgUpload.src.lastIndexOf(".")).toLowerCase()
	if(imgUpload.maxSize!=""&&((thisExt==".gif") || (thisExt==".bmp") || ((thisExt==".jpg")) || ((thisExt==".jpeg")) || ((thisExt==".png")))&&parseInt(imgUpload.fileSize/1000)>parseInt(imgUpload.maxSize)){	
		errorMsg+="Maximum size allowed for this file is: "+imgUpload.maxSize+" Kb - Actual size is "+parseInt(imgUpload.fileSize/1000)+" Kb\n";}
	//Verify With
	if(imgUpload.maxW!=""&&((thisExt==".gif") || (thisExt==".bmp") || ((thisExt==".jpg")) || ((thisExt==".jpeg")) || ((thisExt==".png")))&&imgUpload.width>imgUpload.maxW){
		errorMsg+="Maximum width allowed for this image is: "+imgUpload.maxW+" pixels - Actual width is "+imgUpload.width+" pixels\n";
	}
	//verify height
	if(imgUpload.maxH!=""&&((thisExt==".gif") || (thisExt==".bmp") || ((thisExt==".jpg")) || ((thisExt==".jpeg")) || ((thisExt==".png")))&&imgUpload.height>imgUpload.maxH){
		errorMsg+="Maximum height allowed for this image is: "+imgUpload.maxH+" pixels - Actual height is "+imgUpload.height+" pixels\n";
	}		
	if(errorMsg!=""){alert(imgUpload.src.replace("file:///","")+"\n\n"+errorMsg);}
	if(errorMsg!=""){GoUpload=false}
}


// Example: obj = findObj("image1");
function Dwz_findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}





