//Disable right click script III- By Renigade 
//(renigade@mediaone.net) 
//For full source code, visit http://www.dynamicdrive.com 
var message=""; 
/////////////////////////////////// 
function clickIE() {if (document.all) {(message);return false;}} 
function clickNS(e) {if  
(document.layers||(document.getElementById&&!document.all)) { 
if (e.which==2||e.which==3) {(message);return false;}}} 
if (document.layers)  
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;} 
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;} 

document.oncontextmenu=new Function("return false") 

function showfile(file,prodid,inv)
{
var left = (screen.width-430)/2;
var top = 140;
var winShow = window.open("large_photo.asp?file="+ file + "&prodid=" + prodid + "&ssl_invoice_number=" + inv, "LargePhotos","height=100,width=100,left=0,top=0,toolbar=0,status=0");
winShow.focus();
}

function setbilling()
{
document.user.BillingAddress.value=document.user.Address.value;
document.user.BillingCity.value=document.user.City.value;
document.user.BillingState.value=document.user.State.value;
document.user.BillingZipCode.value = document.user.ZipCode.value;
document.user.BillingPhone.value=document.user.Phone.value;
document.user.Phone.focus();
}

//view cart

function removeitem(frm,Cnt,invNum,query)
{
if(confirm('You are about to remove [ ' + document[frm].Product.value + ' ] from the cart\nTo continue click "OK"\nTo stop now click "Cancel"'))
    {
    document[frm].action='removeitem.asp?cnt=' + Cnt + '&ssl_invoice_number=' + invNum + '&invitemid=' + document[frm].id.value + '&query=' + query;
    document[frm].submit();
    }
}

function valItem(frm)
{
if(document[frm].action=='default.asp?query=email_notification' || document[frm].action=='email_notification.asp')
    {
        if(document[frm].email.value=='enter email address')
            {
            alert('invalid email address');
            return false;
            }
        if(document[frm].email.value=='')
            {
            alert('invalid email address');
            return false;
            }
    }

var ValidChars = "0123456789.";
var IsNumber=true;
var Char;
sText = document[frm].Quantity.value;

if(document[frm].Quantity.value=='')
    {
    alert('Invalid quantity');
    return false;
    }

for (i = 0; i < sText.length && IsNumber == true; i++)
{
    Char = sText.charAt(i);
    if (ValidChars.indexOf(Char) == -1)
        {
        IsNumber = false;
        }
}

if(IsNumber == false)
    {
    alert('Invalid quantity');
    return false;
    }
if(parseInt(document[frm].Quantity.value) < parseInt(document[frm].Minimum_Purchase.value))
{
alert('The minimum purchase for this item is ' + document[frm].Minimum_Purchase.value);
return false;
}
return true;
}

//checkout

function setbilling()
{
document.cart.ssl_company.value=document.cart.ssl_ship_to_company.value;
document.cart.ssl_first_name.value=document.cart.ssl_ship_to_first_name.value;
document.cart.ssl_last_name.value=document.cart.ssl_ship_to_last_name.value;
document.cart.ssl_avs_address.value=document.cart.ssl_ship_to_avs_address.value;
document.cart.ssl_city.value=document.cart.ssl_ship_to_city.value;
document.cart.ssl_state.value=document.cart.ssl_ship_to_state.value;
document.cart.ssl_avs_zip.value=document.cart.ssl_ship_to_avs_zip.value;
document.cart.ssl_phone.value=document.cart.ssl_ship_to_phone.value;
}

//Search form

function valSearchFrm()
{
if(document.searchfrm.searchtxt.value=='')
    {
    alert('Invalid search entry');
    return false;
    }
if(document.searchfrm.searchtxt.value=='search by keyword or item #')
    {
    alert('Invalid search entry');
    return false;
    }
return true;    
}

