function changeDiv(the_div,the_change)
{
var the_style = getStyleObject(the_div);
if (the_style != false)
{
  the_style.display = the_change;
}
}

function getStyleObject(objectId) {
  if (document.getElementById && document.getElementById(objectId)) {
	      return document.getElementById(objectId).style;
} else if (document.all && document.all(objectId)) {
    return document.all(objectId).style;
      } else {
  return false;
    }
}


function rounder(number,X) {
// rounds number to X decimal places, defaults to 2
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function Xtend(Q, N) {
var P;
Q = String(Q);
if (/e/i.test(Q)) {
return Q;
}
while ((P = Q.indexOf(".")) < 0) {
Q += ".";
}
while (Q.length <= P + N) {
Q += "0";
}
return Q;
}


function ST() {

var skins = document.order.controlpanel.value;
var setup=0;
document.order.skintotal.value = setup;
}




function UT() {

var install=0;
var disk=0;

if (document.order.packagecost.value == 0) { packagecost=79
 }
if (document.order.packagecost.value == 1) { packagecost=109
 }
if (document.order.packagecost.value == 2) { packagecost=129
 }


if (document.order.installcb.checked==true)
	{
	var install=50;
	}

var validcost = document.order.valid.value;
var servercost = document.order.server.value;
var discount=1;
var totalcost = install + packagecost*validcost*servercost;

totalcost = totalcost * discount;
totalcost = rounder(totalcost,2);
totalcost = Xtend(totalcost,2);
document.order.total.value = totalcost;
}

function validateEmailv2(email)
{
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}

function CCValidate()
{
    var frm = document.forms["order"];
    r=frm.ccnumber.value
    var no_digit = r.length;
    var oddoeven = no_digit & 1;
    var sum = 0;
    var i, n, c, r, t;
    for (i = 0; i < no_digit; i++) {
        c = parseInt(r.charAt(i));
        if (!((i & 1) ^ oddoeven))
        {
            c *= 2;
            if (c > 9)
            {
                c -= 9;
            }
        }
        sum += c;
    }
    if (sum != 0 && sum % 10 == 0)
    {
        return true;
    }
    else
    {
        alert('The Credit Card number is invalid!');
        return false;
    }
}

function V2validateData(strValidateStr,objValue,strError) 
{ 
    var epos = strValidateStr.search("="); 
    var  command  = ""; 
    var  cmdvalue = ""; 
    if(epos >= 0) 
    { 
     command  = strValidateStr.substring(0,epos); 
     cmdvalue = strValidateStr.substr(epos+1); 
    } 
    else 
    { 
     command = strValidateStr; 
    } 
    switch(command) 
    { 
        case "req": 
        case "required": 
         { 
           if(eval(objValue.value.length) == 0) 
           { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " : Required Field"; 
              }//if 
              alert(strError); 
              return false; 
           }//if 
           break;             
         }//case required 
        case "maxlength": 
        case "maxlen": 
          { 
             if(eval(objValue.value.length) >  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : "+cmdvalue+" characters maximum "; 
               }//if 
               alert(strError + "\n[Current length = " + objValue.value.length + " ]"); 
               return false; 
             }//if 
             break; 
          }//case maxlen 
        case "minlength": 
        case "minlen": 
           { 
             if(eval(objValue.value.length) <  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : " + cmdvalue + " characters minimum  "; 
               }//if               
               alert(strError + "\n[Current length = " + objValue.value.length + " ]"); 
               return false;                 
             }//if 
             break; 
            }//case minlen 
        case "alnum": 
        case "alphanumeric": 
           { 
              var charpos = objValue.value.search("[^A-Za-z0-9]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
               if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only alpha-numeric characters allowed "; 
                }//if 
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break; 
           }//case alphanumeric 
        case "num": 
        case "numeric": 
           { 
              var charpos = objValue.value.search("[^0-9]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only digits allowed "; 
                }//if               
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break;               
           }//numeric 
        case "alphabetic": 
        case "alpha": 
           { 
              var charpos = objValue.value.search("[^A-Za-z]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only alphabetic characters allowed "; 
                }//if                             
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break; 
           }//alpha 
		case "alnumhyphen":
			{
              var charpos = objValue.value.search("[^A-Za-z0-9\-_]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": characters allowed are A-Z,a-z,0-9,- and _"; 
                }//if                             
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 			
			break;
			}
        case "email": 
          { 
               if(!validateEmailv2(objValue.value)) 
               { 
                 if(!strError || strError.length ==0) 
                 { 
                    strError = objValue.name+": Enter a valid Email address "; 
                 }//if                                               
                 alert(strError); 
                 return false; 
               }//if 
           break; 
          }//case email 
        case "lt": 
        case "lessthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              alert(objValue.name+": Should be a number "); 
              return false; 
            }//if 
            if(eval(objValue.value) >=  eval(cmdvalue)) 
            { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " : value should be less than "+ cmdvalue; 
              }//if               
              alert(strError); 
              return false;                 
             }//if             
            break; 
         }//case lessthan 
        case "gt": 
        case "greaterthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              alert(objValue.name+": Should be a number "); 
              return false; 
            }//if 
             if(eval(objValue.value) <=  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : value should be greater than "+ cmdvalue; 
               }//if               
               alert(strError); 
               return false;                 
             }//if             
            break; 
         }//case greaterthan 
        case "regexp": 
         { 
            if(!objValue.value.match(cmdvalue)) 
            { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name+": Invalid characters found "; 
              }//if                                                               
              alert(strError); 
              return false;                   
            }//if 
           break; 
         }//case regexp 
        case "dontselect": 
         { 
            if(objValue.selectedIndex == null) 
            { 
              alert("BUG: dontselect command for non-select Item"); 
              return false; 
            } 
            if(objValue.selectedIndex == eval(cmdvalue)) 
            { 
             if(!strError || strError.length ==0) 
              { 
              strError = objValue.name+": Please Select one option "; 
              }//if                                                               
              alert(strError); 
              return false;                                   
             } 
             break; 
         }//case dontselect 
    }//switch 
    return true; 
}

