﻿function NextPage() {
var isSubmitOK

	isSubmitOK = true;

	if (validatefields()){
		currobj.action = "RequestSample.asp"
		if (currobj.currstepno.value=="1"){
			currobj.currstepno.value=2
		}else if (currobj.currstepno.value=="2"){
			if (document.preview.CardNumber){
				isSubmitOK = CheckCardNumber(document.preview);
			}
			if (isSubmitOK == true)	{ 
				currobj.action = "RequestSample.asp?done=1"			
				currobj.currstepno.value=3
			}
		}

		if (isSubmitOK == true)	{ 
			currobj.submit()
		}
	}
}

function DoCheckout(){
var formname = document.forms.preview;
var isSubmitOK

	isSubmitOK = false;

	if (formname.CardNumber.value != ''){
		isSubmitOK = CheckCardNumber(document.forms.preview);
		alert(isSubmitOK)
	}
}

function validatefields(){

	if (currobj.sample_fname){
		xval = trim_(currobj.sample_fname.value)
		if (xval.length <= 0) {
			currobj.sample_fname.focus()
			alert("Please enter first name")
			return false
		}
	}
	if (currobj.sample_lname){
		xval = trim_(currobj.sample_lname.value)
		if (xval.length <= 0) {
			currobj.sample_lname.focus()
			alert("Please enter last name")
			return false
		}
	}

	if (currobj.sample_company){
		xval = trim_(currobj.sample_company.value)
		if (xval.length <= 0) {
			currobj.sample_company.focus()
			alert("Please enter company name")
			return false
		}
	}

	if (currobj.sample_address1){
		xval = trim_(currobj.sample_address1.value)
		if (xval.length <= 0) {
			currobj.sample_address1.focus()
			alert("Please enter address")
			return false
		}
	}

	if (currobj.sample_city){
		xval = trim_(currobj.sample_city.value)
		if (xval.length <= 0) {
			currobj.sample_city.focus()
			alert("Please enter city")
			return false
		}
	}

	if (currobj.sample_state){
		xval = trim_(currobj.sample_state.value)
		if (xval.length <= 0) {
			currobj.sample_state.focus()
			alert("Please enter state")
			return false
		}
		//var statenames=',AK,AL,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY,'
		//if (statenames.indexOf(',' + xval.toUpperCase() + ',')<0){
		//	currobj.sample_state.focus()
		//	alert("Please enter correct state")
		//	return false
		//}
	}
	if (currobj.sample_zip){
		xval = trim_(currobj.sample_zip.value)
		if (xval.length <= 0) {
			currobj.sample_zip.focus()
			alert("Please enter zipcode")
			return false
		}
	}
	if (currobj.sample_country){
		xval = trim_(currobj.sample_country.value)
		if (xval.length <= 0) {
			currobj.sample_country.focus()
			alert("Please enter country")
			return false
		}
	}
	if (currobj.sample_phone){
		xval = trim_(currobj.sample_phone.value)
		if (xval.length < 7) {
			currobj.sample_phone.focus()
			alert("Please enter phone number")
			return false
		}
	}

	if (currobj.sample_email){
		xval = trim_(currobj.sample_email.value)
		if (xval.length <= 0) {
			currobj.sample_email.focus()
			alert("Please enter email address")
			return false
		}
		if (xval.indexOf("@") <=0 || xval.length <= 4) {
			currobj.sample_email.focus()
			alert("Please entrer valid email address")
			return false
		}
	}

	if (currobj.cc_name){
		xval = trim_(currobj.cc_name.value)
		if (xval.length < 10) {
			currobj.cc_name.focus()
			alert("Please enter name on card")
			return false
		}
	}

	return true
}

function trim_(ystr) {
	var xfound = false
	if (ystr.length == 0) return ""
	for (var k=0; k<ystr.length;k++) {
		if (!xfound) {
			if (ystr.charAt(k) == " ") {
			}
			else {
				ystr = ystr.substring(k, ystr.length)
				xfound = true
				break
			}
		}
	}
	if (!xfound) ystr = ""
	
	xfound = false
	if (ystr.length == 0) return ""
	for (k=ystr.length-1; k>=0;k--) {
		if (!xfound) {
			if (ystr.charAt(k) == " ") {
			}
			else {
				ystr = ystr.substring(0, k+1)
				xfound = true
				break
			}
		}
	}
	if (!xfound) ystr = ""
	return ystr
}

var activerow = new DefineActiveRowProp();

function DefineActiveRowProp() {
	this.whattoident = null;
	this.otherident = null;
	this.whatfeatures = null;
	this.howmany = null;
	this.typsample = null;
	this.ratefactors1 = null;
	this.ratefactors2 = null;
	this.ratefactors3 = null;
	this.ratefactors4 = null;
	this.ratefactors5 = null;
	this.ratefactors6 = null;
	this.ratefactors7 = null;
	this.whereshop = null;
	this.othershop = null;
	this.itemspurchase = null;
	this.similarbuy = null;
	this.whichcomp = null;
	this.remarkscsr = null;
}

function trClickRadio (row, rn, buttonName, divName) {
var objtype='rad'

	if (activerow[buttonName.split(objtype).join('')]) {
		activerow[buttonName.split(objtype).join('')].bgColor = '#FFFFFF';
	}
	activerow[buttonName.split(objtype).join('')] = row;
	activerow[buttonName.split(objtype).join('')].bgColor = '#E8E3D9';

	for (var i=0;i<currobj[buttonName].length;i++) {
		if (GetElement(divName+i)) { 
			GetElement(divName+i).style.fontWeight="normal";
		}
	}
	
	if (GetElement(divName+rn)) {
		if (typeof(currobj[buttonName])!="undefined" && currobj[buttonName].length>1){
			currobj[buttonName][rn].checked=true;
			currobj[buttonName][rn].click();
			GetElement(divName+rn).style.fontWeight="bold";
		}else{
			currobj[buttonName].checked=true;
			currobj[buttonName].click();
			GetElement(divName+rn).style.fontWeight="bold";
		}
	}	
}