//E-Blast Submission
function valfrm()
{

var str  = trim(document.Contact.Email.value);
var strSubscriber = trim(document.Contact.Name.value);
var at ="@"
var dot ="."
var lat = str.indexOf(at)
var lstr = str.length
var ldot = str.indexOf(dot)

if(strSubscriber =='')
    {
    alert('Please enter your name');
    return false;
    }
if(document.Contact.Address.value=='')
    {
    alert('Please entry your address');
    return false;
    }
if(document.Contact.City.value=='')
    {
    alert('Please entry your City, State and Zip');
    return false;
    }
if(document.Contact.Phone.value=='')
    {
    alert('Please entry your phone number');
    return false;
    }
if(document.Contact.Email.value=='')
    {
    alert('Invalid Email Address');
    return false;
    }
if(document.Contact.Email.value=='enter email')
    {
    alert('Invalid Email Address');
    return false;
    }
if (str.indexOf(at)==-1)
    {
    alert("Invalid Email Address")
    return false
    }

if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
    {
    alert("Invalid Email Address")
    return false
    }

if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
    {
    alert("Invalid Email Address")
    return false
    }

if (str.indexOf(at,(lat+1))!=-1)
    {
    alert("Invalid Email Address")
    return false
    }

if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
    {
    alert("Invalid Email Address")
    return false
    }

if (str.indexOf(dot,(lat+2))==-1)
    {
    alert("Invalid Email Address")
    return false
    }
        
if (str.indexOf(" ")!=-1)
    {
    alert("Invalid Email Address")
    return false
    }

return true;    
}

function valcontactfrm()
{

var str  = trim(document.Contact.Email.value);
var strSubscriber = trim(document.Contact.ContactName.value);
var at ="@"
var dot ="."
var lat = str.indexOf(at)
var lstr = str.length
var ldot = str.indexOf(dot)

if(document.Contact.HowSoon.value=='')
    {
    alert('We need to know how soon you would like to be contacted.');
    return false;
    }
if(strSubscriber =='')
    {
    alert('Please enter your name');
    return false;
    }
if(document.Contact.Phone.value=='')
    {
    alert('Please entry your phone number');
    return false;
    }
if(document.Contact.AltPhone.value=='')
    {
    alert('Please entry your alternate phone number');
    return false;
    }
if(document.Contact.Email.value=='')
    {
    alert('Invalid Email Address');
    return false;
    }
if(document.Contact.Email.value=='enter email')
    {
    alert('Invalid Email Address');
    return false;
    }
if (str.indexOf(at)==-1)
    {
    alert("Invalid Email Address")
    return false
    }

if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
    {
    alert("Invalid Email Address")
    return false
    }

if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
    {
    alert("Invalid Email Address")
    return false
    }

if (str.indexOf(at,(lat+1))!=-1)
    {
    alert("Invalid Email Address")
    return false
    }

if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
    {
    alert("Invalid Email Address")
    return false
    }

if (str.indexOf(dot,(lat+2))==-1)
    {
    alert("Invalid Email Address")
    return false
    }
        
if (str.indexOf(" ")!=-1)
    {
    alert("Invalid Email Address")
    return false
    }

if(document.Contact.ZipCode.value=='')
    {
    alert('A zip code is required to help us find a contractor in your area.');
    return false;
    }

return true;    
}


function ValidateForm(){
    var emailID=document.frmSample.txtEmail
    
    if ((emailID.value==null)||(emailID.value=="")){
        alert("Please Enter your Email ID")
        emailID.focus()
        return false
    }
    if (echeck(emailID.value)==false){
        emailID.value=""
        emailID.focus()
        return false
    }
    return true
 }

function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
    return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
    return stringToTrim.replace(/\s+$/,"");
}

function imgswap(x,y)
{
if (document.images)
        document.images[x].src ='./images/' + y;
}

