// JavaScript Document
function isblank(s) {
/************************************************
DESCRIPTION: Validates that a string is not all
  blank (whitespace) characters.

PARAMETERS:
value - the String to be tested for validity

RETURNS:
   True if valid, otherwise false.
*************************************************/

//alert(s);
     for (var i = 0; i < s.length; i++) {
          var c = s.charAt(i);
          if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
}
return true;
}
function CheckSelect(Obj,Errmsg)
{
		if(Obj.value=="")
		{
			if(isblank(Errmsg))
			alert("Please enter value for " + Obj.name);
			else
			alert(Errmsg);
			
			Obj.focus();
			return false;
		}
}
function CheckEmpty(Obj,Errmsg)
{ 
	if (isblank(Obj.value)) {
		if(isblank(Errmsg))
		alert("Please enter value for " + aa);
		else
		alert(Errmsg);
		Obj.focus();
		return false;
	}
	return true;
}

function generalvalidate(formobj)
{
	for(counter=0;counter<formobj.elements.length;counter++)
	{
			objs=formobj.elements[counter];
			if(objs.type!="hidden")
				if(isblank(objs.value))
				{
						alert("Please enter value for "+objs.name);
						objs.focus();
						return false;
				}
	}
}

function validateemail(em)
{

	var mailvalid=0;
	if(em.indexOf(".")==-1 || em.indexOf("@")==-1 )
	mailvalid=1;
	if(em.substring(0,em.indexOf("@")-1).length <1)
		mailvalid=1;
	if(em.substring(em.indexOf("@")+1,em.indexOf(".")).length<1)
		mailvalid=1;
	if(em.substring((eval(em.indexOf("."))+eval(1)),em.length).length<1)
		mailvalid=1;
	return mailvalid;
}

function checkphone(val)
{
	str="1234567890";
	le=val.length;
	for(i=0;i<l;i++)
	{
		alert(str.indexOf(vals.charAt(i))>0);
	}
}

function CheckStr(Obj,str,Errmsg)
{
l=Obj.value.length;
vals=Obj.value;
//alert(str.indexOf(vals.charAt(2)))
	if(isblank(Obj.value))
	{
		alert("Please Enter value for "+ Obj.name);
		Obj.focus();
		return false;
	}
	else
	{
		for(i=0;i<=l;i++)
		{
			if(str.indexOf(vals.charAt(i))<0)
			{
				if(isblank(Errmsg))
				alert("Please enter valid value for "+Obj.name);
				else
				alert(Errmsg);
				
				Obj.focus();
				return false;
			}
		}
	}
	return true;
}

function CheckValueMax(Obj,maxval,Errmsg)
{
	if(Obj.value>maxval)
	{
		if(isblank(Errmsg))
		alert("Please enter value less than "+ maxval);
		else
		alert(Errmsg);
		
		Obj.focus();
		return false;
	}
	return true;
}

function CheckLength(Obj,len,minmax,Errmsg)
{
	if(minmax=="<")
	{
		if(Obj.value.length<=len)
		{
			if(isblank(Errmsg))
			alert("Please Enter length greater than "+ len + " for " + Obj.name);
			else
			alert(Errmsg);
			
			Obj.focus();
			return false;
		}
	}
	else if(minmax==">")
	{
		if(Obj.value.length>=len)
		{
			if(isblank(Errmsg))
			alert("Please Enter length less than "+ len + " for " + Obj.name);
			else
			alert(Errmsg);
			
			Obj.focus();
			return false;
		}
	}
	return true;
}

function CheckEmail(Obj,Errmsg)
{
	if(validateemail(Obj.value)==1)
	{
		if(isblank(Errmsg))
		alert("Please enter valid Email for "+Obj.name);
		else
		alert(Errmsg);
		
		Obj.focus()
		return false;
	}
	return true;
}


