// ***************************** MOTOROLA VALIDATION BEGINS HERE *********************************
function selectManu(type){
	for(var s=0;s<document.recycleform.manufacturer.length;s++)
		if(document.recycleform.manufacturer[s].value == type)
		document.recycleform.manufacturer[s].selected = true ;
}
function selectModel(type){
	for(var s=0;s<document.recycleform.model.length;s++)
		if(document.recycleform.model[s].value == type)
		document.recycleform.model[s].selected = true ; 
}
function selectState(type){
	for(var s=0;s<document.recycleform.selState.length;s++)
		if(document.recycleform.selState[s].value == type)
		document.recycleform.selState[s].selected = true ; 
}
function selectCountry(type){
	for(var s=0;s<document.recycleform.selCountry.length;s++)
		if(document.recycleform.selCountry[s].value == type)
		document.recycleform.selCountry[s].selected = true ; 
}
function ValidateCustDetails(recycleform) {

    if (recycleform.txtFName.value == '') {
		alert("Please Enter First Name.");
		 
		recycleform.txtFName.focus();
		return false ;
	}
	if (recycleform.txtLName.value == '') {
		alert("Please Enter Last Name.");
		recycleform.txtLName.focus();
		return false ;
	}
	if (recycleform.txtAdd1.value == '') {
		alert("Please Enter Address.");
		recycleform.txtAdd1.focus();
		return false ;
	}
	if (recycleform.txtCity.value == '') {
		alert("Please Enter City.");
		recycleform.txtCity.focus();
		return false ;
	}
	 
	if (recycleform.selState.value == '') {
		alert("Please Select State.");
		recycleform.selState.focus();
		return false ;
	}
	if (recycleform.txtZip.value == '') {
		alert("Please Enter Zip Code.");
		recycleform.txtZip.focus();
		return false ;
	}
	if (recycleform.selCountry.value == '') {
		alert("Please Select Country.");
		recycleform.selCountry.focus();
		return false ;
	}
	if (recycleform.txtPhone.value == '') {
		alert("Please Enter Phone.");
		recycleform.txtPhone.focus();
		return false ;
	}
	if ((recycleform.txtPhone.value != '') && (!isPhoneOK(recycleform.txtPhone.value))) {
		alert("Please check the Phone Number");
		recycleform.txtPhone.focus();
		return false ;
	}
	if (recycleform.txtEmail.value == '') {
		alert("Please Enter E-Mail Address.");
		recycleform.txtEmail.focus();
		return false ;
	}
	if ((recycleform.txtEmail.value != '') && (!isEmailOK(recycleform.txtEmail.value))) {
		alert("Please check the Email Address");
		recycleform.txtEmail.focus();
		return false ;
	}
	if (recycleform.year.value == '') {
		alert("Please Select Year.");
		recycleform.year.focus();
		return false ;
	}
	return true ;
}
function isEmailOK(usrInput){
	var rXP = new RegExp("^\\w+([-.]\\w+)?[@]\\w+([-.]\\w+)*([.][a-zA-Z]+)$")
	if(rXP.test(usrInput))
		{return true}
	else
		{return false}
}
function isPhoneOK(usrInput){
	var rXP = new RegExp("\\(?\\d{3,5}\\)?\\s?[-\\/]\\s?(\\d{4,7})$")
	if(rXP.test(usrInput))
		{return true}
	else
		{return false}
}
function formatPhoneNumber(txtObj){
	var txtVal ;
	txtVal = txtObj.value ;
	if (txtVal.length == 3){ txtObj.value = txtVal + '-' } ;
	if (txtVal.length == 7){ txtObj.value = txtVal + '-' } ;
}

// ***************************** Motorola VALIDATION ENDS HERE  *********************************

// ***************************** Virgin Mobile VALIDATION ENDS HERE  ********************************* 

var msgtop = 190 // Set the top position of the div
var msgleft = 380 // Set the left position of the div 
var tborder = "0"
var cspace = "0"
var cpad = "0"
var tabheight = 20 // Set the height of table
var tabwidth = 350 // Set the width of table
var td1height = 20
var td2height = 100
var boxt = ""
function Domsg(flag) {
    hidebox() // Hide the box after clicking on text link in box
    if (flag == "Yes") {
        document.location = "http://www.virginmobileusa.com";
    }
    else {
        document.location = "http://www.virginmobileusa.com";
    }
}


function y2k(number) { return (number < 1900) ? number + 1900 : number; }


function isDate(day, month, year) {
    var today = new Date();
    year = ((!year) ? y2k(today.getYear()) : year);
    month = ((!month) ? today.getMonth() : month - 1);
    if (!day) return false
    var test = new Date(year, month, day);
    if ((y2k(test.getYear()) == year) &&
    (month == test.getMonth()) &&
    (day == test.getDate()))
        return true;
    else
        return false;
}

