function len(field,ll,nm){
	if(field.value.length>ll){
		alert(nm)
		field.focus()
		return false
	}
	return true
 }


function required(field,nm)
{

if(field.value == ""){
		alert(nm)
		field.focus()
		return false
	}
	return true

}


function blank(field,nm)
{
if(field.value!=""){

	var crlf="\r\n"
	text=false
	
	var arr=new Array()
	arr=field.value.split(crlf)
	for(j=0;j<arr.length&&!text;j++){
		a=arr[j]
		if ((a!=crlf)){
			for(i=0;i<a.length&&!text;i++){
				str=a.substring(i,i+1)
				if((str!=" ")&&(str!=""))
					text=true
			}
		}
	}

	if (!text){
		alert(nm)
		field.focus()
		return false;
	}
	return true
}
return true
}

function lenword(field,nm){
	if (field.value!=""){
		var arr=new Array()
		arr=field.value.split(" ")
		for(i=0;i<arr.length;i++){
			if(arr[i].length>70){
				//alert("Sorry, the word '"+arr[i]+"' is too long.  Please enter another word. [max 70 char]")
				alert("Sorry, the word is too long.  Please enter another word. [one word max 70 char]")
				field.focus()
				return false;
			}
		}
	}

	return true
 }
 
 
function dateval(sdate){

var val=sdate.value;
if(val != "")
{

if((val.length>10) ||(val.length<8))
{
	alert(" Please enter the date in (mm/dd/yyyy) format. ")
	sdate.focus();
	return false;
}
else {
	slash1=val.indexOf("/")
	if(slash1==-1)
	{
		alert(" Please enter the date in (mm/dd/yyyy) format.")
		sdate.focus();
		return false;
	}	
	slash2=val.lastIndexOf("/")
	if((slash2==-1)||(slash2==slash1))
	{
		alert(" Please enter the date in (mm/dd/yyyy) format.")
		sdate.focus();
		return false;
	}	
	
	var two=(val.substring(0,slash1));
	if ((two>=0)&&(two<=12))
	{

		mm=two;
	}
	else
	{	
		alert(" Please enter the date in (mm/dd/yyyy) format.")
		
		sdate.focus();
		return false;
	}
	two=(val.substring(slash1+1,slash2));

	if ((two>=0)&&(two<=31))
	{
		dd=two;
	}
	else
	{	
		alert(" Please enter the date in (mm/dd/yyyy) format.")
		
		sdate.focus();
		return false;
	}
	two=(val.substring(slash2+1,slash2+5));
	if ((two>=1900)&&(two<=2075))
	{
		yy=two;
	}
	else
	{	
		alert(" Please enter the date in (mm/dd/yyyy) format.")

		sdate.focus();
		return false;
	}

	if(((dd==29)&&(mm==02))||((dd==29)&&(mm==2)))
	{
	
		if(((yy%4)==0)||((yy%400)==0))
		{
		//valid
		}
		else
		{
		alert(" Please enter the date in (mm/dd/yyyy) format.")
		sdate.focus();
		return false;
		}
	}
	if (((dd>29)&&(mm==2))||((dd==31)&&((mm==2)||(mm==4)||(mm==6)||(mm==9)||(mm==11))))
	{	
		alert(" Please enter the date in (mm/dd/yyyy) format.")
		sdate.focus();
		return false;
	}
}	
return true;
}	
return true;
}


function ValidateEMail(objName)
{
	var sobjValue;
	var iobjLength;
	
	sobjValue=objName.value;
	
	iobjLength=sobjValue.length;
	
	iFposition=sobjValue.indexOf("@");
	iSposition=sobjValue.indexOf(".");
	iTmp=sobjValue.lastIndexOf(".");	
	
	if (iobjLength!=0)
	{
		if ((iFposition == -1)||(iSposition == -1))
		{
			alert("Please enter the E-Mail address in the proper format")
			objName.focus();
			return false;
		}
		else if(sobjValue.charAt(0) == "@" || sobjValue.charAt(0)==".")
		{
			alert("Please enter the E-Mail address in the proper format")
			objName.focus();
			return false;				
		}
		else if(sobjValue.charAt(iobjLength) == "@" || sobjValue.charAt(iobjLength)==".")
		{
			alert("Please enter the E-Mail address in the proper format");
			objName.focus();
			return false;				
		}	
		else if((sobjValue.indexOf("@",(iFposition+1)))!=-1)
		{	
			alert("Please enter the E-Mail address in the proper format")
			objName.focus();
			return false;
		}
		else if ((iobjLength-(iTmp+1)<2)||(iobjLength-(iTmp+1)>3))
		{
			alert("Please enter the E-Mail address in the proper format")
			objName.focus();
			return false;
		}
		else if(sobjValue.indexOf(" ") != -1)
		{	
			alert("Please remove the space between the words")
			objName.focus();
			return false;
		}
		
		else
		{
			return true;
		}		
	}		
}    


