// - - - - - - - - - - - - - - - - - - - - -
//
// Title : Flash Highlight JS
// Author : Kevin Hale
// URL : http://particletree.com
//
// Description : This demo is part of an introduction 
// to the Flash / JavaScript Integration Kit by Particletree. 
// In this demo we are using Flash as an animation underlayer 
// to enhance an html form. Click on the text fields to see 
// the the flash movie clip resize move to the appropriate div.
//
// Created : December 15, 2005
// Modified : January 9, 2006
//
// - - - - - - - - - - - - - - - - - - - - -

addEvent(window, 'load', resizeFlash);

//resizeFlash() by Kevin Hale
function resizeFlash(){
	var oContainer = document.getElementById('container');
	var oFlash = document.getElementById('flash');

}

//flashHighlight() by Kevin Hale
function flashHighlight(ID){
var obj = document.getElementById(ID);
flashProxy.call('moveBeacon', findPosX(obj), findPosY(obj), obj.offsetWidth, obj.offsetHeight);
}

//addEvent() by John Resig
function addEvent( obj, type, fn ){ 
   if (obj.addEventListener){ 
      obj.addEventListener( type, fn, false );
   }
   else if (obj.attachEvent){ 
      obj["e"+type+fn] = fn; 
      obj[type+fn] = function(){ obj["e"+type+fn]( window.event ); } 
      obj.attachEvent( "on"+type, obj[type+fn] ); 
   } 
} 

//findPosX() and findPosY() by Peter-Paul Koch
function findPosX(obj) {
   var curleft = 0;
   if (obj.offsetParent) {
       while (obj.offsetParent) {
           curleft += obj.offsetLeft;
           obj = obj.offsetParent;
       }
   }
   else if (obj.x) {
       curleft += obj.x;
   }
   return curleft;
}

function findPosY(obj) {
   var curleft = 0;
   if (obj.offsetParent) {
       while (obj.offsetParent) {
           curleft += obj.offsetTop;
           obj = obj.offsetParent;
       }
   }
   else if (obj.y) {
       curleft += obj.y;
   }
   return curleft;
}