function getMonthLength(month, year, julianFlag) {
    var ml;
    if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)


    { ml = 31; }


    else {


        if (month == 2) {
            ml = 28;
            if (!(year % 4) && (julianFlag == 1 || year % 100 || !(year % 400)))
                ml++;
        }
        else


        { ml = 30; }
    }
    return ml;
}


function CheckAge(recycleform) {
    var myLimit = 13;

    // Get Current Date
    Today = new Date();
    var yd = Today.getYear();
    var md = Today.getMonth();
    var dd = Today.getDate();

    //check for year on case netscape browser

    if (yd < 1900) {
        yd = yd + 1900;
    }
    // Get Date from the form
    //var birthDate = document.pdfForm.txtAge.value;
    //birthDate.substring(0,2)
    var mb = document.recycleform.month.options[document.recycleform.month.selectedIndex].value; //birthDate.substring(0,2); 
    var db = document.recycleform.date.options[document.recycleform.date.selectedIndex].value; //birthDate.substring(3,5); 
    var yb = document.recycleform.year.options[document.recycleform.year.selectedIndex].value; // birthDate.substring(6,10)
    MNames = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
            "Oct", "Nov", "Dec");


    if ((db == 0) ||
            (mb == 0) ||
            (yb == 0)) {
        alert("You must enter a valid date.");
        document.recycleform.month.focus();
        return false;
    }
    else {
        if (isDate(db, mb, yb) == false) {
            alert("You must enter a valid date");
            document.recycleform.txtAge.focus();
            return false;
        }
    }
    // Month length 0->use calendar length
    var mLength = 0;
    // 0 if Gregorian, 1 is Julian
    var isJulian = 1;
    var ma = 0;
    var ya = 0;
    var da = dd - db;
    // This is the all-important day borrowi
    //     ng code.
    if (da < 0) {
        md--;
        // Borrow months from the year if necess
        //     sary.
        if (md < 1) {
            yd--;
            // Determine no. of months in year
            if (mLength)
            { md = md + parseInt(365 / mLength); }
            else
            { md = md + 12; }
        }
        if (mLength == 0) // Use real month length if no fixed
        { // length is indicated - note that we add a leap day if necessary.
            ml = getMonthLength(md, yd, isJulian);
            da = da + ml;
        }
        // For this case, everything works like 
        //     it did in elementary school.
        else
        { da += mLength; } // Use fixed month length
    }
    ma = md - mb;
    // Month borrowing code - borrows months
    //     from years.
    if (ma < 0) {
        yd--;
        if (mLength != 0)
        { ma = ma + parseInt(365 / mLength); }
        else
        { ma = ma + 12; }
    }
    ya = yd - yb;
    // Find if you are over AgeLimit.
    if (ya >= myLimit) {
        return true;
    }
    else {
        //var theString;
        //theString="<h1>Hello</h1>" 
        //if (document.layers) // Netscape 4.0+
        //{
        //document.formbox.document.write(theString)
        //document.formbox.document.close()
        //document.formbox.left=msgleft
        //document.formbox.top=msgtop+40
        //document.formbox.visibility="show"
        //}
        //else
        //{
        var conn = confirm("Sorry, but registration cannot be accepted for customers under 13 years of age.\nYou may still print a shipping label and recycle your phone anonymously.\nClick OK to print your shipping label now.");
        if (conn == true) {
            document.recycleform.txtFName.value = "";
            document.recycleform.txtLName.value = "";
            document.recycleform.txtAdd1.value = "";
            document.recycleform.txtAdd2.value = "";
            document.recycleform.txtCity.value = "";
            document.recycleform.txtZip.value = "";
            document.recycleform.selState.value = "";
            document.recycleform.selCountry.value = "";
            document.recycleform.txtEmail.value = "";
            document.recycleform.month.value = "";
            document.recycleform.date.value = "";
            document.recycleform.year.value = "";
            document.location = "index.asp?actionMode=SaveAnonymous";
        }
        else {
            document.recycleform.txtFName.value = "";
            document.recycleform.txtLName.value = "";
            document.recycleform.txtAdd1.value = "";
            document.recycleform.txtAdd2.value = "";
            document.recycleform.txtCity.value = "";
            document.recycleform.txtZip.value = "";
            document.recycleform.selState.value = "";
            document.recycleform.selCountry.value = "";
            document.recycleform.txtEmail.value = "";
            document.recycleform.month.value = "";
            document.recycleform.date.value = "";
            document.recycleform.year.value = "";
            document.location = "http://www.virginmobileusa.com";
        }
        return false;
    }
}
//}  


function hidebox() {
    if (document.layers) // Netscape 4.0+
    {
        document.recycleform.visibility = "hidden"
    }
    if (document.getElementById) // Netscape 6.0+ and Internet Explorer 5.0+
    {
        document.getElementById("recycleform").style.visibility = "hidden"
    }
}      
                  
            




