// JavaScript Document
var allSubmit = 1; //default to submit form.  If something fails, it won't be submitted.
var isAddNew="";
	function MM_jumpMenu(targ,selObj,restore){ //v3.0
	  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	  if (restore) selObj.selectedIndex=0;
	}
	
	function uploadFile(isAdd, urlup){
		isAddNew=isAdd;
		if(isAdd=='false'){
			document.casestudy_upload.action="/admin_master/casestudy/upload.cfm?actionPerform=update&uploadid="+getURLVar('uploadid');
		}
		var obj = document.getElementById('messageid').style;
		if(obj.visibility = 'visible'){
			obj.visibility = 'hidden';
		}
		if(isAdd=='true' && document.casestudy_upload.uploadfile.value == ''){
			alert('Please select the file to be uploaded');
			return false;
		} else if(srt_trim(document.casestudy_upload.description.value) == ""){
			alert("Please enter a short description of the case study.");
			return false;
		}else if(document.casestudy_upload.uploadfile.value != '' && !checkFile(document.casestudy_upload.uploadfile.value)){
			return false;
		} else if(document.casestudy_upload.industrial.value=="" && document.casestudy_upload.product.value=="" && document.casestudy_upload.application.value=="") {
			alert("Please select atleast one category");
			return false;
		} else {
			document.casestudy_upload.uploadedFilename.value=document.casestudy_upload.uploadfile.value;
			document.casestudy_upload.uploadedFilefieldname.value=document.casestudy_upload.uploadfile.name;
			document.casestudy_upload.submit();
		}
	}
	
	function checkFile(item){
		//showme checks for spaces in the file name and file extensions (optional).  
		//used with goForm() to submit when all well
		//can be used for multiple fies
			
		var submitForm = 1; //default to submit form.  If something fails, it won't be submitted.
		var checkExtension = 1; //if the extensions should be checked along with spaces. 1=yes 0=no		
		var okExtensions = new Array("pdf", "PDF");
		allSubmit = 1;
		if (item != '' && allSubmit) {
			//don't want to run this if the file is blank or if another file has already triggered allSubmit = 0
			var fileNameArray = item.split("\\");
			var fileName = fileNameArray[fileNameArray.length-1];
			var fileExtensionArray = fileName.split(".");
			var extension = fileExtensionArray[fileExtensionArray.length - 1];
			var extensionOK = 0;
			
			
			if (checkExtension) {
				//find if the extension of the file is in the list of ok Extensions.  run through the list of 
				//acceptable extensions
				for (var i = 0; i < okExtensions.length; i++){
					if (extension == okExtensions[i]){
						extensionOK = 1;
					}
				} 
			} else {
				//if we aren't checking, extension is automatically ok
				extensionOK = 1;
			}
			
			// if the file name has no spaces in it, the fileNameSpaces.length will = 1
			if (fileName.split(' ').length != 1) {
				alert('You cannot upload "' + fileName + '" because the name contains a space(s).  Please rename the file and try again.'); //It has spaces:' + fileName.split(' ').length 
				submitForm = 0
			} else if (extensionOK == 0) {
				alert('You cannot upload "' + fileName + '".  You must enter a file of type .pdf');
				submitForm = 0
			}
		}
		
		if (submitForm && allSubmit) {
			allSubmit = 1;
			return true;
		} else {
			//if at any step submitForm or allSubmit are 0, then allSubmit must be 0
			allSubmit = 0;
			return false;
			//alert('this form will not be submitted');
		}
	}
	function goForm() {
		if (allSubmit) {
			<!---return myEditor1copyValue();--->
			return true;
		} else {
			return false;
		}
	}
	
	function getURLVar(urlVarName) {
		//divide the URL in half at the '?' 
		var urlHalves = String(document.location).split('?');
		var urlVarValue = '';
		if(urlHalves[1]){
		//load all the name/value pairs into an array 
			var urlVars = urlHalves[1].split('&');
			//loop over the list, and find the specified url variable 
			for(i=0; i<=(urlVars.length); i++){
				if(urlVars[i]){
				//load the name/value pair into an array 
					var urlVarPair = urlVars[i].split('=');
					if (urlVarPair[0] && urlVarPair[0] == urlVarName) {
						//I found a variable that matches, load it's value into the return variable 
						urlVarValue = urlVarPair[1];
					}
				}
			}
		}
		return urlVarValue;   
	}
	
	function refreshTable(){
		document.casestudy_search.searchBox.value="";
		document.casestudy_search.submit();
	}
	
	function veritySearch(){
		//document.casestudy_search.action="/casestudy/veritysearch_casestudy.cfm";
		var trimmed = srt_trim(document.casestudy_search.searchBox.value);
		if(!((trimmed == null) || (trimmed.length == 0))){
			document.casestudy_search.submit();				
		}
	}
	
	function pagination(pageName,loc_id,page){
		alert(pageName+'    '+loc_id+'    '+page);
		document.casestudy_search.action = "/ptcasestudies/"+pageName+"?location_id="+loc_id+"&page="+page;
		document.casestudy_search.submit();
	}
	function srt_trim(str){
		if((str != "") && (str.indexOf(" ",0)!=-1)){
			var iMax = str.length;
			var end = str.length;
			var c;
			for(i=0;1<iMax;i++){
				c = str.substring(0,1);
				if (c == " "){
					str=str.substring(1,end);
					end = str.length;
				} else 
					break;
			}
			iMax = str.length;
			end = str.length;
			for(i=iMax;i>0;i--){
				c = str.substring(end-1,end)
				if (c == " "){                                                              
					str=str.substring(0,end-1);
					end = str.length;
				}else 
					break;
			}
		}
		return str;
	}





