function openPopupWindow(url, width, height)
{
   window.open(url, "", "directories=0,height=" + height + ",location=0,menubar=0,resizable=1,scrollbars=0,status=0,toolbar=0,width=" + width);
}


/*
 * function to hide element by setting style "display: none;"
 *
 */
function hidediv(id) {
    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById(id).style.display = 'none';
    }
    else {
        if (document.layers) { // Netscape 4
            document.id.display = 'none';
        }
        else { // IE 4
            document.all.id.style.display = 'none';
        }
    }
}

/*
 * function to show element witch has "display: none;"
 *
 */
function showdiv(id) {
    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById(id).style.display = '';
    }
    else {
        if (document.layers) { // Netscape 4
            document.id.display = '';
        }
        else { // IE 4
            document.all.id.style.display = '';
        }
    }
}

// Radio Button Validation
// copyright Stephen Chapman, 15th Nov 2004,14th Sep 2005
// you may copy this function but please keep the copyright notice with it
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

/*
 *  function to show additional input box in case of
 *  selection "other" in "How did you hear about us?"
 */
function selectedIndexChanged(sender) {
    user_input = sender.options[sender.selectedIndex].value;
    if (user_input == -1) {
        showdiv('txtHowHeard')
    } else {
        hidediv('txtHowHeard')
    }
}

/*
 * function to validate email address
 */
function validateEmail(address) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if(reg.test(address) == false) {
        return false;
    }
    return true ;
}

/*
 * function to validate email address "on key up"
 */
function validateEmailOnKeyUp(input) {
    name = input.name;
    value = input.value;
    
    hidediv('valid_'+name);
    hidediv('wrong_'+name);
    
    if (value == "") {
    showdiv('valid_'+name);
    //getElementById(name).focus();
    return false;
    } else {
       if (validateEmail(value) == false) {
           showdiv('wrong_'+name);
           //name.focus();
           return false;
       }
    }
    return true;
}

/*
 * function to validate phone number
 */
function validatePhone(number) {
    var reg = /^([0-9\+\s-])+$/;
    if(reg.test(number) == false) {
        return false;
    }
    return true ;
}

/*
 * function to validate phone number "on key up"
 */
function validatePhoneOnKeyUp(input) {
    name = input.name;
    value = input.value;

    hidediv('valid_'+name);
    hidediv('wrong_'+name);

    if (value == "") {
    showdiv('valid_'+name);
    //getElementById(name).focus();
    return false;
    } else {
       if (validatePhone(value) == false) {
           showdiv('wrong_'+name);
           //value.focus();
           return false;
       }
    }
    return true;
}

/*
 * function to validate <input>
 */
function validateInput(input) {
    value = input.value;
    hidediv('valid_'+input.name);
    if (value == "") {
        showdiv('valid_'+input.name);
    }
}

/*
 * function to validate <select>
 */
function validateSelect(select) {
    value = select.value;
    hidediv('valid_'+select.name);
    if (value == "") {
        showdiv('valid_'+select.name);
    }
}

/*
 *  function to validate "contact us" form
 */