function checknumbersonly(vals)
{
//str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYS._', "
str="1234567890";
//l=obj.value.length;
l=vals.length;
for(i=0;i<=l;i++)
{
	if(str.indexOf(vals.charAt(i))>0)
	{
		//alert("Enter Characters only");
		//obj.value="";
		//obj.focus();
		return false;
	}
}
}

function CheckRadio(obj,msg)
{
	//var n=0
	for(i=0;i<obj.length;i++)
	{
		if(obj[i].checked)
		{
			return true
		}
	}
	alert(msg)
	return false
	
}
function checkcheckbox(obj)
{
	k=0;
//if return value - 0 , there is no object is selected
	if (obj.length)
	{
		for(ii=0;ii<obj.length;ii++)
		{
		 if (obj[ii].checked==true)
			   k=1;
		 }
	}
	else
	{
		if (obj.checked==true)
		k=1;
	}
return k;
}

function checkcheckboxone(obj)
{		
		k=0;
		if (obj.length)
		{
			for(ii=0;ii<obj.length;ii++)
			{
			 if (obj[ii].checked==true)
			 {
				   k=k+1;
				   reportid=obj[ii].value;
			 }
			 }
		}
		else
		{
			if (obj.checked==true)
			{
			k=1;
			}
		}
return k;
}

function checkAllCheckBoxes(obj,val)
{
if(val==1) // Select all
{
	for (i = 0; i < obj.length; i++)
		obj[i].checked = true ;
}

if(val==0) // Select all
{
	for (i = 0; i < obj.length; i++)
		obj[i].checked = false ;
}

}


function editsingle(pagename)
{
	document.forms[0].operation.value="edit";
	document.forms[0].action=pagename;
	document.forms[0].submit();
}

function edit(control,pagename)
{
	if(editcheck(control)!=1)
	{
		alert("Please select only one checkbox to Edit");
	}
	else
	{
		document.forms[0].operation.value="edit";
		document.forms[0].action=pagename;
//		+"?pageno="+pageno;
		document.forms[0].submit();
	}
}

function add(pagename)
{
	document.forms[0].operation.value="add";
	document.forms[0].action=pagename;
	document.forms[0].submit();
}

function operate(chkcontrol,op,page,hidval)
{
	var flag=0;
	hidval.value=op;
	if(checkcheckbox(chkcontrol)==0)
	alert("Please select atleast one to "+op);
	else
	flag=1;
	
	if(flag==1)
	{
		if(op=="delete")
		{
			if(confirm("Are you sure, you want to delete"))
			{
				document.forms[0].action=page;
				document.forms[0].submit();
			}
		}
		else
		{
			document.forms[0].action=page;
			document.forms[0].submit();
		}
	}
	//checkcheckboxone
}

function operatesingle(op,page,hidval)
{
	var flag=1;
	hidval.value=op;
	if(op=="delete")
	{
		if(confirm("Are you sure, you want to delete"))
		{
			document.forms[0].action=page;
			document.forms[0].submit();
		}
	}
	else
	{
		document.forms[0].action=page;
		document.forms[0].submit();
	}
}

function editcheck(obj)
{		
		var reportid;
		var nan;
		k=0;
		if (obj.length)
		{
			for(ii=0;ii<obj.length;ii++)
			{
			 if (obj[ii].checked==true)
			 {
				   k=k+1;
				   reportid=obj[ii].value;
				   nan=ii;
			 }
			 }
		}
		else
		{
			if (obj.checked==true)
			{
			k=1;
		   reportid=obj.value;
		   nan=0;
			}
		}
		return k;
		//have to check k==1 then one is checked. 
		/*
		if(k==1)
		{
			document.form1.operation.value="edit";
			if(nan==0)
			document.form1.AdminId.value=obj.value;
			else
			document.form1.AdminId.value=obj[nan].value;
			
			document.form1.action="addadmin.asp";
			document.form1.submit();
		}
		else
		{
			alert("Please select only one check box to edit");
		}*/
} 
function lengthcheck(vals,maxlen,Errmsg)
{
	if(vals.length>maxlen)
	{
		if(isblank(Errmsg))
		alert("Please Enter less than "+ maxlen + " characters");
		else
		alert(Errmsg);
	}
}
function pagesubmit(page)
{
	document.forms[0].action=page;
	document.forms[0].submit();
}
function Open(page)
{
	document.forms[0].action=page;
	document.forms[0].submit();
}

