function openWin(url, name) {
                         openNew = window.open(url, name, 'directories=no,height=400,width=500,resizable=yes,menubar=no,scrollbars=yes');
 }

// Function to check the domain transfer request
function checkDomainTransfer() {
       document.forms[0].domainName.value = trimSpaces(document.forms[0].domainName.value);
        if(document.forms[0].domainName.value.length <= 0) {
                alert("Please enter domain name to transfer");
                document.forms[0].domainName.focus();
                return false;
        }
}


// Function to check the login by the user
function checkLogin() {
        document.forms[0].username.value = trimSpaces(document.forms[0].username.value);
        if(document.forms[0].username.value.length <= 0) {
                alert("Please enter your username");
                document.forms[0].username.focus();
                return false;
        }
        document.forms[0].password.value = trimSpaces(document.forms[0].password.value);
        if(document.forms[0].password.value.length <= 0) {
                alert("Please enter your password");
                document.forms[0].password.focus();
                return false;
        }

}

// Function to check the domain name
function checkDomain() {
        document.forms[0].username.value = trimSpaces(document.forms[0].username.value);

        document.forms[0].username.value = trimSpaces(document.forms[0].username.value);
        if(document.forms[0].username.value.length <= 0) {
                alert("Please enter your username");
                document.forms[0].username.focus();
                return false;
        }
        document.forms[0].password.value = trimSpaces(document.forms[0].password.value);
        if(document.forms[0].password.value.length <= 0) {
                alert("Please enter your password");
                document.forms[0].password.focus();
                return false;
        }

}
//Function to check the domain name
function checkDomainAvailable() {
        //alert(document.forms[1].checkDomainName.value);
        if(document.forms[1].singleDomainStatus.value == 1){

                     document.forms[1].domainName.value = trimSpaces(document.forms[1].domainName.value);
                     if(document.forms[1].domainName.value.length <= 0) {
                             alert("Please enter requested domain name");
                             document.forms[1].domainName.focus();
                             return false;
                     }

                     if(document.forms[1].checkDomainName.checked == false) {
                             alert("Please check availability of domain name");
                             document.forms[1].checkDomainName.blur();
                             return false;
                     }

      }
}
// Function to check for changing the password by the user
function userChangePwd() {
        document.forms[0].userName.value = trimSpaces(document.forms[0].userName.value);
        if(document.forms[0].userName.value.length <= 0) {
                alert("Please enter your userName");
                document.forms[0].userName.focus();
                return false;
        }
        document.forms[0].oldPassword.value = trimSpaces(document.forms[0].oldPassword.value);
        if(document.forms[0].oldPassword.value.length <= 0) {
                alert("Please enter your old password");
                document.forms[0].oldPassword.focus();
                return false;
        }
        document.forms[0].newPassword.value = trimSpaces(document.forms[0].newPassword.value);
        if(document.forms[0].newPassword.value.length <= 0) {
                alert("Please enter your new password");
                document.forms[0].newPassword.focus();
                return false;
        }
        document.forms[0].confirmPassword.value = trimSpaces(document.forms[0].confirmPassword.value);
        if(document.forms[0].confirmPassword.value.length <= 0) {
                alert("Please confirm your new password");
                document.forms[0].confirmPassword.focus();
                return false;
        }
        if( (document.forms[0].newPassword.value.length) != (document.forms[0].confirmPassword.value.length) ) {
                alert("Confirm password must be same as  New Password");
                document.forms[0].confirmPassword.focus();
                return false;
        }

}
// Function to check the login by the new user
function checkNewLogin() {
        document.forms[0].username.value = trimSpaces(document.forms[0].username.value);
        if(document.forms[0].username.value.length <= 0) {
                alert("Please enter your username");
                document.forms[0].username.focus();
                return false;
        }
          if(document.forms[0].username.value.length < 5  || document.forms[0].username.value.length > 15 ) {
                alert("Please enter your username which should be atleast 5 letters and not more than 15 letters ");
                document.forms[0].username.focus();
                return false;
        }

        document.forms[0].password.value = trimSpaces(document.forms[0].password.value);
        if(document.forms[0].password.value.length <= 0) {
                alert("Please enter your password");
                document.forms[0].password.focus();
                return false;
        }
        document.forms[0].confirmPassword.value = trimSpaces(document.forms[0].confirmPassword.value);
        if(document.forms[0].confirmPassword.value.length <= 0) {
                alert("Please confirm your password");
                document.forms[0].confirmPassword.focus();
                return false;
        }
        if(document.forms[0].confirmPassword.value != document.forms[0].password.value) {
                alert("Both password should be same, Please try again");
                document.forms[0].confirmPassword.focus();
                return false;
        }

}