function validateContactUs(form,options) {
  hidediv('valid_txtFirstName');
  hidediv('valid_txtLastName');
  hidediv('valid_txtCompany');
  hidediv('valid_txtTitle');
  hidediv('valid_ddlCountry');
  hidediv('valid_txtEmail');
  hidediv('wrong_txtEmail');
  hidediv('valid_txtPhone');
  hidediv('wrong_txtPhone');

  if(options == false) {
      hidediv('valid_txtComments1');
  }

/*  execute just in case of ownership options contact us form */

  if(options == true){
      hidediv('valid_txtSucces');
      hidediv('valid_txtAttack');
      hidediv('valid_txtTarget');
      hidediv('valid_txtCompetition');
      hidediv('valid_txtInvest');
      hidediv('valid_txtCapital');
  }
/*   END execute just in case of ownership options contact us form */

  if (form.txtFirstName.value == "") {
    showdiv('valid_txtFirstName');
    form.txtFirstName.focus();
    return false ;
  }

  if (form.txtLastName.value == "") {
    showdiv('valid_txtLastName');
    form.txtLastName.focus();
    return false ;
  }

  if (form.txtCompany.value == "") {
    showdiv('valid_txtCompany');
    form.txtCompany.focus();
    return false ;
  }

  if (form.txtTitle.value == "") {
    showdiv('valid_txtTitle');
    form.txtTitle.focus();
    return false ;
  }

  if (form.ddlCountry.value == "") {
    showdiv('valid_ddlCountry');
    form.ddlCountry.focus();
    return false ;
  }

  if (form.txtEmail.value == "") {
      showdiv('valid_txtEmail');
      form.txtEmail.focus();
      return false;
  } else {
       if (!validateEmail(form.txtEmail.value)) {
           showdiv('wrong_txtEmail');
           form.txtEmail.focus();
           return false;
       }
  }

  if (form.txtPhone.value == "") {
    showdiv('valid_txtPhone');
    form.txtPhone.focus();
    return false ;
  } else {
       if (!validatePhone(form.txtPhone.value)) {
           showdiv('wrong_txtPhone');
           form.txtPhone.focus();
           return false;
       }
  }

  if(options == false) {
      if (form.txtComments1.value == "") {
        showdiv('valid_txtComments1');
        form.txtComments1.focus();
        return false ;
    }
  }


/*  execute just in case of ownership options contact us form */

if(options == true){

      if (form.txtSucces.value == "") {
        showdiv('valid_txtSucces');
        form.txtSucces.focus();
        return false ;
      }

      if (form.txtAttack.value == "") {
        showdiv('valid_txtAttack');
        form.txtAttack.focus();
        return false ;
      }

      if (form.txtTarget.value == "") {
        showdiv('valid_txtTarget');
        form.txtTarget.focus();
        return false ;
      }

      if (form.txtCompetition.value == "") {
        showdiv('valid_txtCompetition');
        form.txtCompetition.focus();
        return false ;
      }

      if (form.txtInvest.value == "") {
        showdiv('valid_txtInvest');
        form.txtInvest.focus();
        return false ;
      }

      if (form.txtCapital.value == "") {
        showdiv('valid_txtCapital');
        form.txtCapital.focus();
        return false ;
      }
    }
  /*   END execute just in case of ownership options contact us form */

  return true ;
}


/*
 * function to show hints
 */
function viewHint(sender, id, hints)
    {
        var el =  window.document.getElementById(id);

        el.style.display == sender.selectedIndex == 0 ? "none" : "block";

        hints = hints.split("|");
        el.innerHTML = sender.selectedIndex == 0 ? "" : hints[sender.selectedIndex];
    }

/*
 *  function to switching between operational stuctures
 */
function chooseStructure(structure) {
    hidediv('network');hidediv('standAloneCardroom');
    hidediv('independentAggregatedCardroom');hidediv('fullyManagedNetworkIntegratedCardroom');
    user_input = structure.options[structure.selectedIndex].value;
    if (user_input == 'Network') {
        showdiv('network'); 
    } else if (user_input == 'Stand Alone Cardroom') {
        showdiv('standAloneCardroom');
    } else if (user_input == 'Independent Aggregated Cardroom') {
        showdiv('independentAggregatedCardroom');
    } else if (user_input == 'Fully Managed Network Integrated Cardroom') {
        showdiv('fullyManagedNetworkIntegratedCardroom');
    }
}

/*
 * function to validate that options were selected
 * used for: standAloneCardroom
 *           network
 */
