// JavaScript Document
function charsonly(field) {
		var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' "
		var ok = "yes";
		var temp;
		for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
		}
		if (ok == "no") {
		alert("Invalid entry!  Only characters are accepted!");
		field.focus();
		field.select();
		   }
		}

function digitsonly(field) {
		var valid = "0123456789.- "
		var ok = "yes";
		var temp;
		for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
		}
		if (ok == "no") {
		alert("Invalid entry!  Only Numbers are accepted!");
		field.focus();
		field.select();
		   }
		}

function validcharsonly(field) {
		var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890.'-(), "
		var ok = "yes";
		var temp;
		for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
		}
		if (ok == "no") {
		alert("Invalid entry!  Only characters and numbers are accepted!");
		field.focus();
		field.select();
		   }
		}

function checkEmail(txtEmail) {
	var EmailOk  = true;
	var temp     = txtEmail;//window.document.forms[0].txtEmail;
	var atsym    = temp.value.indexOf('@');
	var period   = temp.value.lastIndexOf('.');
	var space    = temp.value.indexOf(' ');
	var length   = temp.value.length - 1;
	if ((atsym < 1) || (period <= atsym+1) || (period == length ) || (space  != -1)) {  
		var emailok = false;
		alert('###### VALID EMAIL REQUIRED ###### \n Please enter a Valid Email Address! \n\n An example of a Valid Email Address would be \n\n userid@domainname.com \n')
		//temp.value='';
		temp.focus();
	}
	return emailok
}


function confirmReset()	{
	if (confirm("########## WARNING ########## \n This action will clear all data in the form. \n \n If you wish to Reset the Form, click on OK. \n If you wish to Cancel, click on CANCEL.")) {
	//	alert("The Form will now be cleared!");
		//focusIt();
		return true;
	}
	else {
		
		return false;
	}
}

//user validation starts here
function valiUser (strSrc)
{

  // ** START **
	fm = document.fmUser;
   if (fm.firstname.value == "" && fm.firstname.value.length<3) {
    alert( "Please Enter your Name." );
    fm.firstname.focus();
    return false ;
  }
   if (fm.username.value == "") {
    alert( "Please Enter User Name." );
    fm.username.focus();
    return false ;
  }
 if (fm.password.value == "") {
    alert( "Please Enter your password." );
    fm.password.focus();
    return false ;
  }
   if (fm.retypepassword.value != fm.password.value) {
    alert( "Confirm password should match" );
    fm.retypepassword.focus();
    return false ;
  }
   if (fm.email.value == ""){
    alert( "Please Enter your Email" );
    fm.email.focus();
    return false ;
  }  
  // ** END **
  return true ;
}
//role validation starts here
function valiRole(strSrc)
{
  // ** START **
	fm = document.fmRole;
   if (fm.txtRoleId.value == "") {
    alert( "Please Enter Role ID." );
    fm.txtRoleId.focus();
    return false ;
  }
   if (fm.txtRoleName.value == "") {
    alert( "Please Enter Role Name." );
    fm.txtRoleName.focus();
    return false ;
  }
  var no=0;
  for(k=3;k<=fm.length-3;k++)
	{
		if(fm.elements[k].type=="checkbox" && fm.elements[k].checked==true)
		{
			no=1;
		}
	}
	if(no<1)
	{
		alert("Select Options");
		return false;
	}
  // ** END **
  return true ;
}
function chkSubMenu(mainMenu,intSubMenucnt)
{alert('in');
	fm=document.fmRole;
	if(fm.elements['chkmain'+mainMenu].checked==true)
	{
		for(k=0;k<intSubMenucnt;k++)
		{
			if(fm.elements['chksub'+mainMenu+k].type=="checkbox")
			{
				fm.elements['chksub'+mainMenu+k].checked=true;
			}
		}
	}
	if(!fm.elements['chkmain'+mainMenu].checked==true)
	{
		for(k=0;k<intSubMenucnt;k++)
		{
			if(fm.elements['chksub'+mainMenu+k].type=="checkbox")
			{
				fm.elements['chksub'+mainMenu+k].checked=true;
			}
		}
	}
}
//signup1 validation
function valiSignup1 ()
{
	fm = document.fmSubscribe;
	if (fm.txtEmail.value == "" && checkNull(fm.txtEmail.value) || checkwrong(fm.txtEmail.value) || checkapo(fm.txtEmail.value)) {
    alert( "Please enter your Email" );
    fm.txtEmail.focus();
    return false ;
  }
  //validate newsletter subscription
  nlSelected = false;
  nlName =1;
  for (i=1; i<=(1+(fm.hidNLEditionCnt.value-1)); i++)
	{	  
		if(document.getElementById('cmbNLEdition'+nlName).checked == true)
		{
			nlSelected = true;
		}
		nlName=nlName+1;
	}
	if(nlSelected==false)
	{
		alert("Select the Editions for receiving Bindaas Daily Newsletter");
		return false;
	} 
}

