whitespace = "\t \n\r";
function isEmptyString(s)
{
    var i;
	if((s == null) || (s.length == 0)) return true;
	for(i=0;i < s.length;i++)
	{
		var currchar = s.charAt(i);
		if(whitespace.indexOf(currchar) == -1) return false;
	}
	return true;
}
All_numbers = "1234567890";
function isAnyNumber_Check(s)
{
    var i;
	for(i=0;i < s.length;i++)
	{
		var currchar = s.charAt(i);
		if(All_numbers.indexOf(currchar) != -1) return true;
	}
	return false;
}
function isNotNumeric(s)
{
	if(isNaN(s))
	{
		return(true);
	}
	return(false);
}
function isEmail(n)
{
		if ((n==null) || (n.length==0))
		{
			return true;
		}
		if (isEmptyString(n)) return false;
		var i=1;
		var nLength=n.length;
		while((parseInt(i) < parseInt(nLength)) && (n.charAt(parseInt(i)) != '@'))
		{
			i++;
		}
		if ((parseInt(i) >= parseInt(nLength)) || (n.charAt(i)!="@"))
		{
			return false;	
		}	
		else i+=2;
		while((i<nLength) && (n.charAt(i)!="."))
		{
			i++;
		}
		if ((i>=nLength-1) || (n.charAt(i)!="."))
		{
			return false;	
		}	
		else return true;		
}

function rollon(imgName)
{
    document.images[imgName.name].src = eval(imgName.name + "_on.src");
}
function rolloff(imgName)
{
	document.images[imgName.name].src = eval(imgName.name + "_off.src");
}