function valorder()
{

if(document.order.How.value =='' && document.order.Other.value=='')
    {
    alert('Please tell us how your heard about us')
    return false;
    }
if(IsEmpty(document.order.street,"Street  is required."))
    {return false;}
if(IsEmpty(document.order.city,"City is required."))
    {return false;}
if(IsEmpty(document.order.state,"State is required."))
    {return false;}
if(IsEmpty(document.order.zip,"Zip Code is required."))
    {return false;}
if(IsNotNumber(document.order.zip,"Please enter only digits for the zip code"))
    {return false;}
if(IsNotMaxLength(document.order.zip,5,"The zip code should be 5 digits long"))
    {return false;}

if(document.order.structures(0).checked==false && document.order.structures(1).checked==false)
    {
    alert('Please tell us how many structures are at this address');
    return false;
    }
if(document.order.additional(0).checked==false && document.order.additional(1).checked==false)
    {
    alert('Please tell us if there have been any additions or structural changes in the last three years');
    return false;
    }
    
if(confirm('If all the information you are about to submit is correct, click OK to continue or Cancel to stop.'))
    {
    return true;
    }
else
    {
    return false;
    }
}


function valOrderForm()
{
var d = new Date();

if(!document.checkout.verify.checked)
    {
    alert('If the address information is correct please check the box "Yes, this is the correct address"')
    return false;
    }

if(!document.checkout.approve.checked)
    {
    alert('To continue please check the box "By ordering you are agreeing to Measure My Roofs Terms & Conditions"')
    return false;
    }
    
if(IsEmpty(document.checkout.Email,"Please enter a valid email address."))
    {return false;}
if(IsEmpty(document.checkout.FirstName,"First Name is required."))
    {return false;}
if(IsEmpty(document.checkout.LastName,"Last Name is required."))
    {return false;}
if(IsEmpty(document.checkout.ssl_avs_address,"Address is required."))
    {return false;}
if(IsEmpty(document.checkout.ssl_city,"City is required."))
    {return false;}
if(IsEmpty(document.checkout.ssl_state,"State is required."))
    {return false;}
if(IsEmpty(document.checkout.ssl_avs_zip,"Zip Code is required."))
    {return false;}
if(IsNotNumber(document.checkout.ssl_avs_zip,"Please enter only digits for the zip code"))
    {return false;}
if(IsNotMaxLength(document.checkout.ssl_avs_zip,5,"The zip code should be 5 digits long"))
    {return false;}
if(IsEmpty(document.checkout.ssl_card_number,"Please enter a valid credit card number"))
    {return false;}
if(IsNotNumber(document.checkout.ssl_card_number,"Please enter only digits for the credit card number"))
    {return false;}
if(document.checkout.Month.value =='00')
    {
    alert("Select a vaild expiration month")
    return false;
    }
if(document.checkout.Year.value =='00')
    {
    alert("Please Select a vaild expiration year")
    return false;
    }


if(document.checkout.Year.value == d.getYear())
    {
        if(document.checkout.Month.value < d.getMonth())
        {
        alert("Your credit card has expired")
        return false;
        }
    }

if(confirm('You are about to submit your order to My Roof Measurements.\nTo continue click OK, To stop now click Cancel.'))
    {
    document.checkout.ssl_merchant_id.value='401800';
    document.checkout.ssl_pin.value='15V15V';
    //document.checkout.ssl_user_id.value='webpage';
    return true;
    }
else
    {
    return false;
    }
}

function PopWin(file)
{
var winShow = window.open(file , "PopupWin","height=" + screen.availheight + ",width=" + screen.availwidth + ",left=0,top=0,toolbar=0,status=0,resizable=yes,scrollbars=yes");
winShow.focus();
}

var state = 'none';

