///////////////////////////////////
//to validate email id of visitor//
///////////////////////////////////
function validateSearch()
{
	//to ensure name has entered
	if(isBlankField(document.frmSearch.txtPhrase.value)==false)
	{
		alert ("Please enter a word / phrase to find with in website");
		document.frmSearch.txtPhrase.select();
		return false;
	}
	
	document.frmSearch.submit();
	
	//window.location.href="http://www.google.com/search?as_q="+document.frmSearch.txtPhrase.value+"&as_sitesearch=www.whitehopeindia.com"
	
	return false;
}

//////////////////////////
//to disable right click//
//////////////////////////
if (window.Event) // Only Netscape will have the CAPITAL E.
	document.captureEvents(Event.MOUSEUP); // catch the mouse up event
 
function nocontextmenu()  // this function only applies to IE4, ignored otherwise.
{
	event.cancelBubble = true
	event.returnValue = false;
	return false;
}
 
function norightclick(e) // This function is used by all others
{
	if (window.Event) // again, IE or NAV?
	{
		if (e.which == 2 || e.which == 3)
		return false;
	}
	else
	if (event.button == 2 || event.button == 3)
	{
		event.cancelBubble = true
		event.returnValue = false;
		return false;
	}
}
 
document.oncontextmenu = nocontextmenu;  // for IE5+
document.onmousedown = norightclick;  // for all others

/////////////////////////////////////////////
//to change the color of menu on mouse over//
/////////////////////////////////////////////
function on(obj)
{
	obj.style.backgroundColor="#DAA853";
}
function off(obj)
{
	obj.style.backgroundColor="#901010";
}

/////////////////////////
//to validate email-id //
/////////////////////////
function isValidEmail(eml)
{
	//declare the required variables
	var mint_len;
	var mstr_eml=eml;
	var mint_at=0;
	var mint_atnum=0;
	var mint_dot=0;
	var mint_dotnum=0;
	
	mint_len=eml.length; //takes the length of the email address entered
	
	//checking for the symbol single quote. If found replace it with its html code
	if (mstr_eml.indexOf("'")!=-1)
	{
		mstr_eml=mstr_eml.replace("'","&#39;");
	}
	
	//checking for the (@) & (.) symbol
	for(var iloop=0;iloop<mint_len;iloop++)
	{
		if(mstr_eml.charAt(iloop)=="@")
		{
			mint_at=iloop+1;
			mint_atnum=mint_atnum+1;
		}
		if(mstr_eml.charAt(iloop)==".")
		{
			mint_dot=iloop+1;
			mint_dotnum=mint_dotnum+1;
		}
	}
	
	//if nothing entered in the field
	if (mstr_eml=="")
	{
		return false
	}
	
	//if @ entered more than once & dot (.) entered more than 4 times
	else if((mint_atnum!=1)||(mint_dotnum>4)||((mint_dot-mint_at)<2)||((mint_len-mint_dot)<2)||(mint_at<3))
	{
		return false;
	}
	
	//if any blank space is entered in the email address
	else if (mstr_eml.indexOf(" ")!=-1)
	{
		return false;
	}
	return true;
}

/////////////////////////////////////////
//to validate date im mm/dd/yyyy format//
/////////////////////////////////////////
function isValidDate(datevalue)
{
	var input_date=new String(datevalue);
	var dat;
	var count=0;
	
	for (var m=0;m<input_date.length;m++)
		{
		if ((input_date.charAt(m)=="/")||(input_date.charAt(m)=="."))
			{
			count=count+1;
			}
		}
	if ((input_date.indexOf(" ")!=-1)||(count!=2))
		{
		return false;
		}
	if (input_date.indexOf("/")!=-1)
		{
		dat=input_date.split("/");
		}
	else if (input_date.indexOf(".")!=-1)
		{
		dat=input_date.split(".");
		}
	
		
	/////validations for month
	
	if (isNaN(dat[0]))
		{
		return false;
		}
	else if ((dat[0]<1)||(dat[0])>12)
		{
		return false;
		}
		
	//validations for days
	
	if (isNaN(dat[1]))
		{
		return false;
		}
	else if ((dat[0]=="1")||(dat[0]=="3")||(dat[0]=="5")||(dat[0]=="7")||(dat[0]=="8")||(dat[0]=="10")||(dat[0]=="12"))
		{
		
			if ((dat[1]<1)||(dat[1]>31))
				{
				return false;
				}
		}	
	else if ((dat[0]=="4")||(dat[0]=="6")||(dat[0]=="9")||(dat[0]=="11"))
		{
			if ((dat[1]<1)||(dat[1]>30))
				{
				return false;
				}
		}
	else if (dat[0]==2)
		{
			
			if ((dat[2] % 4)==0)
				{
				if ((dat[1]<1)||(dat[1]>29))
					{
					return false;
					}
				}
			else
				if((dat[1]<1)||(dat[1]>28))
					{
					return false;
					}
		}
		
	//validation for year
	
	if (isNaN(dat[2]))
	{
		return false;
	}
	else if ((dat[2].length!=2)&&(dat[2].length!=4))
	{
		return false;
	}
	if (dat[2] < 1900)
	{
		return false;
	}
}