function validateOption_n_sac(type,form,justOne){
    var returnValue = true;

    if (justOne == 'all') {
        hidediv('valid_ddlCustomerService'+type);
        hidediv('valid_ddlRiskMgmtService'+type);
        hidediv('valid_ddlServerOwnership'+type);
        hidediv('valid_ddlServerHostService'+type);
        hidediv('valid_ddlLicenseeFee'+type);
    }
    
    if (justOne == 'all' || justOne == 'ddlCustomerService') {
        hidediv('valid_ddlCustomerService'+type);
        if (form.ddlCustomerService.value == -1) {
            showdiv('valid_ddlCustomerService'+type);
            returnValue = false ;
        }
    }

    if (justOne == 'all' || justOne == 'ddlRiskMgmtService') {
        hidediv('valid_ddlRiskMgmtService'+type);
        if (form.ddlRiskMgmtService.value == -1) {
            showdiv('valid_ddlRiskMgmtService'+type);
            returnValue = false ;
        }
    }

    if (justOne == 'all' || justOne == 'ddlServerOwnership') {
        hidediv('valid_ddlServerOwnership'+type);
        if (form.ddlServerOwnership.value == -1) {
            showdiv('valid_ddlServerOwnership'+type);
            returnValue = false ;
        }
    }

    if (justOne == 'all' || justOne == 'ddlServerHostService') {
        hidediv('valid_ddlServerHostService'+type);
        if (form.ddlServerHostService.value == -1) {
            showdiv('valid_ddlServerHostService'+type);
            returnValue = false ;
        }
    }

    if (justOne == 'all' || justOne == 'ddlLicenseeFee') {
        hidediv('valid_ddlLicenseeFee'+type);
        if (form.ddlLicenseeFee.value == -1) {
            showdiv('valid_ddlLicenseeFee'+type);
            returnValue = false ;
        }
    }

    return returnValue;
}

/*
 * function to validate that options were selected
 * used for: independentAggregatedCardroom
 *           fullyManagedNetworkIntegratedCardroom
 */
function validateOption_iac_fmnc(type,form,justOne){

    var returnValue = true;

    if (justOne == 'all') {
        hidediv('valid_ddlCustomerService'+type);
        hidediv('valid_ddlServerHostService'+type);
        hidediv('valid_ddlLicenseeFee'+type);
    }

    if (justOne == 'all' || justOne == 'ddlCustomerService') {
        hidediv('valid_ddlCustomerService'+type);
        if (form.ddlCustomerService.value == -1) {
            showdiv('valid_ddlCustomerService'+type);
            returnValue = false ;
        }
    }

    if (justOne == 'all' || justOne == 'ddlServerHostService') {
        hidediv('valid_ddlServerHostService'+type);
        if (form.ddlServerHostService.value == -1) {
            showdiv('valid_ddlServerHostService'+type);
            returnValue = false ;
        }
    }

    if (justOne == 'all' || justOne == 'ddlLicenseeFee') {
        hidediv('valid_ddlLicenseeFee'+type);
        if (form.ddlLicenseeFee.value == -1) {
            showdiv('valid_ddlLicenseeFee'+type);
            returnValue = false ;
        }
    }

    return returnValue;
}

/*
 * validate option onchange
 */
function validateOptionOnChange(type,form){

}


/*
 * function to validate part of intermediate form: design
 */
