// JavaScript Document
//////////////
function checks(value,f)
{
		
	if(value=="Brochure in the mail")
	{ document.getElementById("apDiv1").innerHTML='<span id=sp >Enter 4 letter code on your brochure <input type=\'text\''+' name=\'code\'></span>';
    }
	else
	{
			document.getElementById("apDiv1").innerHTML='<span id=sp ></span>';
			var parentObj = document.getElementById('sp');
		
			parentObj.parentNode.removeChild(parentObj);  
	}		
}


function amount(form,val,regVal)
{

//alert(regVal);
form.total_reg_fee.value=val;
form.regType.value=regVal;
}

/*function blockWorkshops(wrkshopId)
{
	switch(wrkshopId)
	{
		case "W1":	Form1.wrkshp1[0].disabled=false;
					Form1.wrkshp1[1].disabled=false;
					Form1.wrkshp1[2].disabled=false;
					Form1.wrkshp2[0].disabled=true;
					Form1.wrkshp2[1].disabled=true;
					Form1.wrkshp2[2].disabled=true;
					Form1.wrkshp2[0].checked=Form1.wrkshp2[1].checked=Form1.wrkshp2[2].checked=false;
					break;
		case "W2":
					Form1.wrkshp1[0].disabled=true;
					Form1.wrkshp1[1].disabled=true;
					Form1.wrkshp1[2].disabled=true;
					Form1.wrkshp2[0].disabled=false;
					Form1.wrkshp2[1].disabled=false;
					Form1.wrkshp2[2].disabled=false;
					
					Form1.wrkshp1[0].checked=Form1.wrkshp1[1].checked=Form1.wrkshp1[2].checked=false;
					break;
	}
}*/

function grand_total(formName)
{
	if(formName.grpDiscountAmountType.value=="%")
		totalAmount=((Number(formName.total_conf_fee.value) + Number(formName.total_workshop_fee.value))*formName.grpDiscountAmount.value)/100;
	else
		totalAmount=formName.grpDiscountAmount.value;
	
	formName.total_discount.value=totalAmount;		
	
	if(formName.total_conf_fee.value != "0" || formName.total_workshop_fee.value != "0")
		formName.total_reg_fee.value=Number(formName.total_conf_fee.value)+Number(formName.total_workshop_fee.value)-totalAmount;
	else
		formName.total_reg_fee.value=Number(formName.total_conf_fee.value)+Number(formName.total_workshop_fee.value);
	
}

function add_confamount(form,val)
{
	if(form.conf.checked)
	{
		form.conf_fee.value=form.total_conf_fee.value=val;	
		Form1.wrkshp2.checked=Form1.wrkshp4.checked=Form1.wrkshp6.checked=false;
		form.total_workshop_fee.value=form.workshop_fee.value=0;
	}
	else
	{
		form.conf_fee.value=form.total_conf_fee.value=0;
		Form1.wrkshp1.checked=Form1.wrkshp3.checked=Form1.wrkshp5.checked=false;
		form.total_workshop_fee.value=form.workshop_fee.value=0;
	}
		
	grand_total(form);
}

function add_workshopamount(form,val,workshopId)
{
	var toatal=0;
	switch(workshopId)
	{
		case "W1":	if(form.conf.checked)
					{
						if(form.wrkshp3.checked)
							toatal=toatal+Number(form.wrkshp3.value);						
							
						if(form.wrkshp5.checked)
							toatal=toatal+Number(form.wrkshp5.value);
						
						if(form.wrkshp1.checked)
							toatal=toatal+Number(form.wrkshp1.value);
						
						form.total_workshop_fee.value=form.workshop_fee.value=toatal;
					}
					else
					{
						alert("To receive the discounted workshop registration fee, you must also register for the conference.");
						form.wrkshp1.checked=form.wrkshp3.checked=form.wrkshp5.checked=false;
					}
					break;
		case "W2":
					if(form.conf.checked)
					{
						alert("You are entitled to the discounted registration fee.  Please check the box next to \"with Conference\".");
						form.wrkshp2.checked=form.wrkshp4.checked=form.wrkshp6.checked=false;
					}
					else
					{						
						if(form.wrkshp4.checked)
							toatal=toatal+Number(form.wrkshp4.value);						
							
						if(form.wrkshp6.checked)
							toatal=toatal+Number(form.wrkshp6.value);
						
						if(form.wrkshp2.checked)
							toatal=toatal+Number(form.wrkshp2.value);
						
						form.total_workshop_fee.value=form.workshop_fee.value=toatal;
					}
					break;
	}
	grand_total(form);
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}