// Function to display the print invoice window
function printInvoiceDetails() {


                sWidth = screen.availWidth;
                sHeight = screen.availHeight;

                sTop = (sHeight - 300) / 2;
                sLeft = (sWidth - 650) / 2;
                window.open("orderServiceInvoice.php", "Invoice", "width=650,height=300,top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=1,status=0,scrollbars=1,resizable=0");
                //alert("ok");

                //document.forms[0].action = "orderServiceInvoice.php";
                //document.forms[0].target = "printInvoice";
                //document.forms[0].submit();


}
// Function to validate the customer information entered before ordering packages
function checkOrder() {
        document.forms[0].firstName.value = trimSpaces(document.forms[0].firstName.value);
        if(document.forms[0].firstName.value.length <= 0) {
                alert("Please enter your first name");
                document.forms[0].firstName.focus();
                return false;
        }

        document.forms[0].lastName.value = trimSpaces(document.forms[0].lastName.value);
        if(document.forms[0].lastName.value.length <= 0) {
                alert("Please enter your last name");
                document.forms[0].lastName.focus();
                return false;
        }

        document.forms[0].emailID.value = trimSpaces(document.forms[0].emailID.value);
        if(!checkEmail(document.forms[0].emailID.value)) {
                document.forms[0].emailID.focus();
                return false;
        }

        document.forms[0].street.value = trimSpaces(document.forms[0].street.value);
        if(document.forms[0].street.value.length <= 0) {
                alert("Please enter the street address");
                document.forms[0].street.focus();
                return false;
        }

        document.forms[0].city.value = trimSpaces(document.forms[0].city.value);
        if(document.forms[0].city.value.length <= 0) {
                alert("Please enter the city");
                document.forms[0].city.focus();
                return false;
        }

        document.forms[0].state.value = trimSpaces(document.forms[0].state.value);
        if(document.forms[0].state.value.length <= 0) {
                alert("Please enter the state");
                document.forms[0].state.focus();
                return false;
        }

        document.forms[0].postalCode.value = trimSpaces(document.forms[0].postalCode.value);
        if(document.forms[0].postalCode.value.length <= 0) {
                alert("Please enter the postal code");
                document.forms[0].postalCode.focus();
                return false;
        }

        document.forms[0].telephone.value = trimSpaces(document.forms[0].telephone.value);
        if(document.forms[0].telephone.value.length <= 0) {
                alert("Please enter the telephone number");
                document.forms[0].telephone.focus();
                return false;
        }
}