function validate_form(form)
{

if (V2validateData("req",form.firstname,"Please enter your First Name.")==false) {
form.firstname.focus();return false;
}
if (V2validateData("req",form.lastname,"Please enter your Last Name.")==false) {
form.lastname.focus();return false;
}
if (V2validateData("req",form.address,"Please enter your Address.")==false) {
form.address.focus();return false;
}
if (V2validateData("req",form.city,"Please enter your City.")==false) {
form.city.focus();return false;
}
if (V2validateData("req",form.zip,"Please enter your ZIP/Postal Code.")==false) {
form.zip.focus();return false;
}
if (V2validateData("dontselect=0",form.country,"Please select your Country.")==false) {
form.country.focus();return false;
}
if (V2validateData("req",form.phonenumber,"Please enter your Phone Number.")==false) {
form.phonenumber.focus();return false;
}
if (V2validateData("req",form.email,"Please enter your Email address.")==false) {
form.email.focus();return false;
}
if (V2validateData("email",form.email,"Please enter a valid Email address.")==false) {
form.email.focus();return false;
}
if (V2validateData("req",form.referred_by,"Please let us know how you heard about us.")==false) {
form.referred_by.focus();return false;
}
if (V2validateData("req",form.ccname,"Please enter the Name as shown on the Credit Card.")==false) {
form.ccname.focus();return false;
}
if (V2validateData("req",form.ccnumber,"Please enter the Credit Card number.")==false) {
form.ccnumber.focus();return false;
}
if (V2validateData("num",form.ccnumber,"Only digits are allowed in the Credit Card number field.")==false) {
form.ccnumber.focus();return false;
}
if (V2validateData("minlen=15",form.ccnumber,"The Credit Card number has to be at least 15 digits long.")==false) {
form.ccnumber.focus();return false;
}
if (V2validateData("maxlen=16",form.ccnumber,"The Credit Card number cannot be more than 16 digits long.")==false) {
form.ccnumber.focus();return false;
}
if (V2validateData("regexp=^[3,4,5,6].*",form.ccnumber,"Please enter a valid Credit Card number.")==false) {
form.ccnumber.focus();return false;
}
if (CCValidate()==false) {
form.ccnumber.focus();return false;
}
if (V2validateData("req",form.csr,"Please enter your Certificate Signing Request.")==false) {
form.csr.focus();return false;
}
if (V2validateData("req",form.cccvv,"Please enter the CVV2/CVC2 number of your Credit Card. On MC, VISA and Discover there are 3 digits on the back, on AMEX there are 4 digits on the front of the card.")==false) {
form.cccvv.focus();return false;
}
if (V2validateData("minlen=3",form.cccvv,"The Credit Card CVV2/CVC2 number has to be at least 3 digits long.")==false) {
form.cccvv.focus();return false;
}
if (V2validateData("maxlen=4",form.cccvv,"The Credit Card CVV2/CVC2 number cannot be more than 4 digits long.")==false) {
form.cccvv.focus();return false;
}
if (V2validateData("dontselect=0",form.ccmonth,"Please select the expiration month of your Credit Card.")==false) {
form.ccmonth.focus();return false;
}
if (V2validateData("dontselect=0",form.ccyear,"Please select the expiration year of your Credit Card.")==false) {
form.ccyear.focus();return false;
}
if (V2validateData("dontselect=0",form.cardtype,"Please select the type of your Credit Card.")==false) {
form.cardtype.focus();return false;
}
if (V2validateData("req",form.bankname,"Please enter the name of the Credit Card issuing bank.")==false) {
form.bankname.focus();return false;
}
if (V2validateData("req",form.bankphone,"Please enter the phone number of the Credit Card issuing bank.")==false) {
form.bankphone.focus();return false;
}
if (V2validateData("req",form.domain,"Please enter the primary domain for your server.")==false) {
form.domain.focus();return false;
}
if (V2validateData("regexp=^.*\\..{2,10}$",form.domain,"The domain name is not valid.")==false) {
form.domain.focus();return false;
}
if (V2validateData("dontselect=1",form.AgreeToPolicies,"You have to agree with our policies to place an order.")==false) {
form.AgreeToPolicies.focus();return false;
}

}