function showhide(layer_ref)
{

if (document.all)
    { //IS IE 4 or 5 (or 6 beta)
    state = document.all[layer_ref].style.display;
    if (state == 'block')
        {
        state = 'none';
        }
    else
        {
        state = 'block';
        }
    eval("document.all." + layer_ref + ".style.display = state");
    }
if (document.layers)
    { //IS NETSCAPE 4 or below

    state = document.layers[layer_ref].display;
    if (state == 'block')
        {
        state = 'none';
        }
    else
        {
        state = 'block';
        }
    document.layers[layer_ref].display = state;
    }
if (document.getElementById &&!document.all)
    {
    hza = document.getElementById(layer_ref);
    state = hza.style.display;
    if (state == 'block')
        {
        state = 'none';
        }
    else
        {
        state = 'block';
        }
    hza.style.display = state;
    }
}

function valreview()
{
if(document.reviewsubmit.Rating.value=='0')
    {
    alert('Please enter a rating to continue');
    return false;
    }

if(document.reviewsubmit.CustomerName.value=='')
    {
    alert('Please enter your name to continue');
    return false;
    }
    
if(document.reviewsubmit.ReviewTitle.value=='')
    {
    alert('Please enter a title for your review to continue');
    return false;
    }
    
if(document.reviewsubmit.Comments.value=='')
    {
    alert('Please enter comments to continue');
    return false;
    }
    
if(confirm('You are about to add your review of our services.\nTo continue click OK, To stop now click Cancel.'))
    {
    return true;
    }
else
    {
    return false;
    }
}

function ValPurchaseReview()
{
if(document.customerreview.Rating.value=='0')
    {
    alert('Please enter a rating to continue');
    return false;
    }

if(document.customerreview.CustomerName.value=='')
    {
    alert('Please enter your name to continue');
    return false;
    }

if(document.customerreview.Q1.value=='')
    {
    alert('Please answer question 1 to continue');
    return false;
    }
    
if(document.customerreview.Q2.value=='')
    {
    alert('Please answer question 2 to continue');
    return false;
    }

if(document.customerreview.Q3.value=='')
    {
    alert('Please answer question 1 to continue');
    return false;
    }
        
if(confirm('You are about to submit your review of our services.\nTo continue click OK, To stop now click Cancel.'))
    {
    return true;
    }
else
    {
    return false;
    }
}

function IsEmpty(textField,msg){
    var strValue=textField.value;
    for (var i = 0; i < strValue.length; i++)
    {
    var c = strValue.charAt(i);
    if ((c != ' ') && (c != '\n') && (c != '\t'))
    return false;
    }
    alert (msg);
    textField.focus();
    textField.select();
    return true;
}

function IsNotMaxLength(textField,maxlen,msg) {
  var strValue=textField.value;
  if (strValue.length < maxlen || strValue.length > maxlen) {
    alert (msg);
    textField.focus();
    textField.select();
    return true;
  }
  return false;
}

function IsNotSelected(textField,msg) 
{
  if (textField.options[0].selected) 
  {
    alert (msg);
    textField.focus();
    return true;
  }
  return false;
}

function IsNotNumber(textField,msg) 
{
  var digits = "0123456789";
  for (i=0; i<=textField.size; i++) 
  {
     if (digits.indexOf(textField.value.charAt(i))== -1) 
     {
       alert (msg);
       textField.focus();
       textField.select();
       return true;
     }
  }
  return false;
}

function IsNotValidAmount(textField,msg){
   var numValue=textField.value;
    if(isNaN(numValue))
    {
        alert (msg);
        textField.focus();
        textField.select();
        return true;
    }
    return false;
}

function fixDecimal(DecimalNum) {
 strNum = "" + DecimalNum;
 if (strNum.indexOf('.') == -1)
  return strNum + '.00';
 seperation = strNum.length - strNum.indexOf('.');
 if (seperation > 3)
  return strNum.substring(0,strNum.length-seperation+3);
 else if (seperation == 2)
  return strNum + '0';
 return strNum;
}
function fixAmount()
{
if (!isNaN(document.frmCCP.txtAmount.value))
   document.frmCCP.txtAmount.value=fixDecimal(document.frmCCP.txtAmount.value)
}