//admin member registration validation starts here
function valiSignup2Admin (strSrc)
{
  // ** START **
	fm = document.fmSignup;
	if (fm.txtEmail.value == "" && checkNull(fm.txtEmail.value) || checkwrong(fm.txtEmail.value) || checkapo(fm.txtEmail.value)) 
	{
		alert( "Please enter your Email" );
		fm.txtEmail.focus();
		return false ;
	}
}
//user registration validation starts here
function valiSignup2 (strSrc)
{
  // ** START **
	fm = document.fmSignup;
	if (fm.txtEmail.value == "" && checkNull(fm.txtEmail.value) || checkwrong(fm.txtEmail.value) || checkapo(fm.txtEmail.value)) 
	{
		alert( "Please enter your Email" );
		fm.txtEmail.focus();
		return false ;
	}
	//validate newsletter subscription
	if(strSrc=="P")
	{
	  nlSelected = false;
	  nlName =1;
	  for (i=1; i<=(1+(fm.hidNLEditionCnt.value-1)); i++)
		{	  
			if(document.getElementById('cmbNLEdition'+nlName).checked == true)
			{
				nlSelected = true;
			}
			nlName=nlName+1;
		}
		if(nlSelected==false)
		{
			alert("Select alteast one Edition");
			return false;
		} 
	}
	  if (fm.txtPwd.value == "") {
		alert( "Please Enter your password." );
		fm.txtPwd.focus();
		return false ;
	  }
		if (fm.txtRetypePwd.value != fm.txtPwd.value) {
		alert( "Confirm password should match" );
		fm.txtRetypePwd.focus();
		return false ;
	  }

	if(fm.expcollPersonal.value=="E")
	{
	   if (fm.txtFName.value == "" && fm.txtFName.value.length<3) {
		alert( "Please enter your first name." );
		fm.txtFName.focus();
		return false ;
	  }
	   if (fm.txtLName.value == "" && fm.txtLName.value.length<3) {
		alert( "Please enter your last name." );
		fm.txtLName.focus();
		return false ;
	  }
	  if (fm.cmbGender.value == "") {
		alert( "Please select Gender." );
		fm.cmbGender.focus();
		return false ;
	  }
	  if (fm.cmbNationality.value == "") {
		alert( "Please select Nationality." );
		fm.cmbNationality.focus();
		return false ;
	  }
	  if (fm.cmbResidence.value == "") {
		alert( "Please select Residence Country." );
		fm.cmbResidence.focus();
		return false ;
	  }
	  /*if (fm.Img0.value == "" && fm.OldImg0.value=="") {
		alert( "Please upload photo." );
		fm.Img0.focus();
		return false ;
	  }*/
	}
	
	if(fm.expcollOther.value=="E")
	{
	   if (fm.cmbCompSize.value == "" ) {
		alert( "Please select Company size." );
		fm.cmbCompSize.focus();
		return false ;
	  }
	   if (fm.cmbDesignation.value == "" ) {
		alert( "Please select Designation." );
		fm.cmbDesignation.focus();
		return false ;
	  }
	  if (fm.cmbDesignation.value == "Other" && fm.txtOtherDesignation.value == "" ) {
		alert( "Please enter Other Designation." );
		fm.cmbDesignation.focus();
		return false ;
	  }
 	   if (fm.cmbOccupation.value == "" ) {
		alert( "Please select Occupation." );
		fm.cmbOccupation.focus();
		return false ;
	  }
 	   if (fm.cmbIncome.value == "" ) {
		alert( "Please select Income." );
		fm.cmbIncome.focus();
		return false ;
	  }
	   if (fm.txtHobbies.value == "" ) {
		alert( "Please enter Hobbies." );
		fm.txtHobbies.focus();
		return false ;
	  }
	}
}