////////////////////////////////
//to ensure field is not blank//
////////////////////////////////
function isBlankField(txt)
{
	var mint_txt=txt.length; //Takes the total length of the value entered
	var mstr_txt=txt;
	var mint_count=0;
	
	//checking with each character for space
	for(var iloop=0;iloop<mint_txt;iloop++)
	{
		if(mstr_txt.charAt(iloop)==" ")
		{
			mint_count=mint_count+1;
		}
	}
	
	//if nothing entered in the field
	if (txt=="")
	{
		return false;
	}
	
	//if only spaces are entered
	else if (mint_count==mint_txt)
	{
		return false;
	}
	else
	{
		return true;
	}
}

//////////////////////////////////////////////////
//to ensure number entered is a Positive Integer//
//////////////////////////////////////////////////
function isPositiveInteger(val)
{
	if (isNaN(val)==true)
	{
		return false;
	}
	var mystring=new String(val)
	var x=mystring.indexOf(".")
	if (x!="-1")
	{
		return false;
	}
	if (val<1)
	{
		return false;
	}    
}

////////////////////////////////////
//to trim a value entered in field//
///////////////////////////////////
function trimSpaces(pass)
{
	str = pass

	while(str.charAt(0) == " ")
	{
		str=str.substring(1,str.length)
	}
	while(str.charAt(str.length-1) == " ")
	{
		str=str.substring(0,str.length-1)
	}
	return (str);
}

////////////////////////////////////////////
//to replace double quotes by single quote//
////////////////////////////////////////////
function doubleQuotesReplace()
{
	var intRootCounter;
		
	for(intRootCounter = 0; intRootCounter<document.frmMain.elements.length; intRootCounter++)
	{
		if (((document.frmMain.elements[intRootCounter].type) == "text") || ((document.frmMain.elements[intRootCounter].type) == "textarea"))
		{
			var reg=/"/gi;
			document.frmMain.elements[intRootCounter].value = (document.frmMain.elements[intRootCounter].value).replace(reg,"'");
		}
	}
}

////////////////////////////
//to select all checkboxes//
////////////////////////////
function fnCheckAll()
{
	// to check all checkboxes
	for (i=0;i<document.frmMain.elements.length;i++)
	{
		if((document.frmMain.elements[i].name)=="chkCheckBox")
		{
			if(isNaN(document.frmMain.chkCheckBox.length))
			{
				if(document.frmMain.chkAll.checked==false)
				{
					document.frmMain.chkCheckBox.checked=false;
				}
				else
				{
					document.frmMain.chkCheckBox.checked=true;
				}
			}
			else
			{
				if(document.frmMain.chkAll.checked==false)
				{
					for(var iloop=0;iloop<document.frmMain.chkCheckBox.length;iloop++)
					{
						document.frmMain.chkCheckBox[iloop].checked=false;
					}
				}
				else
				{
					for(var iloop=0;iloop<document.frmMain.chkCheckBox.length;iloop++)
					{
						document.frmMain.chkCheckBox[iloop].checked=true;
					}
				}
			}
			break;
		}
	}
}

