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 isNum(argvalue) 
{	
	var count = 0
	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) == ".")
		{
			count += 1 ;
			if (count<=1)
			{
				continue;
			}
			else
			{
				return  false ;
			}
			continue;
		}
		else
			return false;

	}
return true;
}


//*******************************************************

function isInt(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
			return false;

	}
return true;
}


function isDate(sdate, format) {
     var s, ss, leapyear;
     s = sdate.value;
     ss = s.split("/");
     var today = new Date();
     today = today.getYear();
     today = '20' + today;

     if (format == null || format == "" || format == "mm/dd/yyyy") {
         mon = 0;
         day = 1;
     }
     else if (format == "dd/mm/yyyy") {
         mon = 1;
         day = 0;
     }
     else {
         mon = 0;
         day = 1;
     }

     if ((s.substr(1, 1) != "/" && s.substr(2, 1) != "/") || (s.substr(3, 1) != "/" && s.substr(4, 1) != "/" && s.substr(5, 1) != "/")) {
         if (format != null || format != "") {
             alert('Enter Date In Correct Format');
         }
         else {
             alert("Enter Date In Correct Form (mm/dd/yyyy)");
         }
         return val_focus(sdate);
     }

     else if ((ss[mon].length > 2) || (ss[mon].length < 1) || (ss[day].length > 2) || ss[day].length < 1 || (ss[2].length != 4) || (!isNum(ss[mon])) || (!isNum(ss[day])) || (!isNum(ss[2]))) {
         if (format != null || format != "") {
             alert("Enter Date In Correct Form ");
         }
         else {
             alert("Enter Date In Correct Form (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[day] < 1 || ss[day] > 31) {
         alert("Enter Valid Day [Between 1-31]");
         return val_focus(sdate);
     }
     else if (ss[mon] < 1 || ss[mon] > 12) {
         alert("Enter Valid Month [Between 1-12]");
         return val_focus(sdate);
     }
     else if (ss[mon] == 4 || ss[mon] == 6 || ss[mon] == 9 || ss[mon] == 11) {
         if (ss[day] > 30) {
             alert("For This Month Day Should Be Less Than 30");
             return val_focus(sdate);
         }
     }

     else if (ss[mon] == 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[day] > 29)) {
             alert("This Is Leap Year So Date Can't Greater Than 29");
             return val_focus(sdate);
         }

         else if (!(leapyear) && ss[day] > 28) {
             alert("This Is Not Leap Year So Date Can't Greater Than 28");
             return val_focus(sdate);
         }

     }

 }



//*******************************************************
//author@GBS
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 validEmailId(CheckEmptyEmail)
{
		var inem1,inem2,lenem1,l,l1,lenem2,lensp,lechar;
		inem1 = CheckEmptyEmail.length;
		l = CheckEmptyEmail;
		l1 = l.lastIndexOf('.');
		lenem1 = l.lastIndexOf('@');
		lenem2 = l.indexOf('@');
		lensp = l.indexOf(' ');
		lechar = l.charAt(lenem1 + 1);
	
		if(lechar == '.')
		{
			return false;
		}
		
		if((lenem1 + 1) == l1 || (l1 + 1) == inem1 || lenem1 > l1 || lenem2 != lenem1 || lensp != -1 || lenem1 == 0)
		{
			return false;
		}
	
		if(CheckEmptyEmail.indexOf('@') == -1 || CheckEmptyEmail.indexOf('.')== -1)
		{
			return false;
		}
		
		if (l.indexOf(',') != -1 || l.indexOf('/') != -1 || l.indexOf('(') != -1 || l.indexOf(')') != -1 || l.indexOf('*') != -1 || l.indexOf('&') != -1 || l.indexOf('^') != -1 || l.indexOf('%') != -1 || l.indexOf('$') != -1 || l.indexOf('&') != -1 || l.indexOf('#') != -1 || l.indexOf('!') != -1 )
		{
			return false;
		}
		
		return true;
}





function val_focus(formobj) {
    formobj.select();
    formobj.focus();
    return true;

}


function view_image(flag,id) {
    if (flag == 1) {
        var win = window.open("viewimage.aspx?lid=" + id, null, "location=0,scrolling=0,resize=0,directories=0,status=0,menubar=0,toolbar=0,width=800,height=650", true);
        win.focus();
        return false;
    }
    else {
        var win = window.open("viewimage.aspx?cid=" + id, null, "location=0,scrolling=0,resize=0,directories=0,status=0,menubar=0,toolbar=0,width=800,height=650", true);
        win.focus();
        return false;
    }
}

function resizeMe() {
    self.resizeTo(document.getElementById("Table12").clientWidth + 45, document.getElementById("Table12").clientHeight + 120);
}