//user registration validation starts here
function valiRegn (strSrc)
{
  // ** START **
	fm = document.fmCust;
   if (fm.txtFName.value == "" && fm.txtFName.value.length<3) {
    alert( "Please enter your first name." );
    fm.txtFName.focus();
    return false ;
  }
   if (fm.txtLName.value == "" && fm.txtLName.value.length<3) {
    alert( "Please enter your last name." );
    fm.txtLName.focus();
    return false ;
  }
 /* if (fm.txtAge.value == "") {
    alert( "Please enter your Age" );
    fm.txtAge.focus();
    return false ;
  }*/
   if (fm.txtEmail.value == "" && checkNull(fm.txtEmail.value) || checkwrong(fm.txtEmail.value) || checkapo(fm.txtEmail.value)) {
    alert( "Please enter your Email" );
    fm.txtEmail.focus();
    return false ;
  }
  
  if (fm.txtPwd.value == "") {
    alert( "Please Enter your password." );
    fm.txtPwd.focus();
    return false ;
  }
    if (fm.txtRetypePwd.value != fm.txtPwd.value) {
    alert( "Confirm password should match" );
    fm.txtRetypePwd.focus();
    return false ;
  }
/*  if (fm.txtCity.value == "" && fm.txtCity.value.length<5) {
    alert( "Please enter your city" );
    fm.txtCity.focus();
    return false ;
  }

  if (fm.cmbCountry.value == "") {
    alert( "Please select your country" );
    fm.cmbCountry.focus();
    return false ;
  }
  if (fm.cmbNationality.value == "") {
    alert( "Please select your Nationality" );
    fm.cmbNationality.focus();
    return false ;
  }*/
 /* if (fm.cmbEdition.value == "" || fm.cmbEdition.value == "0") {
    alert( "Please select preferred Edition" );
    fm.cmbEdition.focus();
    return false ;
  }*/
  //validate newsletter subscription
  nlSelected = false;
  nlName =1;
  for (i=12; i<=(12+(fm.hidNLEditionCnt.value-1)); i++)
	{	  
		if(document.getElementById('cmbNLEdition'+nlName).checked == true)
		{
			nlSelected = true;
		}
		nlName=nlName+1;
	}
	if(nlSelected==false)
	{
		alert("Select the Editions for receiving Bindaas Daily Newsletter");
		return false;
	} 
}

function valiLogin()
{
  // ** START **
	fm = document.fmLogin;
   if (fm.username.value == "") {
    alert( "Please Enter your username." );
    fm.username.focus();
    return false ;
  }
  if (fm.password.value == "") {
    alert( "Please Enter your password." );
    fm.password.focus();
    return false ;
  }
}

//category validation starts here
function valiCatg (strSrc)
{

  // ** START **
	fm = document.fmCatg;
   if (fm.txtCatgCode.value == "" && fm.txtCatgCode.value.length<2) {
    alert( "Please Enter Category Code." );
    fm.txtCatgCode.focus();
    return false ;
  }
   if (fm.txtCatgName.value == "" && fm.txtCatgName.value.length<3) {
    alert( "Please Enter Category Name." );
    fm.txtCatgName.focus();
    return false ;
  }
}
//sub category validation starts here
function valiSubCatg (strSrc)
{

  // ** START **
	fm = document.fmSubCatg;
   if (fm.cmbCatg.value == "" || fm.cmbCatg.value == "0" ) {
    alert( "Please Select Category." );
    fm.cmbCatg.focus();
    return false ;
  }
    if (fm.txtSubCatgId.value == "") {
    alert( "Please Enter Sub Category Code." );
    fm.txtSubCatgId.focus();
    return false ;
  }
   if (fm.txtSubCatgName.value == "" && fm.txtSubCatgName.value.length<3) {
    alert( "Please Enter Sub Category Name." );
    fm.txtSubCatgName.focus();
    return false ;
  }
}