function validateInterFormDesign(form) {
    var returnValue = true;

    var radLogo = valButton(form.radLogo);
    if (radLogo == null) {
        showdiv('valid_radLogo');
        returnValue = false;
    }
    else hidediv('valid_radLogo');


    //--------------------------------------
    
    var radWebsiteDesign = valButton(form.radWebsiteDesign);
    if (radWebsiteDesign == null) {
        showdiv('valid_radWebsiteDesign');
        returnValue = false;
    } else hidediv('valid_radWebsiteDesign');

    //--------------------------------------

    if (form.txtWebsiteFeeling.value == "") {
        showdiv('valid_txtWebsiteFeeling');
        returnValue = false;
    } else {
        hidediv('valid_txtWebsiteFeeling');
    }

    var radCardroomDesign = valButton(form.radCardroomDesign);
    if (radCardroomDesign == null) {
        showdiv('valid_radCardroomDesign');
        returnValue = false;
    }else hidediv('valid_radCardroomDesign');




    // additional info if ELD is selected ---------


    if (radCardroomDesign == 'To be designed by ELG') {
        if (form.txtCardroomFeeling.value == "") {
            showdiv('valid_txtCardroomFeeling');
            returnValue = false;
        } else {
            hidediv('valid_txtCardroomFeeling');
        }
    }

    //--------------------------------------

    if (form.txtDesignApprovalFullName.value == "") {
        showdiv('valid_txtDesignApprovalFullName');
        returnValue = false;
    } else {
        hidediv('valid_txtDesignApprovalFullName');
    }

    if (form.txtDesignApprovalEmail.value == "") {
      showdiv('valid_txtDesignApprovalEmail');
      form.txtDesignApprovalEmail.focus();
      returnValue = false;
      } else {
           if (!validateEmail(form.txtDesignApprovalEmail.value)) {
               showdiv('wrong_txtDesignApprovalEmail');
               form.txtDesignApprovalEmail.focus();
               returnValue = false;
           }
       hidediv('valid_txtDesignApprovalEmail');
      }

    if (form.txtDesignApprovalPhone.value == "") {
        showdiv('valid_txtDesignApprovalPhone');
        form.txtDesignApprovalPhone.focus();
        returnValue = false;
    } else {
       if (!validatePhone(form.txtDesignApprovalPhone.value)) {
           showdiv('wrong_txtDesignApprovalPhone');
           form.txtDesignApprovalPhone.focus();
           returnValue = false;
       }
    hidediv('valid_txtDesignApprovalPhone');
    }

    if (form.txtDesignApprovalIM.value == "") {
        showdiv('valid_txtDesignApprovalIM');
        returnValue = false;
    } else {
        hidediv('valid_txtDesignApprovalIM');
    }

    /* temp returnValue = true;*/
    return returnValue;
}



/*
 * function to validate part of intermediate form: development
 */