function del()
{
	var aa;
	aa = confirm("Are you sure you want to delete this record");
	if(aa)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function checkemail(textfldobj)
{
  if (textfldobj.value.indexOf('@') == -1 || textfldobj.value.indexOf('.')== -1)
  {
  //alert("Please enter a Valid Email Id.");
  textfldobj.focus();
  return false;
  }
  return true
}

function emptyField(textobj)
{
	if(textobj.value.length==0)
	{
		 textobj.focus();
		 return true;
	}
	for(var i=0;i < textobj.value.length;++i)
	{
		var ch =textobj.value.charAt(i);
	if(ch!=' '&&ch!= '\t') 
		return false;
	}
	textobj.focus();
	return true;
}


function isblank(blafield)
{
if(blafield.indexOf(' ') ==1)
{
return false;

}
else
{
return true;
}
}




function isNum(argvalue) 
{
argvalue = argvalue.toString();

if (argvalue.length == 0)
{
return true;
}

for (var n = 0; n < argvalue.length; n++)
{
if(argvalue.substring(n, n+1) == "0")
continue;
else if(argvalue.substring(n, n+1) == "1")
continue;
else if(argvalue.substring(n, n+1) == "2")
continue;
else if(argvalue.substring(n, n+1) == "3")
continue;
else if(argvalue.substring(n, n+1) == "4")
continue;
else if(argvalue.substring(n, n+1) == "5")
continue;
else if(argvalue.substring(n, n+1) == "6")
continue;
else if(argvalue.substring(n, n+1) == "7")
continue;
else if(argvalue.substring(n, n+1) == "8")
continue;
else if(argvalue.substring(n, n+1) == "9")
continue;
else if(argvalue.substring(n, n+1) == ".")
continue;

else if(argvalue.substring(n, n+1) == " ")
continue;

else

return false;
}
return true;
}


function isdate(sdate)
{


var s,ss,leapyear;
s = sdate.value;
if (s=="")
{
return false;
}
ss = s.split("/");
var today = new Date();
today = today.getYear();
today = '20'+today;

if ((s.substr(1,1) != "/" && s.substr(2,1) != "/") || (s.substr(3,1) != "/" && s.substr(4,1) != "/" && s.substr(5,1) != "/"))
	{
	
		alert("Enter date in correct form (mm/dd/yyyy)");
		return val_focus(sdate);
		
	}
  
	else if ((ss[0].length > 2) || (ss[0].length < 1) || (ss[1].length > 2) || ss[1].length < 1 || (ss[2].length != 4) || (!isNum(ss[0])) || (!isNum(ss[1])) || (!isNum(ss[2])))
	 {
		alert("Enter date in Correct format (mm/dd/yyyy)");
		return val_focus(sdate);
	 }
	else if (ss[2] < 1900 || ss[2] > today)
	 {
		alert("Enter Valid Year [Between 1900-To current Year]");
		return val_focus(sdate);
	 }
	
	else if(ss[0] < 1 || ss[0] > 12)
	{
		alert("Enter Valid Month [Between 1-12]");
		return val_focus(sdate);
	}
	
	else if(ss[1] < 1 || ss[1] > 31)
	{
		alert("Enter Valid day [Between 1-31]");
		return val_focus(sdate);
	}
	
	else if(ss[0]==4 || ss[0] == 6 || ss[0] == 9 || ss[0] == 11)
	{
		if(ss[1] > 30)
		{
			alert("For this month day should be less than 30");
			return val_focus(sdate);
		 }
	}
	
	else if(ss[0] == 2)
	{
		if((ss[2]%4)==0) 
		{	
			if((ss[2]%100)==0)
			{	
				if((ss[2]%400) ==0)
				leapyear = true;
				else
				leapyear = false;
			}
			else
			leapyear = true;	
		}		
	    else 
		    leapyear = false;
		 
		if((leapyear) && (ss[1] > 29))
		 {
			alert("This is leap year so date can't greater than 29");
			return val_focus(sdate);
		 }
		 else if(!(leapyear) && ss[1] > 28)
		 {
			alert("This is not leap year so date can't greater than 28");
			return val_focus(sdate);
		 }
		 
	}
	else 
	return false;
 }


 function val_focus(formobj)
{
 formobj.select();
 formobj.focus();
 return true;

}
function chkExtension(txtfield)
{


	var filename,filenamelen
	var fileext,fileextlen
	var allowedtypes = [".jpg",".JPG",".jpeg",".JPEG",".gif",".GIF"]
	var dotpos
	filename = txtfield.value
	filenamelen = filename.length
	dotpos = filename.lastIndexOf(".")
	fileextlen = (filenamelen - dotpos - 1)
	
	if (fileextlen >= 3 && fileextlen <= 4) //this allows files with a min of 3 and max of 4 chars in their extension
	{
	fileext = filename.substring(dotpos,filenamelen)
	//alert (fileext)
		for(var ctr=0;ctr<allowedtypes.length;ctr++)
		{
			
			if(allowedtypes[ctr] == fileext)
			{
				return true
			}		
		}
		alert("Only JPG/JPEG/GIF type picture files are allowed.\n Please select a valid file type.")	

	}
	else
	alert("The file you have selected is not a valid picture file.\nPlease select a different file.")
	
	return false


}

function checkBal (txtTargObj,txtDispObj,maxLength)
{


	var currLen = txtTargObj.value.length	
	
	if (currLen > maxLength) 
	{
		txtTargObj.value = txtTargObj.value.substring(0,maxLength)
		currLen = txtTargObj.value.length	
		txtDispObj.value = maxLength - currLen
	}
	else
	txtDispObj.value = maxLength - currLen
		
	
}