//edition master validation starts here
function valiEdition (strSrc)
{
  // ** START **
	fm = document.fmEdition;
   if (fm.txtEditionCode.value == "" && fm.txtEditionCode.value.length<2) {
    alert( "Please Enter Edition Code." );
    fm.txtEditionCode.focus();
    return false ;
  }
   if (fm.txtEditionName.value == "" && fm.txtEditionName.value.length<3) {
    alert( "Please Enter Edition Name." );
    fm.txtEditionName.focus();
    return false ;
  }
   if (fm.txtEditionURL.value == "") {
    alert( "Please Enter Edition URL." );
    fm.txtEditionURL.focus();
    return false ;
  }
  /* if (fm.txtIPFrom.value == "") {
    alert( "Please Enter From IP Range." );
    fm.txtIPFrom.focus();
    return false ;
  }
   if (fm.txtIPTo.value == "") {
    alert( "Please Enter To IP Range." );
    fm.txtIPTo.focus();
    return false ;
  }*/
}

//location validation starts here
function valiLocation (strSrc)
{

  // ** START **
	fm = document.fmLoc;
   if (fm.txtLocCode.value == "" && fm.txtLocCode.value.length<2) {
    alert( "Please Enter Location Code." );
    fm.txtLocCode.focus();
    return false ;
  }
   if (fm.txtLocName.value == "" && fm.txtLocName.value.length<3) {
    alert( "Please Enter Location Name." );
    fm.txtLocName.focus();
    return false ;
  }
}

//story master validation starts here
function valiStory (strSrc)
{
  // ** START **
	fm = document.fmStory;
   if (fm.txtStoryCode.value == "" && fm.txtStoryCode.value.length<2) {
    alert( "Please Enter Story Code." );
    fm.txtStoryCode.focus();
    return false ;
  }
   if (fm.txtStoryCaption.value == "" && fm.txtStoryCaption.value.length<3) {
    alert( "Please Enter Story Caption." );
    fm.txtStoryCaption.focus();
    return false ;
  }
   if (fm.cmbEdition.value == "" || fm.cmbEdition.value == "0") {
    alert( "Please Select Edition." );
    fm.cmbEdition.focus();
    return false ;
  }
   if (fm.cmbCatg.value == "" || fm.cmbCatg.value == "0" ) {
    alert( "Please Select Category." );
    fm.cmbCatg.focus();
    return false ;
  }
   if (fm.cmbCatg.value != ""  && (fm.cmbSubCatg.value == "" || fm.cmbSubCatg.value == "0")) {
    alert( "Please Select Sub Category." );
    fm.cmbSubCatg.focus();
    return false ;
  }
  if ((fm.cmbEdition.value != "" || fm.cmbEdition.value != "0" ) && (fm.cmbLocation.value == "" || fm.cmbLocation.value == "0") ) {
    alert( "Please Select Location." );
    fm.cmbLocation.focus();
    return false ;
  }
  if (fm.txtStory.value == "") {
    alert( "Please Enter Story." );
    fm.txtStory.focus();
    return false ;
  }
  //return false;
}
//faq category validation starts here
function valiFaqCatg (strSrc)
{

  // ** START **
	fm = document.fmFAQCatg;
   if (fm.txtCatgCode.value == "" && fm.txtCatgCode.value.length<2) {
    alert( "Please Enter Category Code." );
    fm.txtCatgCode.focus();
    return false ;
  }
   if (fm.txtCatgName.value == "" && fm.txtCatgName.value.length<3) {
    alert( "Please Enter Category Name." );
    fm.txtCatgName.focus();
    return false ;
  }
}
//faq validation starts here
function valiFaq (strSrc)
{

  // ** START **
	fm = document.fmFAQ;
   if (fm.cmbFAQCatg.value == "" || fm.cmbFAQCatg.value == "0" ) {
    alert( "Please Select Category." );
    fm.cmbFAQCatg.focus();
    return false ;
  }
    if (fm.txtFaqQues.value == "") {
    alert( "Please Enter FAQ Question." );
    fm.txtSubCatgId.focus();
    return false ;
  }
   if (fm.txtFaqAnswer.value == "" && fm.txtFaqAnswer.value.length<3) {
    alert( "Please Enter Answer." );
    fm.txtFaqAnswer.focus();
    return false ;
  }
}
//deals validation starts here
function valiDeals (strSrc)
{
  // ** START **
	fm = document.fmDeal;
   if (fm.txtDealCaption.value == "" ) {
    alert( "Please Enter Caption." );
    fm.txtDealCaption.focus();
    return false ;
  }
   if (fm.txtDeals.value == "" ) {
    alert( "Please Enter Deals." );
    fm.txtDeals.focus();
    return false ;
  }
 
}