function validateInterFormDevelopment(form) {
    var returnValue = true;


    //--------------------------------------

    if (form.txtDomainsForRealMoneyCardroom.value == "") {
        showdiv('valid_txtDomainsForRealMoneyCardroom');
        returnValue = false;
    } else {
        hidediv('valid_txtDomainsForRealMoneyCardroom');
    }

    if (form.txtDomainsForPracticeChipsCardroom.value == "") {
        showdiv('valid_txtDomainsForPracticeChipsCardroom');
        returnValue = false;
    } else {
        hidediv('valid_txtDomainsForPracticeChipsCardroom');
    }

    if (form.txtDomainsForAffiliateProgram.value == "") {
        showdiv('valid_txtDomainsForAffiliateProgram');
        returnValue = false;
    } else {
        hidediv('valid_txtDomainsForAffiliateProgram');
    }

    var radWebsiteDev = valButton(form.radWebsiteDev);
    if (radWebsiteDev == null) {
        showdiv('valid_radWebsiteDev');
        returnValue = false;
    }
    else hidediv('valid_radWebsiteDev');

    var radWebsiteHosting = valButton(form.radWebsiteHosting);
    if (radWebsiteHosting == null) {
        showdiv('valid_radWebsiteHosting');
        returnValue = false;
    }
    else hidediv('valid_radWebsiteHosting');

    var radMailHosting = valButton(form.radMailHosting);
    if (radMailHosting == null) {
        showdiv('valid_radMailHosting');
        returnValue = false;
    }
    else hidediv('valid_radMailHosting');

    //--------------------------------------

    if (form.txtDnsMgrName.value == "") {
        showdiv('valid_txtDnsMgrName');
        returnValue = false;
    } else {
        hidediv('valid_txtDnsMgrName');
    }

    if (form.txtDnsMgrEmail.value == "") {
      showdiv('valid_txtDnsMgrEmail');
      returnValue = false;
      } else {
           if (!validateEmail(form.txtDnsMgrEmail.value)) {
               showdiv('wrong_txtDnsMgrEmail');
               returnValue = false;
           }
       hidediv('valid_txtDnsMgrEmail');
      }

    if (form.txtDnsMgrPhone.value == "") {
        showdiv('valid_txtDnsMgrPhone');
        returnValue = false;
    } else {
       if (!validatePhone(form.txtDnsMgrPhone.value)) {
           showdiv('wrong_txtDnsMgrPhone');
           returnValue = false;
       }
    hidediv('valid_txtDnsMgrPhone');
    }

    if (form.txtDnsMgrIM.value == "") {
        showdiv('valid_txtDnsMgrIM');
        returnValue = false;
    } else {
        hidediv('valid_txtDnsMgrIM');
    }

    //--------------------------------------

    var radSslPurchase = valButton(form.radSslPurchase);
    if (radSslPurchase == null) {
        showdiv('valid_radSslPurchase');
        returnValue = false;
    }
    else hidediv('valid_radSslPurchase');
    // additional info owhen SSL is provided by ELG
    if (radSslPurchase == 'by ELG') {
        if (form.txtSslOrgName.value == "") {
        showdiv('valid_txtSslOrgName');
        returnValue = false;
        } else {
            hidediv('valid_txtSslOrgName');
        }

        if (form.txtSslEmail.value == "") {
          showdiv('valid_txtSslEmail');
          returnValue = false;
          } else {
               if (!validateEmail(form.txtDnsMgrEmail.value)) {
                   showdiv('wrong_txtSslEmail');
                   returnValue = false;
               }
           hidediv('valid_txtDnsMgrEmail');
          }

          if (form.txtSslCity.value == "") {
            showdiv('valid_txtSslCity');
            returnValue = false;
            } else {
                hidediv('valid_txtSslCity');
            }

            if (form.ddlSslCountry.value == "") {
            showdiv('valid_ddlSslCountry');
            returnValue = false;
            } else {
                hidediv('valid_ddlSslCountry');
            }

        }
    //END additional info owhen SSL is provided by ELG
    
    //--------------------------------------

    if (form.txtEmailFromWebsites.value == "") {
    showdiv('valid_txtEmailFromWebsites');
    returnValue = false;
    } else {
        hidediv('valid_txtEmailFromWebsites');
    }


    var radDevSupport = valButton(form.radDevSupport);
    if (radDevSupport == null) {
        showdiv('valid_radDevSupport');
        returnValue = false;
    }
    else hidediv('valid_radDevSupport');

    var radPlayerReg = valButton(form.radPlayerReg);
    if (radPlayerReg == null) {
        showdiv('valid_radPlayerReg');
        returnValue = false;
    }
    else hidediv('valid_radPlayerReg');

    var radCountryRestrict = valButton(form.radCountryRestrict);
    if (radCountryRestrict == null) {
        showdiv('valid_radCountryRestrict');
        returnValue = false;
    }
    else hidediv('valid_radCountryRestrict');

    /* temp returnValue = true;*/
    return returnValue;
}

/*
 * function to validate part of intermediate form: operations
 */
