<!-- // Hide

/****************************
Jeff Hoffmann
Site Design Dept.
10-02-2003
Script for I-store cart form
*****************************/


function validateQuote(){
	var quoteError = 'There was a problem building the quote:\n\n';
	var valid = true;

	for (j=0; j<document.quote.elements.length; j++){
		if(document.quote.elements[j].type == 'text' && document.quote.elements[j].value == ''){
			document.quote.elements[j].style.backgroundColor = "#ffcccc";
			quoteError += document.quote.elements[j].name+' was empty\n';
			valid = false;
		}
	}

	if (document.quote.state.options[document.quote.state.selectedIndex].value == '0'){
			document.quote.state.options[document.quote.state.selectedIndex].style.backgroundColor = "#ffcccc";
			quoteError += 'a state was not chosen\n';
			valid = false;
	}
	else if ((document.quote.state.options[document.quote.state.selectedIndex].text == 'Non US' && document.quote.country.options[document.quote.country.selectedIndex].value == 'US') || (document.quote.state.options[document.quote.state.selectedIndex].text != 'Non US' && document.quote.country.options[document.quote.country.selectedIndex].value != 'US')){
			document.quote.state.options[document.quote.state.selectedIndex].style.backgroundColor = "#ffcccc";
			document.quote.country.options[document.quote.country.selectedIndex].style.backgroundColor = "#ffcccc";
			quoteError += 'state and country choices do not match\n';
			valid = false;
	}

	if (!emailCheck(document.quote.customer_email.value)){
		document.quote.customer_email.style.backgroundColor = "#ffcccc";
		quoteError += 'customer email address is not valid\n';
		valid = false;		
	}
	if (!emailCheck(document.quote.rep_email.value)){
		document.quote.rep_email.style.backgroundColor = "#ffcccc";
		quoteError += 'rep email address is not valid\n';
		valid = false;		
	}
	if (!emailCheck(document.quote.manager_email.value)){
		document.quote.manager_email.style.backgroundColor = "#ffcccc";
		quoteError += 'manager email address is not valid\n';
		valid = false;		
	}


	document.quote.order_id.value = oid;
	document.quote.products.value = theseProducts;
	document.quote.multi_insert_link.value = ReturnLink();

	for (c=0; c<window.document.quote.elements.length; c++){
		if(window.document.quote.elements[c].name.indexOf("rep_") != -1 || window.document.quote.elements[c].name.indexOf("manager_") != -1){
			SetCookie(window.document.quote.elements[c].name, window.document.quote.elements[c].value);
		}
	}



	if (valid){
		return true;
	}
	else{
		alert(quoteError);
		return false;
	}
}

function emailCheck(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at)
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   //alert("Invalid E-mail ID");
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   //alert("Invalid E-mail ID");
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    //alert("Invalid E-mail ID");
	    return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    //alert("Invalid E-mail ID");
	    return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    //alert("Invalid E-mail ID");
	    return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    //alert("Invalid E-mail ID");
	    return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
	    //alert("Invalid E-mail ID");
	    return false;
	 }

 	 return true;
}


function LeadZeros(num){// make sure numbers are 3 digits.
	num = num.toString();
	var newNum = '';
	var shortZero = eval(3 - num.length);
	if (shortZero == 2){
		newNum = '00'+num;
	}
	else if (shortZero == 1){
		newNum = '0'+num;
	}
	else if (shortZero == 0){
		newNum = num;
	}

	return newNum;

}

function ReturnLink(){
	var sid = document.quote.site_id.value;

	var part1 = 'http://www.symantecstore.com/dr/sat/ec_MAIN.Master?p_name=SP&p_val=10034&p_name=PN&p_val=19&p_name=XID&p_val='+sid+'&PC1=-1&PC1=-1&PC2=-1&PC2=-1&PC3=-1&PC3=-1&PC4=-1&PC4=-1&PC5=-1&PC5=-1';
 	var part2 = '';

	var count = 1;

	for (k=0; k<vidArray.length; k++){
		numIteration = LeadZeros(count);
		part2 += '&p_name=multiinsert'+numIteration+'qty&p_val='+quoteQtyArray[k]+'&p_name=multiinsert'+numIteration+'vid&p_val='+vidArray[k];
		count++;
	}
	
	var url = part1+part2;
	return url;
}



// -->
