// JavaScript Document
function checkForm(currForm){
	var errorMsg = "";
	var errObj;
	
	// Puppy Details
	if ($F('BREED')=='0') {
		errorMsg += errorPrefix + "Please select the Breed from the list."; 
		if(!errObj)errObj = $('BREED');
	}
	if (trim($F('FIRST_NAME')).length==0) {
		errorMsg += errorPrefix + "Please enter your First Name."; 
		if(!errObj)errObj = $('FIRST_NAME');
	}
	if (trim($F('LAST_NAME')).length==0) {
		errorMsg += errorPrefix + "Please enter your Last Name."; 
		if(!errObj)errObj = $('LAST_NAME');
	}
	if (trim($F('EMAIL')).length==0) {
		errorMsg += errorPrefix + "Please enter a valid email address."; 
		if(!errObj)errObj = $('EMAIL');
	} else {
		if (!isValidEmailAddress(trim($F('EMAIL')))){
			errorMsg += errorPrefix + "Email is not valid."; 
			if(!errObj)errObj = $('EMAIL');
		}
	}
	var areacode = trim($F('BEST_PHONE1'));
	if (areacode.length<3||trim($F('BEST_PHONE2')).length<3||trim($F('BEST_PHONE3')).length<4) {
		errorMsg += errorPrefix + "Please enter a valid US telephone number including your area code."; 
		if(!errObj)errObj = $('BEST_PHONE1');
	} else {
		if (areacode=='000'||areacode=='111'||areacode=='222'||areacode=='333'||areacode=='444'||areacode=='555'||areacode=='666'||areacode=='777'||areacode=='999'||areacode=='123')
			errorMsg += errorPrefix + "Please enter a valid US telephone number including your area code."; 
			if(!errObj)errObj = $('BEST_PHONE1');
	}
		
	if($('campaign')) {readGAData(currForm);}
	
	// msg if errors , otherwise submit
	if (errorMsg.length>0) {
		alert(errorHeader + errorMsg);
		if(errObj.type=='text') errObj.select(); else errObj.focus();
	}
	return (errorMsg.length==0);
}

function readGAData(obj){
   var z = _uGCn(document.cookie, '__utmz=', ';');

   var source     = _uGCn(z, 'utmcsr=', '|');
   var medium     = _uGCn(z, 'utmcmd=', '|');
   var term       = _uGCn(z, 'utmctr=', '|');
   var content    = _uGCn(z, 'utmcct=', '|');
   var campaign   = _uGCn(z, 'utmccn=', '|');
   var gclid      = _uGCn(z, 'utmgclid=', '|');

   if (gclid !="-") {
       source = 'google';
       medium = 'cpc';
   }

   obj['source'].value = decodeURI(source);
   obj['medium'].value = decodeURI(medium);
   obj['term'].value = decodeURI(term);
   obj['content'].value = decodeURI(content);
   obj['campaign'].value = decodeURI(campaign);
}

function _uGCn(l, n, s) {
   if (!l || l=="" || !n || n=="" || !s || s=="") return "-";
   var i, i2, i3, c="-";
   i = l.indexOf(n);
   i3 = n.indexOf("=")+1;
   if (i > -1) {
      i2=l.indexOf(s,i); if (i2 < 0) { i2=l.length; }
      c=l.substring((i+i3),i2);
   }
   return c;
}