function year_validation(field)
{
var valid = "1234567890."
if(field.value!="")
{
		var len=field.value.length;
		var chk=field.value;
		for(i=0;i<len;i++)
		{
			x = chk.charAt(i)
			if(valid.indexOf(x) == -1)
			{
				field.focus()
				field.select()
				alert("Please enter only numeric values in year field.")
				return false;
			}
		}
		if((chk<1900)||(chk>2075)){
			field.focus()
			field.select()
			alert("Please enter the Year between 1900 to 2075.")
			return false;
		}
		
}
return true;
}

function numeric(field)
{
var valid = "1234567890-,."
if(field.value!="")
{
		var len=field.value.length;
		var chk=field.value;
		for(i=0;i<len;i++)
		{
			x = chk.charAt(i)
			if(valid.indexOf(x) == -1)
			{
				field.focus()
				field.select()
				alert("Please enter only numeric values")
				return false;
			}
		}
}
return true;
}  

function isapostrophe(field) {
var str
str = field.value 
var len =str.length
//alert(str+len)
	var i
	for(i=0; i<len;++i){
		if(str.charAt(i)=="'"){
		field.focus()
		field.select()
		alert("cannot insert  APOSTROPHE ( ' ) into any field.")
		return true
		}
	}
	return false
}


function specialcheck(field,nm)
{    
	alert("hi");							
	var mikExp = /[$?\\@\\\#%\^\&\*\(\)\[\]\+\_\!\{\}\`\~\=\|]/;
	var strPass = field.value;
	var sFldval = field.value;
	var strLength = strPass.len;
				
	var lchar = strPass.charAt((strLength) - 1);
					
	var lchar1 = strPass.charAt(0)
					
	if((lchar.search(mikExp) != -1)|| (lchar1.search(mikExp) != -1))
	{
	alert("Please enter the valid characters only!");
	field.focus()
	return false;
	}
	alert("i reached here")				
	if(sFldval.indexOf('"') != -1) 
	{
		alert("Please remove the double Quotes");
		field.focus()
		return false;
	}
	if(sFldval.indexOf("'") != -1) 
	{
		alert("please remove the single Quote");
		field.focus()
		return false;
	}
					
	if(sFldval.indexOf(" ") != -1) 
	{
		alert("Please remove the space between the words");
		field.focus()
		return false;
	}
	alert("hi manas");	
	//else 	
	return true;
	alert("hi manas i reached final stage");		
} 	

//function to check the file extension of uploading file
function check(field)

{

//Checks wheather any file is present for uploading

if(field.value=="")

{
alert("Please select the image")
return false
}

var t=field.value
var f=t.split('.')
if (f.length>2)

{
alert("The file type is not Correct or please check the file type...")
return false
}
else
{

// You can modify the file extentions to which ever file extensions you want to unblock
// Example you can modify ".jpg" extension to ".bmp" extension if you want to allow ".bmp" //file to upload.

if((field.value.lastIndexOf(".jpg")==-1) && (field.value.lastIndexOf(".gif")==-1))
{
alert("You can upload only GIF and JPG extention files")
return false
}
}
return true
}




//Open window with progress bar.
//pair upload window and progress window (using UploadID).
function ProgressBar(form){
 //check file sizes.
 
 if (checkFileSize()) {
   alert('Upload size is over limit. Please check selected files.')
   return false;
 };

  
 //ASP script handling progress window
 var ProgressScript
 ProgressScript = 'progress.dat'
 

 //Progress window parameters
 var pp = 'toolbar=no,location=no,directories=no,status=no,menubar=no'
 pp+=',scrollbars=no,resizable=yes,width=350,height=200';
  
 //1. Get unique UploadID
 var UploadID
 UploadID = Math.round(Math.random() * 0x7FFFFFF0)
  
 //2. Add upload ID to form action URL
 var action = form.action;
 if ('' == action) action = ''+document.location;
 action = AddToQuery(action, 'UploadID', UploadID);
 form.action = action

 //3. Open progress window with the same UploadID
 var ProgressURL
 ProgressURL = ProgressScript + '?UploadID=' + UploadID 

 var v = window.open(ProgressURL,'_blank',pp)
 
 return true;
};

//Adds value and its name to querystring
function AddToQuery(q, valname, val){
 if (q.indexOf('?')<0) {
   q += '?'
 } else {
 var pv = q.indexOf(valname+'=');
 if (pv >= 0){
  var amp = q.indexOf('&', pv);
  if (amp<0) {
   q = q.substr(0, pv) 
  } else {
   q = q.substr(0, pv) + q.substr(amp+1) + '&'
  }
 } else {
  if (q.substr(q.length-1)!='?') q += '&'
 };
 };
 q += valname + '=' + val
 return q
};
 



//Additional function - dynamic form to add new files at a client side.

var nfiles = 2;
//Add two files for upload
//Expand();
function Expand(){
  
  //get an HTML code of a first upload element
  var adh = dfile1.outerHTML;

  //replace '1' to nfiles (2, 3, ...)
  adh = adh.replace(/1/g,++nfiles)
  
  //insert the code of a new element before end of div files
  files.insertAdjacentHTML('BeforeEnd',adh);

  //clear mask and real value of the element nfiles
  //document.getElementById('maskfile'+nfiles).value=''
  return false;
};




//Huge-asp upload preview sample
//http://www.pstruh.cz

function isImage(file){
  //Get a file extension
  var ext = file.substr(file.lastIndexOf('.')).toLowerCase()

  //Check extension to image types.
  
  return '.gif,.jpg,.png,.jpeg,.bmp,'.indexOf(ext+',') >= 0
};

var lastfieldname = ''
var filenamechecked = ''
function preview(n) {
  //get current input preview
  var htmlfile = document.getElementById('img'+n);
  var file = htmlfile.value;
  //set the size field.
  var himg = document.getElementById('himg'+n);
  if (file.length>0) himg.src = 'file://' + file;
  else { 
    himg.src = ''; 
    document.getElementById('size'+n).innerHTML='-'
  };
  
  if (file.length<=0) return;

  //or get get preview for one of form field
  //var file = file_upload.SourceFile1.value
  var ipreview = document.getElementById('ipreview');
  
  //do not check the file more than one.
  if (filenamechecked != htmlfile.value) {
    filenamechecked = htmlfile.value
  } else {
    return true;
  };

  if (isImage(file)) {

    //Show preview for the image.
    ipreview.src = 'file://' + file
    //alert(file);
    //alert(ipreview.src);
    ipreview.title = 'Image ' + file 
    if (ipreview.width != 300) ipreview.width = 300;

    ImageName.innerHTML = 'Image preview<br>(' + htmlfile.name + ')'
  } else {
    //some default image for preview
    ipreview.src = 'res://shdoclc.dll/warning.gif'

    alert('Please choose some image file (.gif,.jpg,.png,.jpeg,.bmp)');
    
  };
  
  lastfieldname = htmlfile.name
}

function himgLoaded(n){
  checkFileSize();
};


//this function gets a sizes of images,
//write the sizes to HTML form
//counts total size and checks file sizes against a limit
var maxFileSize = 200000
var FormSizeLimit = 4000000
function checkFileSize() {
  var totalSize = 0;
  var htmlSize;
  var overLimit = false;
  for (j = 1; j <= nfiles; j++) {
    var himg = document.getElementById('himg'+j);
    var size = document.getElementById('size'+j);
    var fileSize = himg.fileSize ;
    fileSize = parseInt(fileSize);
    
    if (fileSize < 0) {
      size.innerHTML = '-';
    } else {
      htmlSize = formatSize(fileSize);
      if ( fileSize>maxFileSize ) {
        htmlSize += ' (over limit, ' + formatSize(maxFileSize) + ' max)'
        size.style.color = 'red';
        overLimit = true;
      } else {
        size.style.color = '';
      };
      size.innerHTML = htmlSize;
      totalSize += fileSize;
    };//if (fileSize < 0) {
  };//for (j = 1; j <= nfiles; j++)


  var htotalSize = document.getElementById('totalSize');
  
  if (totalSize > 0){
    htmlSize = formatSize(totalSize);
  } else {
    htmlSize = '-';
  };
  if (totalSize > FormSizeLimit) {
    htotalSize.style.color = 'red';
    htmlSize += ' (over limit, ' + formatSize(FormSizeLimit) + ' max)'
    overLimit = true;
  } else {
    htmlSize += ' (of ' + formatSize(FormSizeLimit) + ' max)'
  };
  htotalSize.innerHTML = htmlSize
  return overLimit;
};

function formatSize(size) {
  if (size < 0x100000) {// < 1 MB
    return Math.round(size / 0x400)+"&nbsp;kB"; 
  } else { // > 1 MB
    return (Math.round((size / 0x100000)*10)/10)+"&nbsp;MB";
  }
}


//window.onerror = donotmsgboxes;
function donotmsgboxes(msg,url,line)
{  // we do not need error messages
  return true
}

function chk_domain(strDomain)
{ 
	//alert("hi");
	domain_val=window.document.add.username.value;
	domain_val=strDomain;
	flag = false
		len=(domain_val).length;
		if (len<=3)
			{
				flag = true;
			}
		else
		{			
			domain_val=domain_val.toLowerCase();
			theChar="";
			for(i=0;i<len;i++)
			{
				theChar=domain_val.substring(i,i+1)
				if ((theChar<"0" || theChar>"9") && (theChar<"a" || theChar>"z") && (theChar!="_"))
				{
					flag=true;
					break;
				}
			}
			
		}	
		return flag	
}