function validateInterFormOperations(form) {
    var returnValue = true;

    if (form.txtBackendFullName1.value == "") {
        showdiv('valid_txtBackendFullName1');
        returnValue = false;
    } else {
        hidediv('valid_txtBackendFullName1');
    }

    if (form.txtBackendEmail1.value == "") {
      showdiv('valid_txtBackendEmail1');
      returnValue = false;
      } else {
           if (!validateEmail(form.txtBackendEmail1.value)) {
               showdiv('wrong_txtBackendEmail1');
               returnValue = false;
           }
       hidediv('valid_txtBackendEmail1');
      }

      if (form.txtBackendDep1.value == "") {
            showdiv('valid_txtBackendDep1');
            returnValue = false;
        } else {
            hidediv('valid_txtBackendDep1');
        }

        //--------------------------------------
       if (form.txtLicMgrFullName.value == "") {
            showdiv('valid_txtLicMgrFullName');
            returnValue = false;
        } else {
            hidediv('valid_txtLicMgrFullName');
        }

        if (form.txtLicMgrEmail.value == "") {
          showdiv('valid_txtLicMgrEmail');
          returnValue = false;
          } else {
               if (!validateEmail(form.txtLicMgrEmail.value)) {
                   showdiv('wrong_txtLicMgrEmail');
                   returnValue = false;
               }
           hidediv('valid_txtLicMgrEmail');
          }

        if (form.txtLicMgrPhone.value == "") {
        showdiv('valid_txtLicMgrPhone');
        returnValue = false;
        } else {
           if (!validatePhone(form.txtLicMgrPhone.value)) {
               showdiv('wrong_txtLicMgrPhone');
               returnValue = false;
           }
        hidediv('valid_txtLicMgrPhone');
        }

        if (form.txtLicMgrIM.value == "") {
            showdiv('valid_txtLicMgrIM');
            returnValue = false;
        } else {
            hidediv('valid_txtLicMgrIM');
        }

        if (form.txtReconciliation.value == "") {
            showdiv('valid_txtReconciliation');
            returnValue = false;
        } else {
            hidediv('valid_txtReconciliation');
        }

        if (form.txtSignupBonuses.value == "") {
            showdiv('valid_txtSignupBonuses');
            returnValue = false;
        } else {
            hidediv('valid_txtSignupBonuses');
        }

        if (form.txtBonusAccount.value == "") {
            showdiv('valid_txtBonusAccount');
            returnValue = false;
        } else {
            hidediv('valid_txtBonusAccount');
        }

        if (form.txtAffilPayPlan.value == "") {
            showdiv('valid_txtAffilPayPlan');
            returnValue = false;
        } else {
            hidediv('valid_txtAffilPayPlan');
        }

        if (form.txtSpecTour.value == "") {
            showdiv('valid_txtSpecTour');
            returnValue = false;
        } else {
            hidediv('valid_txtSpecTour');
        }

        if (form.txtSpecPromo.value == "") {
            showdiv('valid_txtSpecPromo');
            returnValue = false;
        } else {
            hidediv('valid_txtSpecPromo');
        }

        var radPayment = valButton(form.radPayment);
        if (radPayment == null) {
            showdiv('valid_radPayment');
            returnValue = false;
        }else hidediv('valid_radPayment');

        if (form.txtCompanyPostalAddress.value == "") {
            showdiv('valid_txtCompanyPostalAddress');
            returnValue = false;
        } else {
            hidediv('valid_txtCompanyPostalAddress');
        }
  /* temp returnValue = true;*/
    return returnValue;
}

/*
 * jump to the second section of intermediate form: "development"
 *
 */
function toDevelopment(){
    if (validateInterFormDesign(document.getElementById('intermediaryForm'))) {
        hidediv('design');
        hidediv('operations');
        showdiv('development');
    }
}

/*
 * jump to the third section of intermediate form: "operations"
 *
 */
function toOperations(){
    if (validateInterFormDevelopment(document.getElementById('intermediaryForm'))) {
        hidediv('design');
        hidediv('development');
        showdiv('operations');
    }
}

/*
 * back to the second section of intermediate form: "development"
 *
 */
function backToDevelopment(){
         hidediv('design');
        hidediv('operations');
        showdiv('development');
}

/*
 * back to the first section of intermediate form: "design"
 *
 */
function backToDesign(){
        hidediv('development');
        hidediv('operations');
        showdiv('design');
}