function gotopage(pcount)
{
var pageno;
pageno=document.forms[0].pageno.value;
if(CheckStr(document.forms[0].pageno,"1234567890","")==false)
{
	return false;
}
else
{
	if (pcount<pageno)
	{
		alert("Please enter valid page no. Total pages are : "+pcount);
		document.forms[0].pageno.focus();
		return false;
	}
	movepageto(pageno);
}
}

function OpenUploadImageForm(imagefor,objname,oldimagename)
{
	window.open("Upload/ImgUploadform.asp?ImageFor="+imagefor+"&objname="+objname+"&oldimagename="+oldimagename,"","width=400,height=180");
}


<!--
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: David Leppek :: https://www.azcode.com/Mod10

Basically, the alorithum takes each digit, from right to left and muliplies each second
digit by two. If the multiple is two-digits long (i.e.: 6 * 2 = 12) the two digits of
the multiple are then added together for a new number (1 + 2 = 3). You then add up the 
string of numbers, both unaltered and new values and get a total sum. This sum is then
divided by 10 and the remainder should be zero if it is a valid credit card. Hense the
name Mod 10 or Modulus 10. */
function isCreditCard(ccNumb) {  // v2.0
var valid = "0123456789"  // Valid digits in a credit card number
var len = ccNumb.length;  // The length of the submitted cc number
var iCCN = parseInt(ccNumb);  // integer of ccNumb
var sCCN = ccNumb.toString();  // string of ccNumb
sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces
var iTotal = 0;  // integer total set at zero
var bNum = true;  // by default assume it is a number
var bResult = false;  // by default assume it is NOT a valid cc
var temp;  // temp variable for parsing string
var calc;  // used for calculation of each digit

// Determine if the ccNumb is in fact all numbers
for (var j=0; j<len; j++) {
  temp = "" + sCCN.substring(j, j+1);
  if (valid.indexOf(temp) == "-1"){bNum = false;}
}

// if it is NOT a number, you can either alert to the fact, or just pass a failure
if(!bNum){
  /*alert("Not a Number");*/bResult = false;
}

// Determine if it is the proper length 
if((len == 0)&&(bResult)){  // nothing, field is blank AND passed above # check
  bResult = false;
} else{  // ccNumb is a number and the proper length - let's see if it is a valid card number
  if(len >= 15){  // 15 or 16 for Amex or V/MC
    for(var i=len;i>0;i--){  // LOOP throught the digits of the card
      calc = parseInt(iCCN) % 10;  // right most digit
      calc = parseInt(calc);  // assure it is an integer
      iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
      i--;  // decrement the count - move to the next digit in the card
      iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
      calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
      calc = calc *2;                                 // multiply the digit by two
      // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
      // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
      switch(calc){
        case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
        case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
        case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
        case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
        case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
        default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
      }                                               
    iCCN = iCCN / 10;  // subtracts right most digit from ccNum
    iTotal += calc;  // running total of the card number as we loop
  }  // END OF LOOP
  if ((iTotal%10)==0){  // check to see if the sum Mod 10 is zero
    bResult = true;  // This IS (or could be) a valid credit card number.
  } else {
    bResult = false;  // This could NOT be a valid credit card number
    }
  }
}
// change alert to on-page display or other indication as needed.
/*if(bResult) {
  alert("This IS a valid Credit Card Number!");
}
if(!bResult){
  alert("This is NOT a valid Credit Card Number!");
}*/
  return bResult; // Return the results
}
// -->

