// ================================================================================================================================== 
/* 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
 *******************************************************************************/
// ================================================================================================================================== 

// IF Called from Object ...............
function chek_alert()
{
	alert('sdfsdf');
}

	
// call method of this function (IF from onchange)--- 
//	file_filter('jpg','pdf',.....,'cdr',this);
// ---------
// call method of this function (IF from string_Url_chek)--- 
//	if (document.form1.photo_url.value!='')
//  errors+=file_filter('jpg','pdf','cdr',document.form1.photo_url.value);
 
 

 
 
function file_filter()
{
var i=0,j=0;
var t='';
var errors='';
var arg=file_filter.arguments;

// ............... IF Called from Object ...............
var str1=arg[arg.length-1].value;
// ............... IF Called from String Url ...............
var str2=arg[arg.length-1];

if (str1) str=str1; else str=str2; 

if(!str) return errors='File dosen\'t have right format';

var ext=str.substring(str.lastIndexOf(".")+1,str.length);


	for (j=0;j<=arg.length-2;j++)
	{	
		t=t+'.'+arg[j]+'  ';
	}
	//alert(t);
	for (i=0;i<=arg.length-2;i++)
	{	//alert('chek for '+arg[i]);
		//alert(ext+'   '+arg[i]);
		if (arg[i].toUpperCase()!=ext.toUpperCase()) 
		errors='file dosen\'t have right format. file should be only'+t;
		else 
		{ 	
			if (str1) errors='Yes it is OK';
			else
			errors='';
			break;
		}
	}

	if (!errors)
	{
		filename=str.substring(str.lastIndexOf("\\")+1,str.length);
		errors=isIncorrectFileName(filename,'File name');
		//alert(errors);
	}
	//alert('This File dosen\'t have right format \n File should be only '+arg);
	

	return errors;
}


function isIncorrectFileName(v1, t1) 
{	var FileName = ''; 
	var iChars = v1; 
	var data = "`!@#$%^&*()+= []\\\';,/{}|\":<>?~"; 
	for (var i = 0; i < data.length; i++) 
	{	
		if (iChars.indexOf(data.charAt(i)) != -1) 
		{
		  FileName='Has Special Character';
		}
	}
	if (FileName) return "- "+t1+" has special characters or spaces. These are not allowed.";
	else return ''; 
}



function fileValues(fieldName,fileName) { (document.form1)[(fieldName)].value=fileName;	} function removeValues(fieldName) { (document.form1)[(fieldName)].value=''; }