function DonloadWindow(my_url)
{ 
	var My_Download_Open = window.open(my_url,"My_Download","toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resize=no,copyhistory=0,width=627,height=375")
	My_Download_Open.focus();
	My_Download_Open.moveTo(85,50);
}
function openWindow(URL, h, w) 
{
  	var gg = typeof (popupWin);
  	if (gg =='object')
	{ 
	  	if (popupWin.closed ) {}
		else { popupWin.close();  }
	};
  	popupWin = window.open(URL, 'popup', 'dependent=0,height='+h+',width='+w+',screenX=20,left=60,screenY=190,top=130,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=1,toolbar=0', 'launcher');
	if (window.focus)
	{
   		popupWin.focus();
   	}
}
function confdel()
{
	var fl = 0;
	for(i = 0; i < (document.frm_1.elements.length); i++)
	{
		if((document.frm_1.elements[i].type=="checkbox") && (document.frm_1.elements[i].checked==true))
		{
			fl = 1;
			break;
		}
	}
	if(fl == 1)
	{
		if(confirm("Records related will also get Deleted, Are you sure you want to Delete?"))
		{
			fl = 1;
		}
		else
		{
			fl = 0;
		}
	}
	else
	{
		alert("Nothing to Delete.");
		fl = 0;
	}
	if(fl == 1)
	{
		return true;
	}
	else
	{
		return false;
	}
}
function confdel_schedule()
{
	var fl = 0;
	for(i = 0; i < (document.frm_1.elements.length); i++)
	{
		if((document.frm_1.elements[i].type=="checkbox") && (document.frm_1.elements[i].checked==true))
		{
			fl = 1;
			break;
		}
	}
	if(fl == 1)
	{
		if(confirm("Are you sure you want to delete unit from contest ?"))
		{
			fl = 1;
		}
		else
		{
			fl = 0;
		}
	}
	else
	{
		alert("Nothing to Delete.");
		fl = 0;
	}
	if(fl == 1)
	{
		return true;
	}
	else
	{
		return false;
	}
}
function confdel2()
{
	var fl = 0;
	for(i = 0; i < (document.frm_2.elements.length); i++)
	{
		if((document.frm_2.elements[i].type=="checkbox") && (document.frm_2.elements[i].checked==true))
		{
			fl = 1;
			break;
		}
	}
	if(fl == 1)
	{
		if(confirm("Records related will also get Deleted, Are you sure you want to Delete?"))
		{
			fl = 1;
		}
		else
		{
			fl = 0;
		}
	}
	else
	{
		alert("Nothing to Delete.");
		fl = 0;
	}
	if(fl == 1)
	{
		return true;
	}
	else
	{
		return false;
	}
}
function confsubmit()
{
	var fl = 0;
	for(i = 0; i < (document.frm_1.elements.length); i++)
	{
		if((document.frm_1.elements[i].type=="checkbox") && (document.frm_1.elements[i].checked==true))
		{
			fl = 1;
			break;
		}
	}
	if(fl == 1)
	{
		if(true)
		{
			fl = 1;
		}
		else
		{
			fl = 0;
		}
	}
	else
	{
		alert("Nothing to Send.");
		fl = 0;
	}
	if(fl == 1)
	{
		return true;
	}
	else
	{
		return false;
	}
}
function Select_Delect_All(total_records_viewed)
{
	for(i=0;i<total_records_viewed;i=i+1)
	{
		if(document.frm_1.chk_SD.checked==true)
		{
			document.frm_1.elements["chk_1["+i+"]"].checked=true;
		}
		else
		{
			document.frm_1.elements["chk_1["+i+"]"].checked=false;
		}
	}
}
function Select_Delect_All2(total_records_viewed)
{
	for(i=0;i<total_records_viewed;i=i+1)
	{
		if(document.frm_2.chk_SD.checked==true)
		{
			document.frm_2.elements["chk_1["+i+"]"].checked=true;
		}
		else
		{
			document.frm_2.elements["chk_1["+i+"]"].checked=false;
		}
	}
}
function single_textbox_date_validation_MMDDYYYY(textbox)
{
	if(!isNaN(textbox.value))
	{
		alert("Invalid Date format");
		return false;
	}
	//Checking leap year validation
	var mystring = new String(textbox.value)
	var myRegExp_Slash=new RegExp("/","gi");
	mystring=mystring.replace(myRegExp_Slash,"-");
	textbox.value=mystring;
	
 	m=mystring.indexOf("-",0)
	mm=mystring.slice(0,m)

	d=mystring.indexOf("-",m+1)
	dd=mystring.slice(m+1,d)

	yyyy=mystring.slice(d+1,mystring.length)	

	if ((isNaN(mm))||(mm.length>2)||parseInt(mm)>12||mm<1)
  	{
	  	alert("Invalid Date Format, Please Enter in MM-DD-YYYY");
		textbox.focus();
  		return false;
  	}
	if ((isNaN(dd))||(dd.length>2)||parseInt(dd)>31||dd<1)
  	{
  		alert("Invalid day");
		textbox.focus();
  		return false;
  	}
	if ((isNaN(yyyy))||(yyyy.length>4)||(yyyy.length==3)||(yyyy.length==0))
  	{
  		alert("Invalid year");
		textbox.focus();
  		return false;
  	}
	if ((yyyy.length==4) && (parseInt(yyyy)<=1900 || parseInt(yyyy)>=2030))
  	{
  		alert("Invalid year");
		textbox.focus();
  		return false;
  	}
	var monthInt=+(parseInt(mm))
	if (monthInt==4)
	{
		var month="April"
	}
	if (monthInt==6)
	{
		var month="June"
	}
	if ((monthInt==9) || (mm=="09"))
	{
		var month="September"
	}
	if (monthInt==11)
	{
		var month="November"
	}
	if ((parseInt(yyyy)%400==0)||(!((parseInt(yyyy)%100==0)&&(parseInt(yyyy)%4==0)) && (parseInt(yyyy)%4==0)))
	{	
		//Leap Year
		if ((parseInt(mm)==2)&& (parseInt(dd)>29)) //februry
		{
			alert("Day of Februry month in a leap year should not be greater than 29")
			textbox.focus();
			return false;
		}
	}
	else
	{	
		//Simple Year
		if ((parseInt(mm)==2)&& (parseInt(dd)>28)) //februry
		{
			alert("Day of Februry month in a simple year should not be greater than 28")
			textbox.focus();
			return false;
		}
	}
	if (((parseInt(mm)==4) || (parseInt(mm)==6) || ((monthInt==9) || (mm=="09")) || (parseInt(mm)==11)) && (parseInt(dd)>30))
	{
		//month=april		      month=June         month=September	  month=November				
		alert("In " +month+ " month day should not be greater than 30")
		textbox.focus();
		return false;
	}
	return true;
}
//----------**end of function for validate date in a single textbox**----------//
function Format(total,decimals)
 {
      var num = parseFloat(total);
      // First section sets non-number value to zero
          if (!(num = parseFloat(num)))
               num = "0.00";
      // Second section sets two decimal place format
          var Pad = "";
          num = "" + Math.floor(num * Math.pow(10,decimals + 1) + 5);
          // Pad if less than 0.10
          if(num.length < decimals+1) 
          {
               for(Count = num.length; Count <= decimals; Count++)
                    Pad += "0";
          }
          num = Pad + num;
     // Parse into final string
          num = num.substring(0,num.length - decimals - 1) + 
               "." + num.substring(num.length - decimals -1, num.length -1);
     // If less than 1 then add 0 to the left of the decimal
          if((num == "") || (parseFloat(num) < 1))
               num = "0" + num;
     // Final section returns formatted number
          return num;
}
extArray = new Array(".gif",".jpg",".jpeg",".jpe");
function Allowed_Uploaded_Files(File_Value)
{
	allowSubmit = false;
	if (!File_Value)
	{
		return true;
	}
	while (File_Value.indexOf("\\") != -1)
	{
		File_Value = File_Value.slice(File_Value.indexOf("\\") + 1);
	}
	ext = File_Value.slice(File_Value.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++)
	{
		if (extArray[i] == ext)
		{
			allowSubmit = true;
			break;
		}
	}
	if (allowSubmit)
	{
		return true;
	}
	else
	{
		return false;
	}
}
