﻿		
		/*Modal Triggers*/
		$().ready(function() {
			$('#TAF, #RAQ').jqm();
			$('#TAF').jqmAddTrigger('#TAFlink');
			$('#RAQ').jqmAddTrigger('#RAQlink');
		});

		function TAF_send(){
			var spc_request, brand, division, from_name, from_email, to_name, to_email, message, description, image, category, linkpath, site, site_bkgd, logo, cls_phone, subject, thank_message, bcc_name, bcc_email, typed_captcha, cookie_captcha
			var TAF_form = document.form_TAF;
			
			//reset all the error messages
			TAF_reset();
			
			spc_request = TAF_form.request.value;
			brand = TAF_form.TAF_brand.value;
			division = TAF_form.TAF_division.value;
			from_name = TAF_form.form_your_name.value;
			from_email = TAF_form.form_your_email.value;
			to_name = TAF_form.form_send_name.value;
			to_email = TAF_form.form_send_email.value;
			
			message = TAF_form.form_message.value;
			description = TAF_form.TAF_description.value;
			image = 'http://www.clsmith.com'+TAF_form.TAF_image.value;
			category = TAF_form.TAF_category.value;
			linkpath = TAF_form.TAF_path.value;
			
			if (brand == 'cls')
			{
				site = 'CLSmith.com';
				site_bkgd = 'tellafriend_topheader.jpg';
				logo = '<img src="http://www.clsmith.com/images/logo_cls.jpg" alt="C.L. Smith Company">';
				cls_phone = '800-264-1202';
				subject = 'CLSmith.com - Website Quote Request';
				thank_message = '';
			}
			
			if ((brand == 'cls') && (division == 'hazplus'))
			{
				site = 'CLSmith.com/HAZPlus';
				site_bkgd = 'hazplus_taf_topheader.jpg';
				logo = '<img src="http://www.clsmith.com/images/logo_haz.jpg" alt="HAZPLUS a division of C.L. Smith">';
				cls_phone = '1-866-596-6786';
				subject = 'HazPlus / CLSmith.com - Website Quote Request';
				thank_message = '';
			}
			
			if (brand == 'n2it')
			{
				site = 'N2itContainers.com';
				site_bkgd = 'n2it_taf_topheader.jpg';
				logo = '<img src="http://www.clsmith.com/images/logo_n2it" alt="N2it Containers">';
				cls_phone = '1-866-596-6786';
				subject = 'N2itcontainers.com - Tell A Friend';
				thank_message = '';
			} 
			
			from_name = from_name.replace(/ /g,'%20').replace(/&/g, '%26');
			to_name = to_name.replace(/ /g,'%20').replace(/&/g, '%26');
			subject = subject.replace(/ /g,'%20').replace(/&/g, '%26');
			
			message = '<head><!DOCTYPE html PUBLIC"-//W3C//DTDXHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><title>'+site+' Tell A Friend</title><meta http-equiv="Content-Type" content="text/html;charset=utf-8"/></head><body bgColor=#ffffff style="margin:0px; padding:0px" background="http://www.clsmith.com/images/bkgd_TAF_body.jpg"><style type="text/css">a{color:#ffffff;text-decoration:none;}a:hover{text-decoration:underline;}</style><table border="0" cellspacing="0" cellpadding="0" width="550" align="center"><tr><td width="550" style="border:#333333 1px solid;"><table border="0" cellspacing="0" cellpadding="0" width="550" align="center"><tr><td width="550"><img style="display:block" alt="C.L.Smith" src="http://www.clsmith.com/images/'+site_bkgd+'" height="158" width="550"/></td></tr><tr><td height="15" width="550" style="background-color:#EEEDE8;"></td></tr><tr><td align="center" style="background-color:#EEEDE8;"><table border="0" cellspacing="0" cellpadding="10" width="520" align="center" style="background-color:#ffffff;"><tr><td width="520" colspan="2"><p style="text-align:left;FONT-FAMILY:Arial,Helvetica,sans-serif;font-weight:bold;font-size:12px;color:#333333;">Information about the following product at '+site+' was sent by: '+from_name+' ('+from_email+')</p></td></tr><tr><td width="140"><img src="'+image+'" alt="'+description+'" title="'+description+'" height="100" width="100"></td><td width="380" align="left" valign="top"><p style="text-align:left;FONT-FAMILY:Arial,Helvetica,sans-serif;font-weight:bold;font-size:18px;color:#333333;">'+category+' > '+description+'</p><p>'+linkpath+'</p></td></tr><tr><td width="520" align="left" valign="top" colspan="2"><p style="text-align:left;FONT-FAMILY:Arial,Helvetica,sans-serif;font-weight:bold;font-size:18px;color:#676767;">Message from '+from_name+':</p><p style="text-align:left;FONT-FAMILY:Arial,Helvetica,sans-serif;font-weight:bold;font-size:12px;color:#333333;background-color:#fff;">'+message+'</p></td></tr></table></td><tr><td height="15" width="550"></td></tr></table></td></tr></table></body>';
			message = message.replace(/ /g,'%20').replace(/&/g, '%26').replace(/"/g, '%22').replace(/</, '%3C').replace(/>/g, '%3E').replace(/:/g, '%3A');
			
			bcc_name = 'Ellen Mughal';
			bcc_email = 'emughal@clsmith.com';
			
			typed_captcha = TAF_form.TAF_captcha_code.value;
			cookie_captcha = get_cookie ( "CapCode" );
			
			//filter for quick email validation
			var emailFilter = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; 
			//tests each field, works it's way down the form, success uses the ajax send email
			if ((from_name.length)>0) { 
				if (emailFilter.test(from_email)) { 
					if ((to_name.length)>0) { 
						if (emailFilter.test(to_email)) {
							if(typed_captcha.toLowerCase() == cookie_captcha.toLowerCase()){
								if(spc_request+'' == ''){
									$.post('/dis/ajax_send_email.asp','from_name='+from_name+'&from_email='+from_email+'&to_name='+to_name+'&to_email='+to_email+'&subject='+subject+'&message='+message+'&bcc_name='+bcc_name+'&bcc_email='+bcc_email+'&typed_captcha='+typed_captcha+'&cookie_captcha='+cookie_captcha,TAF_success());
								}
							} else {
								document.getElementById('TAF_captcha_error').style.display = "block";
								document.getElementById('TAF_captcha').src = document.getElementById('captcha').src + '?' + (new Date()).getMilliseconds();
								document.getElementById('TAF_captcha_code').value = '';
							}
						} else {
							document.getElementById('TAF_valid_semail1').style.display = 'block';
						}
					} else {
						document.getElementById('TAF_valid_sname').style.display = 'block';
					}
				} else { 
					document.getElementById('TAF_valid_remail1').style.display = 'block';
				} 
			} else {
				document.getElementById('TAF_valid_rname').style.display = 'block';
			}
			return false 
		}
		function TAF_success(){	
			$('#TAF').jqmHide();
			$('#TAF_send_pop').jqm();
			$('#TAF_send_pop').jqmShow();
		}
		function TAF_reset(full_clear){
			document.getElementById('TAF_valid_rname').style.display = 'none';
			document.getElementById('TAF_valid_remail1').style.display = 'none';
			document.getElementById('TAF_valid_sname').style.display = 'none';
			document.getElementById('TAF_valid_semail1').style.display = 'none';
			document.getElementById('TAF_valid_semail1').style.display = 'none';
			if (full_clear == 'yes') {
				document.getElementById('form_your_name').value = '';
				document.getElementById('form_your_email').value = '';
				document.getElementById('form_send_name').value = '';
				document.getElementById('form_send_email').value = '';
				document.getElementById('form_message').value = '';
			}
		}
		
//----------------------------------------------------------------------------//
		function goText() {
			window.open("/dis/image_verification.asp", "ImageText","width=400,height=355,toolbar=0,menubar=0,scrollbars=0,resizable=0"); 
		}

		function RAQ_send(inDivision){
			var from_name, from_email, to_name, to_email, subject, message, bcc_name, bcc_email, description, typed_captcha, cookie_captcha;
			var thank_message, site, category, linkpath, telephone, company, att_count, text, quantity, address, logo, security, spc_request, brand, division;
			var RAQ_form = document.form_RAQ;
			
			RAQ_reset();
			
			spc_request = RAQ_form.request.value;
			brand = RAQ_form.RAQ_brand.value;
			division = RAQ_form.RAQ_division.value;
			
			from_name = RAQ_form.form_your_name.value;
			from_name = from_name.replace(/ /g,'%20').replace(/&/g, '%26');
			from_email = RAQ_form.form_your_email.value;
			telephone = RAQ_form.form_telephone.value;
			company = RAQ_form.form_company.value;
			address = RAQ_form.RAQ_address.value;
			address = address.replace(/ /g,'%20').replace(/&/g, '%26');
			
			if (brand == 'cls')
			{
				to_name = 'Customer Service - Request a Quote';
				to_email = 'service@clsmith.com';
				site = 'CLSmith';
				logo = '<img src="http://www.clsmith.com/images/logocls_small.jpg" alt="C.L. Smith Company">';
				cls_phone = '800-264-1202';
				subject = 'CLSmith.com - Website Quote Request';
				thank_message = 'Thank you for submitting a quote request through our website.<BR><BR>One of our Packaging Consultants will contact you shortly.<BR><BR>We appreciate the opportunity to meet your packaging needs.<br><br>'+logo+'<br>'+cls_phone+'<br>www.clsmith.com<br>';
			}
			
			if ((brand == 'cls') && (division == 'hazplus'))
			{
				to_name = 'Customer Service - Request a Quote';
				to_email = 'info_request@hazplus.com';
				site = 'CLSmith.com/hazplus';
				cls_phone = '1-866-596-6786';
				subject = 'HazPlus / CLSmith.com - Website Quote Request';
				logo = '<img src="http://www.clsmith.com/images/logohaz_small.jpg" alt="HAZPLUS a division of C.L. Smith">';
				thank_message = 'Thank you for submitting a quote request through our website.<BR><BR>One of our Hazardous Materials Packaging Consultants will contact you shortly.<BR><BR>We appreciate the opportunity to meet your packaging needs.<br><br>'+logo+'<br>'+cls_phone+'<br>www.clsmith.com/hazplus<br>';
			}
			
			if (brand == 'n2it')
			{
				to_name = 'Customer Service - Request a Quote';
				to_email = 'n2itsales@n2itcontainers.com';
				site = 'N2it Containers';
				cls_phone = '1-866-596-6786';
				subject = 'N2itcontainers.com - Website Quote Request';
				logo = '<img src="http://www.clsmith.com/images/logon2it_small.jpg" alt="N2it Containers">';
				thank_message = 'Thank you for submitting a quote request through our website.<BR><BR>One of our Packaging Consultants will contact you shortly.<BR><BR>We appreciate the opportunity to meet your packaging needs.<br><br>'+logo+'<br>'+cls_phone+'<br>www.n2itcontainers.com<br>';
			} 
			
			subject = subject.replace(/ /g,'%20').replace(/&/g, '%26');
			to_name = to_name.replace(/ /g,'%20').replace(/&/g, '%26');
			thank_message = thank_message.replace(/ /g,'%20').replace(/&/g, '%26').replace(/"/g, '%22').replace(/</, '%3C').replace(/>/g, '%3E').replace(/:/g, '%3A');
			
			text = RAQ_form.RAQ_text.value;
			description = RAQ_form.RAQ_description.value;
			category = RAQ_form.RAQ_category.value;
			linkpath = RAQ_form.RAQ_path.value;
			quantity = RAQ_form.form_quantity.value;
			att_count = RAQ_form.RAQ_att_count.value;
			security = RAQ_form.RAQ_security.value; 
			bcc_name = '';
			bcc_email = '';
			
			message = 'Product:'+category+' > '+description+'<br>'+ linkpath +'<BR><BR><BR>=== Contact Information ===<br><br>Name: '+from_name+'<br>Email: '+from_email+'<br>Telephone: '+telephone+'<br>Company: '+company+'<br>Address: '+address+'<br><br>=== Product Information ===<br><br>Quantity: '+quantity+'<br>Product: '+description+'<br>';
			var i=0;
			if(parseInt(att_count) > 0){
				for (i=0;i<=att_count;i++)
				{
					message = message + document.getElementById('RAQ_att_lbl'+i).innerHTML+' '+document.getElementById('form_att_'+i).value+'<br>';
				}
			}
			message = message + 'Additional Details:<br>'+ text+'<br>IP Address: '+security;
			
			message = message.replace(/ /g,'%20').replace(/&/g, '%26').replace(/"/g, '%22').replace(/</, '%3C').replace(/>/g, '%3E').replace(/:/g, '%3A');
			
			typed_captcha = RAQ_form.RAQ_captcha_code.value;
			cookie_captcha = get_cookie ( "CapCode" );
			
			if(typed_captcha.toLowerCase() == cookie_captcha.toLowerCase()){
				if(spc_request+'' == ''){
					//Activate for Testing
					//to_email = 'ryan.burch@deckis.com';
					
					//request
					$.post('/dis/ajax_send_email.asp','from_name='+from_name+'&from_email='+from_email+'&to_name='+to_name+'&to_email='+to_email+'&subject='+subject+'&message='+message+'&bcc_name='+bcc_name+'&bcc_email='+bcc_email+ '&typed_captcha=' + typed_captcha+ '&cookie_captcha=' + cookie_captcha,RAQ_success());
					//auto response
					$.post('/dis/ajax_send_email.asp','from_name='+site+'&from_email='+to_email+'&to_name='+from_name+'&to_email='+from_email+'&subject='+subject+'&message='+thank_message+'&bcc_name=&bcc_email=&typed_captcha=' + typed_captcha+ '&cookie_captcha=' + cookie_captcha);
				}
			} else {
				document.getElementById('RAQ_captcha_error').style.display = "block";
				document.getElementById('RAQ_captcha').src = document.getElementById('RAQ_captcha').src + '?' + (new Date()).getMilliseconds();
				document.getElementById('RAQ_captcha_code').style.display = '';
			}
			return false 
		}
		
		function RAQ_success(){	
			$('#RAQ').jqmHide();
			$('#RAQ_send_pop').jqm();
			$('#RAQ_send_pop').jqmShow();
		}
		function RAQ_reset(full_clear){
			document.getElementById('RAQ_captcha_error').style.display = 'none';
		}
		
		function RAQ_popup(inInnerHTML){
			document.getElementById('RAQ_popup_inner').innerHTML = inInnerHTML;
			document.getElementById('RAQ_popup').style.display = 'block';
		}
		function RAQ_popup_close(){
			document.getElementById('RAQ_popup_inner').innerHTML = '';
			document.getElementById('RAQ_popup').style.display = 'none';
		}
		
//----------------------------------------------------------------------------//	
		
		function LimitMsg( inLen, inVar, inCounter )
		{
			var ct, ct2;
			ct = document.getElementById(inVar);
			counter = document.getElementById(inCounter);
			if((ct) && (counter))
			{
				if(ct.value.length >= inLen)
					ct.value = ct.value.substring(0, inLen);
				
				counter.innerHTML = ct.value.length;
			}
		}
		
		function get_cookie ( cookie_name )
		{
		  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
		
		  if ( results )
		    return ( unescape ( results[2] ) );
		  else
		    return null;
		}
		
		function chkObject(inParent,theVal) {
			if(inParent){
				if (window.opener.document.getElementById(theVal) != null) {
					return true;
				} else {
					return false;
				}
			}else{
				if (document.getElementById(theVal) != null) {
					return true;
				} else {
					return false;
				}
			}
		}