//


var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function formatPhone(num)
{ 
  var _return=false;
  /*
   * 7181238748 to 1(718)123-8748
   */ 

  if(num.length != 10)
  { 
    /* 
     * if user did not enter 10 digit phone number then simply print whatever user entered 
     */ 
	_return=_OUTPUT?num:false;
  } 
  else
  { 
    /* formating phone number here */ 
	_return="(";
	var ini = num.substring(0,3);
	_return+=ini+")";
	var st = num.substring(3,6);
	_return+=st+"-";
	var end = num.substring(6,10);
	_return+=end;
 }
  return _return; 
} 


function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function validate_phonenum(theForm){

    var s;

	s=stripCharsInBag(theForm.phonenumber1.value,validWorldPhoneChars);

	ret = isInteger(s) && (s.length > 4 && s.length < 16);

	if (ret == false) {
		return false;
	}

	if (theForm.phonenumber1.value.charAt(0) != "+") {
	    if (s.length == 10) {
	        theForm.phonenumber1.value = formatPhone(s); 
        }
    }

	return true;
}





function Validate_Index_Form(theForm)
{
		
	if (theForm.firstname.value == "")
  {
    alert("Please enter a value for the \"First Name\" field.");
    theForm.firstname.focus();
    return (false);
  }

  if (theForm.firstname.value.length < 1)
  {
    alert("Please enter at least 1 characters in the \"First Name\" field.");
    theForm.firstname.focus();
    return (false);
  }
  if (theForm.firstname.value.length > 45)
  {
    alert("Please enter at most 45 characters in the \"First Name\" field.");
    theForm.firstname.focus();
    return (false);
  }
  
  if (theForm.lastname.value == "")
  {
    alert("Please enter a value for the \"Last Name\" field.");
    theForm.lastname.focus();
    return (false);
  }
  
  if (theForm.lastname.value.length < 1)
  {
    alert("Please enter at least 1 characters in the \"Last Name\" field.");
    theForm.lastname.focus();
    return (false);
  }

  if (theForm.lastname.value.length > 45)
  {
    alert("Please enter at most 45 characters in the \"Last Name\" field.");
    theForm.lastname.focus();
    return (false);
  }
   //if (theForm.Occupation.value == "")
//  {
//    alert("Please enter a value for the \"Occupation\" field.");
//    theForm.Occupation.focus();
//    return (false);
//  }
//
//  if (theForm.Occupation.value.length < 4)
//  {
//    alert("Please enter at least 4 characters in the \"Occupation\" field.");
//    theForm.Occupation.focus();
//    return (false);
//  }
//
//  if (theForm.Occupation.value.length > 100)
//  {
//    alert("Please enter at most 100 characters in the \"Occupation\" field.");
//    theForm.Occupation.focus();
//    return (false);
//  }
 if (theForm.emailid.value == "")
  {
    alert("Please enter a value for the \"Email\" field.");
    theForm.emailid.focus();
    return (false);
  }

 if (validate_email(theForm) == false) {
	alert("Please enter a valid Email id");
        theForm.emailid.focus();
        return (false);
  }
  
  if (theForm.email_val.value == "false")
  {
    alert("Please enter a valid Email id");
    theForm.emailid.focus();
    return (false);
  }

   if (theForm.address1.value == "")
  {
    alert("Please enter a value for the \"Address\" field.");
    theForm.address1.focus();
    return (false);
  }

  if (theForm.address1.value.length < 4)
  {
    alert("Please enter at least 4 characters in the \"Address\" field.");
    theForm.address1.focus();
    return (false);
  }

  if (theForm.address1.value.length > 100)
  {
    alert("Please enter at most 100 characters in the \"Address\" field.");
    theForm.address1.focus();
    return (false);
  }

if (theForm.city.value == "")
  {
    alert("Please enter a value for the \"City\" field.");
    theForm.city.focus();
    return (false);
  }

  if (theForm.city.value.length < 4)
  {
    alert("Please enter at least 4 characters in the \"City\" field.");
    theForm.city.focus();
    return (false);
  }

  if (theForm.city.value.length > 45)
  {
    alert("Please enter at most 45 characters in the \"City\" field.");
    theForm.city.focus();
    return (false);
  }
 if (theForm.fmcountry.selectedIndex < 0)
  {
    alert("Please select one of the \"Country\" options.");
    theForm.fmcountry.focus();
    return (false);
  }

  if (theForm.fmcountry.selectedIndex == 0)
  {
    alert("The first \"Country\" option is not a valid selection.  Please choose one of the other options.");
    theForm.fmcountry.focus();
    return (false);
  }
  
   if (theForm.fmstate.value =="")
  {
    alert("Please select one of the \"state\" options.");
    theForm.fmstate.focus();
    return (false);
  }

  if (theForm.fmstate.selectedIndex == 0)
  {
    alert("The first \"state\" option is not a valid selection.  Please choose one of the other options.");
    theForm.fmstate.focus();
    return (false);
  }
   if (theForm.zip.value =="")
  {
    alert("Please enter the \"Zip\" code.");
    theForm.zip.focus();
    return (false);
  }
  
   if (theForm.phonenumber1.value == "")
  {
    alert("Please enter a value for the \"Phone\" field.");
    theForm.phonenumber1.focus();
    return (false);
  }

  if (validate_phonenum(theForm) == false) 
  {
	alert("Please enter a valid phone number");
        theForm.phonenumber1.focus();
        return (false);
  }
   if(theForm.phonenumber2.value!="")
   {
   theForm.phonenumber.value=theForm.phonenumber1.value+"-"+theForm.phonenumber2.value;
   //theForm.phonenumber.value=theForm.phonenumber.value+;
   }
   else
   {
    theForm.phonenumber.value=theForm.phonenumber1.value;
   }
   
  if (theForm.heard.selectedIndex == 0)
  {
    alert("Please enter a choice to tell us how you heard about this conference."); 
    theForm.heard.focus();
    return (false);
  }
   

/*if(!(theForm.parent.checked || theForm.professional.checked))
  {
	  alert("Please choose your role.");
	  theForm.parent.focus();
	  return (false);
  }
  */
  for(i=0;i<theForm.check.length;i++)
   {
	  if(theForm.check[i].checked)
	  {
	  	if(theForm.profession.value=="")
	  	{
		  theForm.profession.value=theForm.check[i].value;
	  	}
  	  	else
     	{
	  	 theForm.profession.value=theForm.profession.value+",";
	 	 theForm.profession.value=theForm.profession.value+theForm.check[i].value;
     	}
	  }
   }
   
      if(theForm.profession.value=="")
	  	{
		  theForm.profession.value=theForm.checktext.value;
	  	}
  	  	else
     	{
	  	theForm.profession.value=theForm.profession.value+",";
	 	 theForm.profession.value=theForm.profession.value+theForm.checktext.value;
     	}


/*if(!(theForm.fee[0].checked || theForm.fee[1].checked || theForm.fee[2].checked || theForm.fee[3].checked|| theForm.fee[4].checked|| theForm.fee[5].checked || theForm.fee[6].checked || theForm.fee[7].checked || theForm.fee[8].checked || theForm.fee[9].checked || theForm.fee[10].checked|| theForm.fee[11].checked|| theForm.fee[12].checked || theForm.fee[13].checked))
  {
	  alert("Please select a conference or workshop type.");
	  theForm.fee[0].checked=false;
	  theForm.fee[1].checked=false;
	  theForm.fee[2].checked=false;
	  theForm.fee[3].checked=false;
	  theForm.fee[4].checked=false;
	  theForm.fee[5].checked=false;
	  theForm.fee[6].checked=false;
	  theForm.fee[7].checked=false;
	  theForm.fee[8].checked=false;
	  theForm.fee[9].checked=false;
	  theForm.fee[10].checked=false;
	  theForm.fee[11].checked=false;
	  theForm.fee[12].checked=false;
	  theForm.fee[13].checked=false;
	
	  
	  theForm.fee[0].focus();
	  return (false);
  }*/
  
  if(!theForm.conf.checked && !theForm.wrkshp1.checked && !theForm.wrkshp2.checked && !theForm.wrkshp3.checked && !theForm.wrkshp4.checked && !theForm.wrkshp5.checked && !theForm.wrkshp6.checked)
  {
	  alert("Please do register for conference or workshop");
	  theForm.conf.focus();
	  return false;
  }
  
  return true;
	
	
	
}

//
//function validate_email(theForm){
//	var emailID=theForm.emailid;
//	
//	if ((emailID.value==null)||(emailID.value=="")){
//		return false
//	}
//	if (echeck(emailID.value)==false){
//		return false
//	}
//	return true
// }

function validate_email(FrontPage_Form1){
	var emailID=FrontPage_Form1.emailid;
	
	if ((emailID.value==null)||(emailID.value=="")){
		return false
	}
	if (echeck(emailID.value)==false){
		return false
	}
	return true
 }