// Function to display the selected package information while ordering for the package
// This will be shown in a new window.
function showPackageDetails(packageId) {
        sWidth = screen.availWidth;
        sHeight = screen.availHeight;

        sTop = (sHeight - 180) / 2;
        sLeft = (sWidth - 700) / 2;
        window.open("packageDetails.php?packageid=" + packageId, "packageDetails", "width=700,height=180,top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
        return;
}


// Function to check the order form where the payment details are involved
function checkPayment() {
        if(document.forms[0].paymentOption.value == "prepaidcoupon") {
                document.forms[0].couponNumber.value = trimSpaces(document.forms[0].couponNumber.value);
                if(document.forms[0].couponNumber.value.length <= 0) {
                        alert("Please enter the prepaid coupon number");
                        document.forms[0].couponNumber.focus();
                        return false;
                }
        }
        if(document.forms[0].paymentOption.value == "demanddraft") {

                    document.forms[0].transAmount.value = trimSpaces(document.forms[0].transAmount.value);
                    document.forms[0].refillAmount.value = trimSpaces(document.forms[0].refillAmount.value);
                    document.forms[0].firstTakeUp.value = trimSpaces(document.forms[0].firstTakeUp.value);
                    document.forms[0].userType.value = parseInt(document.forms[0].userType.value);
                    document.forms[0].userType.value = trimSpaces(document.forms[0].userType.value);

                //checking refillamount and first takeup

                if(parseInt(document.forms[0].userType.value) == 1){
                       if( parseFloat(document.forms[0].transAmount.value) < parseFloat(document.forms[0].refillAmount.value) ){

                           alert("Amount is below the minimum refill amount");
                           document.forms[0].transAmount.focus();
                           return false;
                       }
                }else{

                       if(parseFloat(document.forms[0].transAmount.value) < parseFloat(document.forms[0].firstTakeUp.value)){
                           alert("Amount is below the minimum first take up amount");
                           document.forms[0].transAmount.focus();
                           return false;
                       }

                }





                    document.forms[0].transNumber.value = trimSpaces(document.forms[0].transNumber.value);
                if(document.forms[0].transNumber.value.length <= 0) {
                        alert("Please enter the DD number");
                        document.forms[0].transNumber.focus();
                        return false;
                }
                document.forms[0].transDate.value = trimSpaces(document.forms[0].transDate.value);
                if(document.forms[0].transDate.value.length <= 0) {
                        alert("Please enter the DD date");
                        document.forms[0].transDate.focus();
                        return false;
                }
                dateSplit = document.forms[0].transDate.value.split("/");
                if(dateSplit.length != 3) {
                        alert("Please enter a valid date in 'dd/mm/yyyy' format");
                        document.forms[0].transDate.focus();
                        return false;
                }
                if(isNaN(dateSplit[0]) || isNaN(dateSplit[1]) || isNaN(dateSplit[2])) {
                        alert("Please enter a valid date in 'dd/mm/yyyy' format");
                        document.forms[0].transDate.focus();
                        return false;
                }
                if(!checkDate(dateSplit[0], dateSplit[1], dateSplit[2])) {
                        document.forms[0].transDate.focus();
                        return false;
                }

                if(document.forms[0].transAmount.value.length <= 0) {
                        alert("Please enter the DD amount");
                        document.forms[0].transAmount.focus();
                        return false;
                }
                if(parseFloat(document.forms[0].transAmount.value) <= 0) {
                        alert("Please enter a value greater than 0 for the DD amount");
                        document.forms[0].transAmount.focus();
                        return false;
                }
                if(isNaN(parseFloat(document.forms[0].transAmount.value))) {
                        alert("Please enter a numeric value for the DD amount");
                        document.forms[0].transAmount.focus();
                        return false;
                }


                document.forms[0].transBank.value = trimSpaces(document.forms[0].transBank.value);
                if(document.forms[0].transBank.value.length <= 0) {
                        alert("Please enter the name of bank");
                        document.forms[0].transBank.focus();
                        return false;
                }
                document.forms[0].transBranch.value = trimSpaces(document.forms[0].transBranch.value);
                if(document.forms[0].transBranch.value.length <= 0) {
                        alert("Please enter the branch of bank");
                        document.forms[0].transBranch.focus();
                        return false;
                }



        }
        if(document.forms[0].paymentOption.value == "cheque" ) {
                document.forms[0].transAmount.value = trimSpaces(document.forms[0].transAmount.value);
                    document.forms[0].refillAmount.value = trimSpaces(document.forms[0].refillAmount.value);
                    document.forms[0].firstTakeUp.value = trimSpaces(document.forms[0].firstTakeUp.value);
                    document.forms[0].userType.value = parseInt(document.forms[0].userType.value);
                    document.forms[0].userType.value = trimSpaces(document.forms[0].userType.value);

                //checking refillamount and first takeup

                if(parseInt(document.forms[0].userType.value) == 1){
                       if( parseFloat(document.forms[0].transAmount.value) < parseFloat(document.forms[0].refillAmount.value) ){

                           alert("Amount is below the minimum refill amount");
                           document.forms[0].transAmount.focus();
                           return false;
                       }
                }else{

                       if(parseFloat(document.forms[0].transAmount.value) < parseFloat(document.forms[0].firstTakeUp.value)){
                           alert("Amount is below the minimum first take up amount");
                           document.forms[0].transAmount.focus();
                           return false;
                       }

                }


                document.forms[0].transNumber.value = trimSpaces(document.forms[0].transNumber.value);
                if(document.forms[0].transNumber.value.length <= 0) {
                        alert("Please enter the cheque number");
                        document.forms[0].transNumber.focus();
                        return false;
                }
                document.forms[0].transDate.value = trimSpaces(document.forms[0].transDate.value);
                if(document.forms[0].transDate.value.length <= 0) {
                        alert("Please enter the cheque date");
                        document.forms[0].transDate.focus();
                        return false;
                }
                dateSplit = document.forms[0].transDate.value.split("/");
                if(dateSplit.length != 3) {
                        alert("Please enter a valid date in 'dd/mm/yyyy' format");
                        document.forms[0].transDate.focus();
                        return false;
                }
                if(isNaN(dateSplit[0]) || isNaN(dateSplit[1]) || isNaN(dateSplit[2])) {
                        alert("Please enter a valid date in 'dd/mm/yyyy' format");
                        document.forms[0].transDate.focus();
                        return false;
                }
                if(!checkDate(dateSplit[0], dateSplit[1], dateSplit[2])) {
                        document.forms[0].transDate.focus();
                        return false;
                }
                document.forms[0].transAmount.value = trimSpaces(document.forms[0].transAmount.value);
                if(document.forms[0].transAmount.value.length <= 0) {
                        alert("Please enter the cheque amount");
                        document.forms[0].transAmount.focus();
                        return false;
                }
                if(parseFloat(document.forms[0].transAmount.value) <= 0) {
                        alert("Please enter a value greater than 0 for the cheque amount");
                        document.forms[0].transAmount.focus();
                        return false;
                }
                if(isNaN(parseFloat(document.forms[0].transAmount.value))) {
                        alert("Please enter a numeric value for the cheque amount");
                        document.forms[0].transAmount.focus();
                        return false;
                }
                document.forms[0].transAmount.value = parseFloat(document.forms[0].transAmount.value);

                document.forms[0].transBank.value = trimSpaces(document.forms[0].transBank.value);
                if(document.forms[0].transBank.value.length <= 0) {
                        alert("Please enter the name of bank");
                        document.forms[0].transBank.focus();
                        return false;
                }
                document.forms[0].transBranch.value = trimSpaces(document.forms[0].transBranch.value);
                if(document.forms[0].transBranch.value.length <= 0) {
                        alert("Please enter the branch of bank");
                        document.forms[0].transBranch.focus();
                        return false;
                }


        }//ending check
        if(document.forms[0].paymentOption.value == "wiretransfer") {
               document.forms[0].transAmount.value = trimSpaces(document.forms[0].transAmount.value);
                    document.forms[0].refillAmount.value = trimSpaces(document.forms[0].refillAmount.value);
                    document.forms[0].firstTakeUp.value = trimSpaces(document.forms[0].firstTakeUp.value);
                    document.forms[0].userType.value = parseInt(document.forms[0].userType.value);
                    document.forms[0].userType.value = trimSpaces(document.forms[0].userType.value);

                //checking refillamount and first takeup

                if(parseInt(document.forms[0].userType.value) == 1){
                       if( parseFloat(document.forms[0].transAmount.value) < parseFloat(document.forms[0].refillAmount.value) ){

                           alert("Amount is below the minimum refill amount");
                           document.forms[0].transAmount.focus();
                           return false;
                       }
                }else{

                       if(parseFloat(document.forms[0].transAmount.value) < parseFloat(document.forms[0].firstTakeUp.value)){
                           alert("Amount is below the minimum first take up amount");
                           document.forms[0].transAmount.focus();
                           return false;
                       }

                }


                document.forms[0].transNumber.value = trimSpaces(document.forms[0].transNumber.value);
                if(document.forms[0].transNumber.value.length <= 0) {
                        alert("Please enter the transaction number");
                        document.forms[0].transNumber.focus();
                        return false;
                }
                document.forms[0].transDate.value = trimSpaces(document.forms[0].transDate.value);
                if(document.forms[0].transDate.value.length <= 0) {
                        alert("Please enter the wire transfer date");
                        document.forms[0].transDate.focus();
                        return false;
                }
                dateSplit = document.forms[0].transDate.value.split("/");
                if(dateSplit.length != 3) {
                        alert("Please enter a valid date in 'dd/mm/yyyy' format");
                        document.forms[0].transDate.focus();
                        return false;
                }
                if(isNaN(dateSplit[0]) || isNaN(dateSplit[1]) || isNaN(dateSplit[2])) {
                        alert("Please enter a valid date in 'dd/mm/yyyy' format");
                        document.forms[0].transDate.focus();
                        return false;
                }
                if(!checkDate(dateSplit[0], dateSplit[1], dateSplit[2])) {
                        document.forms[0].transDate.focus();
                        return false;
                }
                document.forms[0].transAmount.value = trimSpaces(document.forms[0].transAmount.value);
                if(document.forms[0].transAmount.value.length <= 0) {
                        alert("Please enter the wire transfer amount");
                        document.forms[0].transAmount.focus();
                        return false;
                }
                if(parseFloat(document.forms[0].transAmount.value) <= 0) {
                        alert("Please enter a value greater than 0 for the wire transfer amount");
                        document.forms[0].transAmount.focus();
                        return false;
                }
                if(isNaN(parseFloat(document.forms[0].transAmount.value))) {
                        alert("Please enter a numeric value for the wire transfer amount");
                        document.forms[0].transAmount.focus();
                        return false;
                }
                document.forms[0].transAmount.value = parseFloat(document.forms[0].transAmount.value);

                document.forms[0].transBank.value = trimSpaces(document.forms[0].transBank.value);
                if(document.forms[0].transBank.value.length <= 0) {
                        alert("Please enter the name of bank");
                        document.forms[0].transBank.focus();
                        return false;
                }
                document.forms[0].transBranch.value = trimSpaces(document.forms[0].transBranch.value);
                if(document.forms[0].transBranch.value.length <= 0) {
                        alert("Please enter the branch name");
                        document.forms[0].transBranch.focus();
                        return false;
                }



        }//ending wire transfer
        if(document.forms[0].paymentOption.value == "creditcard") {


        }

      if(document.forms[0].procedure.value == "refill"){
      document.forms[0].action = "refillYourAccount3.php";

      }
       if(document.forms[0].procedure.value == " "){

      document.forms[0].action = "placeServiceOrder.php";
      }
      document.forms[0].target = "";
}

/***************************************************************************************/
// General functions
/***************************************************************************************/

/////////////////////////////////////////////////////////////////////////////////////////
// Checks whether a date entered is a valid date or not.
/////////////////////////////////////////////////////////////////////////////////////////
function checkDate(ddVal, mmVal, yyVal) {
        if(ddVal <= 0 || ddVal > 31 || mmVal <= 0 || mmVal > 12 || yyVal <= 0 || yyVal.length != 4) {
                alert("Please enter a valid date");
                return false;
        }
        monthArray = new Array("January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
        if(mmVal == 2) {
                if(yyVal % 4 == 0) {
                        if(ddVal > 29) {
                                alert("February " + yyVal + " has only 29 days");
                                return false;
                        }
                }
                else {
                        if(ddVal > 28) {
                                alert("February " + yyVal + " has only 28 days");
                                return false;
                        }
                }
        }
        else {
                if(mmVal == 4 || mmVal == 6 || mmVal == 9 || mmVal == 11) {
                        if(ddVal > 30) {
                                alert(monthArray[mmVal-1] + " has only 30 days");
                                return false;
                        }
                }
        }
        return true;
}

/////////////////////////////////////////////////////////////////////////////////////////
// Checks whether a string is a valid email address.
/////////////////////////////////////////////////////////////////////////////////////////
function checkEmail(emailString) {
        splitVal = emailString.split('@');

        if(splitVal.length <= 1) {
                alert("Please enter a valid email address");
                return false;
        }
        if(splitVal[0].length <= 0 || splitVal[1].length <= 0) {
                alert("Please enter a valid email address");
                return false;
        }

        splitDomain = splitVal[1].split('.');
        if(splitDomain.length <= 1) {
                alert("Please enter a valid email address");
                return false;
        }
        if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1) {
                alert("Please enter a valid email address");
                return false;
        }
        return true;
}

/////////////////////////////////////////////////////////////////////////////////////////
// Removes the leading and trailing spaces in a strings and returns the trimmed string
/////////////////////////////////////////////////////////////////////////////////////////
function trimSpaces(stringValue) {
        // Checks the first occurance of spaces and removes them
        for(i = 0; i < stringValue.length; i++) {
                if(stringValue.charAt(i) != " ") {
                        break;
                }
        }
        if(i > 0) {
                stringValue = stringValue.substring(i);
        }

        // Checks the last occurance of spaces and removes them
        strLength = stringValue.length - 1;
        for(i = strLength; i >= 0; i--) {
                if(stringValue.charAt(i) != " ") {
                        break;
                }
        }
        if(i < strLength) {
                stringValue = stringValue.substring(0, i + 1);
        }

        // Returns the string after removing leading and trailing spaces.
        return stringValue;
}