//////////////////////////////////////////////////////
//to validate main form and to call update form page//
//////////////////////////////////////////////////////
function fnUpdate(strFileName)
{
	//to check any check box exists on or not
	updateFlag = false;
	
	for (i=0;i<document.frmMain.elements.length;i++)
	{
		if((document.frmMain.elements[i].name) == "chkCheckBox") 
		{
			updateFlag = true;
		}
	}

	if (updateFlag == false)
	{
		alert ("Nothing is there to Update");
		return false;
	}

	//to ensure at least one checkbox selected
	
	intCounter = 0;
	
	// to check delete checkboxes
	for (i=0;i<document.frmMain.elements.length;i++)
	{
		if((document.frmMain.elements[i].name)=="chkCheckBox")
		{
			if(isNaN(document.frmMain.chkCheckBox.length))
			{
				if(document.frmMain.chkCheckBox.checked==true)
				{
					intCounter = intCounter + 1;		
				}
			}
			else
			{
				for(var iloop=0;iloop<document.frmMain.chkCheckBox.length;iloop++)
				{
					if (document.frmMain.chkCheckBox[iloop].checked)
					{
						intCounter = intCounter + 1;
					}
				}
			}
		}
	}
	
	
	if(intCounter == 0)
	{
		alert ("Please select at least one Checkbox");
		return false;
	}
	else
	{
		var str_reply = confirm("Are you sure you want to update all selected records ?")
	
		if (str_reply==false)
		{
			return false;
		}
		document.frmMain.action= strFileName
		document.frmMain.submit()	
		return true;
	}	
	return false;		
}

///////////////////////////////////////////////
//to validate upper panel of recordset paging//
///////////////////////////////////////////////
function validatePageNoUpNext(pageCount)
{
	//to ensure page no. has entered in page number text box
	if (isBlankField(document.frmRecordsetOne.txtPage.value) == false)
	{
		alert ("Please Enter Page Number, which has to be displayed.");
		document.frmRecordsetOne.txtPage.select();
		return false;		
	} 
	
	//to ensure a positive interger has entered
	if (isPositiveInteger(document.frmRecordsetOne.txtPage.value) == false)
	{
		alert ("Please Enter a Positive Integer for Page Number");
		document.frmRecordsetOne.txtPage.select();
		return false;		
	}
	
	//to ensure a valid value has entered
	if ((document.frmRecordsetOne.txtPage.value < 1) || (document.frmRecordsetOne.txtPage.value>pageCount))
	{
		alert ("Please enter a value between 1 and "+ pageCount + " for Page Number");
		document.frmRecordsetOne.txtPage.select();
		return false;
	}
	
	return true;
}

///////////////////////////////////////////////
//to validate lower panel of recordset paging//
///////////////////////////////////////////////
function validatePageNoDownNext(pageCount)
{
	//to ensure page no. has entered in page number text box
	if (isBlankField(document.frmRecordsetTwo.txtPage.value) == false)
	{
		alert ("Please Enter Page Number, which has to be displayed.");
		document.frmRecordsetTwo.txtPage.select();
		return false;		
	} 
	
	//to ensure a positive interger has entered
	if (isPositiveInteger(document.frmRecordsetTwo.txtPage.value) == false)
	{
		alert ("Please Enter a Positive Integer for Page Number");
		document.frmRecordsetTwo.txtPage.select();
		return false;		
	}
	
	//to ensure a valid value has entered
	if ((document.frmRecordsetTwo.txtPage.value < 1) || (document.frmRecordsetTwo.txtPage.value>pageCount))
	{
		alert ("Please enter a value between 1 and "+ pageCount + " for Page Number");
		document.frmRecordsetTwo.txtPage.select();
		return false;
	}
	
	return true;
}

//////////////////////////////////////////
//validate login for valid characters//
//////////////////////////////////////////
function isValidLogin(field)
{
	var valid = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ."
	var flag = true;
	var temp;
	for (var i=0; i<field.length; i++)
	{
		temp = "" + field.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			flag = false;
	}
	return flag;
}

//////////////////////////////////////////
//validate password for valid characters//
//////////////////////////////////////////
function isPassword(field)
{
	var valid = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._@"
	var flag = true;
	var temp;
	for (var i=0; i<field.length; i++)
	{
		temp = "" + field.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			flag = false;
	}
	return flag;
}

////////////////////////////////////////////
//validate image name for valid characters//
////////////////////////////////////////////
function isValidImageName(field)
{
	var valid = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.\\"
	var flag = true;
	var temp;
	for (var i=0; i<field.length; i++)
	{
		temp = "" + field.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			flag = false;
	}
	return flag;
}

////////////////////////////////
//to call edit, view page//
////////////////////////////////
function fnNewWindow(actionType,width,height,actionOn,id)
{
	myWindow = open (actionType+".asp?width="+width+"&height="+height+"&"+actionOn+"="+id,"newwin","scrollbars=yes,resizable=no,left=50,top=50");
}

///////////////////////////
//to validate Website URL//
///////////////////////////
function isValidURL(url)
{
	if (url.indexOf("http://www.") == "-1")
		return false;
	else
		return true;
	return true;
}