function valiPostRecommend()
{
  // ** START **
  fm=document.fmShare;
  if(fm.txtYourEmail.value =="" && checkNull(fm.txtYourEmail.value) || checkwrong(fm.txtYourEmail.value) || checkapo(fm.txtYourEmail.value))
  {
    alert( "Please Enter Your Email." );
    fm.txtYourEmail.focus();
    return false ;
  }
   if (fm.txtFrndEmail1.value == "" && checkNull(fm.txtFrndEmail1.value) || checkwrong(fm.txtFrndEmail1.value) || checkapo(fm.txtFrndEmail1.value)) {
    alert( "Please Enter atleast one email." );
    fm.txtFrndEmail1.focus();
    return false ;
  }
}

function valiSuggestion()
{
  // ** START **
  fm=document.fmSuggestion;
  if(fm.txtYourEmail.value =="" && checkNull(fm.txtYourEmail.value) || checkwrong(fm.txtYourEmail.value) || checkapo(fm.txtYourEmail.value))
  {
    alert( "Please Enter Your Email." );
    fm.txtYourEmail.focus();
    return false ;
  }
   if (fm.txtSuggestion.value == "") {
    alert( "Please Enter your suggestion." );
    fm.txtSuggestion.focus();
    return false ;
  }
}

function valiMemContact()
{
  // ** START **
  fm=document.fmMemContact;
  if(fm.txtYourEmail.value =="" && checkNull(fm.txtYourEmail.value) || checkwrong(fm.txtYourEmail.value) || checkapo(fm.txtYourEmail.value))
  {
    alert( "Please Enter Your Email." );
    fm.txtYourEmail.focus();
    return false ;
  }
   if (fm.txtSubject.value == "") {
    alert( "Please Enter Subject." );
    fm.txtSubject.focus();
    return false ;
  }
   if (fm.txtMessage.value == "") {
    alert( "Please Enter Message." );
    fm.txtMessage.focus();
    return false ;
  }
}
function UserManage(val,src)
{
	fm = document.fmUser;
	fm.hidId.value=val;
	fm.hidSubmit.value=src;
	if (src=="D")
	{
		if(confirm("Do you want to delete this record?"))
		{
			fm.submit();
		}
	}
	else if(src=="E" || src=="O")
	{
		
		fm.submit();
	}
}


function checknum (){
var temp     = window.document.forms[0].txtQuan;
if (!validateNumeric(form1.txtQuan.value == "")) {
  alert( "Please enter only numbers." );
  Form1.txtQuan.focus();
  return false ;
}
    return true ;
}

function winPopup(width,height,theurl) { 
	OpenWindow=window.open(theurl, "newwin", "height="+height+", width=" + width + ",toolbar=no,scrollbars=" + 1 + ",menubar=no,resizable=yes");
	self.name="child";
}

function textCounter(field, countfield, maxlimit) {
	alert(field)
	if (field.value.length > maxlimit)
	{
	field.value = field.value.substring(0, maxlimit);
	alert("Exceeded the number of characters allowed:"+maxlimit);

	}
	/*else
	{countfield.value = maxlimit - field.value.length;}
	*/
}

function checkwrong(mail)
{
if (mail.indexOf('@')==-1 || mail.indexOf('.')==-1 ||
			mail.indexOf('@')+1==mail.indexOf('.',mail.indexOf('@')) ||
			mail.indexOf('@')==0  || mail.lastIndexOf('.') == (mail.length-1))
		{
			return true;
		}
else 
		{
			return false;
		}
	
}  


function checkNull(strr)
{
	
   for(i=0;i<strr.length;i++)
	{
	  st=strr.charAt(i);
		  if(st!=" ")
	       {
     	   return false;
	       }
	}
	strr.value="";
	return true;
}
function checkapo(strr)
{
	
   for(i=0;i<strr.length;i++)
	{
	  st=strr.charAt(i);
		  if(st=="'" || st=='"' || st=='`')
	       {
     	   return true;
	       }
	}
	
}
