// JavaScript Document
function echeck(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 makeBlank(val)
	{
		var trimmed = val.replace(/^\s+|\s+$/g, '') ;
		if(trimmed=='--Your Email--')
		{
			eval("document.getElementById('ea').value=''");
		}
	}
	function putValue(val)
	{
		var trimmed = val.replace(/^\s+|\s+$/g, '') ;
		
		if(trimmed=='')
		{
			eval("document.getElementById('ea').value='--Your Email--'");
		}	
		
	}
	
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage(id,imagename,tdid,istrue) { //v3.0
	if(istrue==0)
	{
		eval("document.getElementById('"+id+"').src='"+imagename+"'");
		if(tdid!='')
		{
			currentClass=eval("document.getElementById('"+tdid+"').className");
			if(currentClass=='black_back')
				eval("document.getElementById('"+tdid+"').className='white_back'");
			else
				eval("document.getElementById('"+tdid+"').className='black_back'");
		}
	}
}

function orderFormValidator()
{
	if($('#first_name').val()=='')
	{
		alert('First Name field can not be empty.');
		$('#first_name').focus();
		return false;
	}	
	if($('#last_name').val()=='')
	{
		alert('Last Name field can not be empty.');
		$('#last_name').focus();
		return false;
	}
	
	if($('#phone').val()=='')
	{
		alert('Phone field can not be empty.');
		$('#phone').focus();
		return false;
	}	
	if($('#company_name').val()=='')
	{
		alert('Enter your company name');
		$('#company_name').focus();
		return false;
	}
	if($('#address').val()=='')
	{
		alert('Please Enter your address');
		$('#address').focus();
		return false;
	}	
	
	if($('#city').val()=='')
	{
		alert('City field can not be empty.');
		$('#city').focus();
		return false;
	}	
	if($('#state').val()=='' && $('#stateOther').val=='')
	{
		alert('State field can not be empty.');
		$('#stateOther').focus();
		return false;
	}	
	if($('#zip').val()=='')
	{
		alert("Zip field can not be empty");
		$('#zip').focus();
		return false;
	}	
	if(!emailcheck($('#email').val()))
	{
		$('#email').focus();
		return false;
	}
	if($('#email').val()!=$('#email2').val())
	{
		alert("Please Re-enter your email address properly");
		$('#email2').focus();
		return false;
	}
	if($('#captchastring').val()=='')
	{
		alert('Please enter the security string as you see it');
		$('#captchastring').focus();
		return false;
	}
	
	return true;
}


function validateLink(theForm)
{
	if(theForm.inbound_url.value == "" || theForm.inbound_url.value == "http://")
	{
		alert("Please enter the URL of the page where you have posted a link to partsandpeople.com.");
		theForm.inbound_url.focus();
		return false;
	}
	if(theForm.outbound_url.value != "" && theForm.outbound_url.value != "http://" && theForm.inbound_url.value.substring(0,14) != theForm.outbound_url.value.substring(0,14))
	{
		alert("The page we link to must be on the same domain as the page where you've posted your link.");
		theForm.outbound_url.focus();
		return false;
	}
	if(theForm.security_code.value=='')
	{
		alert('Please enter the security code');
		theForm.security_code.focus();
		return false;
	}
	return true;
}

function comment_form_validator(theForm,urlto)
{
  var chkVal = document.getElementById('username').value;
  var prsVal = chkVal;
  if (chkVal == "")
  {
    alert("Please enter your name.");
    document.getElementById('username').focus();
    return (false);
  }

  var chkVal = document.getElementById('email').value;
  var prsVal = chkVal;
  if (chkVal == "" )
  {
    alert("Please enter your email address.");
    document.getElementById('email').focus();
    return (false);
  }
  if(!echeck(chkVal))
  {
	document.getElementById('email').focus();
    return (false);  	
  }
  var chkVal = document.getElementById('comments').value;
  var prsVal = chkVal;
  if (chkVal == "")
  {
    alert("Please enter your comments.");
    document.getElementById('comments').focus();
    return (false);
  }
  var chkVal = document.getElementById('security_code').value;
  var prsVal = chkVal;
  if (chkVal == "")
  {
    alert("Please enter your security code.");
    document.getElementById('security_code').focus();
    return (false);
  }
	document.getElementById('divCommentMsg').innerHTML='<strong>Please wait ...</strong>';
	$('#divCommentMsg').prepend='Loading...';
	$('#formCommentSubmit').ajaxSubmit({target:'#divCommentMsg' ,url:urlto}); 
	theForm.reset();
	return false;  
/*  queryString="Contact_Name="+theForm.Contact_Name.value+"&Contact_Email="+theForm.Contact_Email.value+"&Comments="+theForm.Comments.value+"&security_code="+theForm.security_code.value+"&articleID="+theForm.articleID.value;
  theForm.commentSubmit.value='Wait';
  theForm.commentSubmit.disabled=true;
  sendRequest('http://www.turbolution.com/Clients/partsandpeople/test_server/ajaxExecutable/add_comment.php', queryString, 'divCommentMsg','Post','resetForm');
*/  return (false);
}

function email_form_validator(theForm,urlto)
{

  var chkVal = theForm.Contact_Name.value;
  var prsVal = chkVal;
  if (chkVal == "")
  {
    alert("Please enter your name.");
    theForm.Contact_Name.focus();
    return (false);
  }

  var chkVal = theForm.Contact_Email.value;
  var prsVal = chkVal;
  if (chkVal == "" )
  {
    alert("Please enter your email address.");
    theForm.Contact_Email.focus();
    return (false);
  }
  if(!echeck(chkVal))
  {
	theForm.Contact_Email.focus();
    return (false);  	
  }
  var chkVal = theForm.Contact_RecipientName.value;
  var prsVal = chkVal;
  if (chkVal == "" )
  {
    alert("Please enter the recipient name.");
    theForm.Contact_RecipientName.focus();
    return (false);
  }

  var chkVal = theForm.Contact_RecipientEmail.value;
  var prsVal = chkVal;
  if (chkVal == "" )
  {
    alert("Please enter the recipient email address.");
    theForm.Contact_RecipientEmail.focus();
    return (false);
  }
  if(!echeck(chkVal))
  {
	theForm.Contact_RecipientEmail.focus();
    return (false);  	
  }
  var chkVal = theForm.security_code.value;
  var prsVal = chkVal;
  if (chkVal == "")
  {
    alert("Please enter your security code.");
    theForm.security_code.focus();
    return (false);
  }
	document.getElementById('divEmailMsg').innerHTML='<strong>Please wait ...</strong>';
	$('#btnEmailSend').value='Please Wait...';
	$('#emailSendForm').ajaxSubmit({target:'#divEmailMsg' ,url:urlto}); 

	return false;  
  
  
}

function poll_form_validator(theForm,urlto)
{

	document.getElementById('divPollMsg').innerHTML='<strong>Please wait ...</strong>';
	$('#frmPoll').ajaxSubmit({target:'#divPollMsg' ,url:urlto}); 
	$('#divPollMsg').show();

	return false;  
  
  
}

function openComment(id)
{	
	document.getElementById('divSendMail').style.display="none";
	document.getElementById('divComment').style.display="block";
	document.getElementById('divCommentMsg').innerHTML="";
	document.getElementById('divEmailMsg').innerHTML="";
	document.getElementById('username').focus();
}
function openEmail(id)
{	
	document.getElementById('divSendMail').style.display="block";
	document.getElementById('divComment').style.display="none";
	document.getElementById('divEmailMsg').innerHTML="";
	document.getElementById('divCommentMsg').innerHTML="";
	document.getElementById('Contact_Name').focus();
}

function winOpenBanner()
{
	window.open('http://www.partsandpeople.com/links/bannerWindow/','Banners','width=600, height=800, scrollbars=Yes,resizable=Yes');
}
function winOpenList()
{
	window.open('http://www.partsandpeople.com/viewLinks.php','Links_Exchanged','width=600, height=600, scrollbars=Yes,resizable=Yes');
}
function winOpenRate(id)
{
	window.open('http://www.partsandpeople.com/article_ratings/rateWindow/'+id,"Rate","menubar=0,resizable=0,width=450,height=150");
}
function winOpenLinkArtice(id)
{
	window.open('http://www.partsandpeople.com/articles/linkWindow/'+id,'Link','menubar=0,resizable=0,width=550, height=200');
}


function submit_link_form_validator(theForm)
{

  var chkVal = theForm.Contact_FirstName.value;
  var prsVal = chkVal;
  if (chkVal == "")
  {
    alert("Please enter a value in the \"Contact_FirstName\" field.");
    theForm.Contact_FirstName.focus();
    return (false);
  }

  var chkVal = theForm.Contact_LastName.value;
  var prsVal = chkVal;
  if (chkVal == "")
  {
    alert("Please enter a value in the \"Contact_LastName\" field.");
    theForm.Contact_LastName.focus();
    return (false);
  }

  var chkVal = theForm.Contact_Organization.value;
  var prsVal = chkVal;
  if (chkVal== "")
  {
    alert("Please enter a value in the \"Contact_Organization\" field.");
    theForm.Contact_Organization.focus();
    return (false);
  }

  var chkVal = theForm.Contact_StreetAddress.value;
  var prsVal = chkVal;
  if (chkVal== "")
  {
    alert("Please enter a value in the \"Contact_StreetAddress\" field.");
    theForm.Contact_StreetAddress.focus();
    return (false);
  }
  
  
  var chkVal = theForm.Contact_City.value;
  var prsVal = chkVal;
  if (chkVal == "" )
  {
    alert("Please enter a value in the \"Contact_City\" field.");
    theForm.Contact_City.focus();
    return (false);
  }

  var chkVal = theForm.Contact_State.value;
  var prsVal = chkVal;
  if (chkVal == "")
  {
    alert("Please enter a value in the \"Contact_State\" field.");
    theForm.Contact_State.focus();
    return (false);
  }

  var chkVal = theForm.Contact_ZipCode.value;
  var prsVal = chkVal;
  if (chkVal == "" )
  {
    alert("Please enter a value in the \"Contact_ZipCode\" field.");
    theForm.Contact_ZipCode.focus();
    return (false);
  }

  var chkVal = theForm.Contact_WorkPhone.value;
  var prsVal = chkVal;
  if (chkVal == "")
  {
    alert("Please enter a value in the \"Contact_WorkPhone\" field.");
    theForm.Contact_WorkPhone.focus();
    return (false);
  }

  var chkVal = theForm.Contact_Email.value;
  var prsVal = chkVal;
  if (chkVal == "" )
  {
    alert("Please enter a value in the \"Contact_Email\" field.");
    theForm.Contact_Email.focus();
    return (false);
  }
  
  var chkVal = theForm.security_code.value;
  if (chkVal == "" )
  {
    alert("Please enter a security code properly.");
    theForm.security_code.focus();
    return (false);
  }

  
  return (true);
}

	function doValidateSubscription()
	{
		var flag2=false;
		var valReceive='';
		var flagReceive=false;
		var flag4=false;
		var flagRegion=false;
		var flagBusinessTypeOther=false;
		var flagBusinessType=false;
		var flagName=false;
		var flagSchool=false;
		var flagVersion=false;
		
		var rt=document.SubscriptionForm.elements.length;
		

		var j=0;
		for(i=0;i<rt;i++)
		{
			if(document.SubscriptionForm.elements[i].name=='chk_free[]')
			{
				j=j+1;
				if(document.SubscriptionForm.elements[i].checked==true)
				{
					
					flag2=true;
					if(j==2)
					{
						flag4=true;
					}
				}
			}
			
			if(document.SubscriptionForm.elements[i].name=='radReceive')
			{
				if(document.SubscriptionForm.elements[i].checked==true)
				{
					valReceive=document.SubscriptionForm.elements[i].value;
					flagReceive=true;
				}
			}
			
			if(document.SubscriptionForm.elements[i].name=='chk_region[]')
			{
				if(document.SubscriptionForm.elements[i].checked==true)
				{
					flagRegion=true;
				}
			}
			
			
			if(document.SubscriptionForm.elements[i].name=='chk_bustype[]')
			{
				if(document.SubscriptionForm.elements[i].checked==true)
				{
					if(document.SubscriptionForm.elements[i].value=='10')
						flagBusinessTypeOther=true;
					else
						flagBusinessType=true;
				}
			}
			
/*			if(document.SubscriptionForm.elements[i].name=='radFutureVerify')
			{
				if(document.SubscriptionForm.elements[i].checked==true)
				{
					if(document.SubscriptionForm.elements[i].value=='1')
						flagName=true;
					else
						flagSchool=true;
				}
			}
*/			
			if(document.SubscriptionForm.elements[i].name=='radVersion')
			{
				if(document.SubscriptionForm.elements[i].checked==true)
				{
					flagVersion=true;
				}
			}
			
			
		}

		if(flagReceive==false)
		{
			alert('You must check to receive or continue to receive');
			return false;
		}
		else if(valReceive=='Yes')
		{
		
				if(document.SubscriptionForm.BusinessName.value=='')
				{
					alert('Please enter the business name.');
					document.SubscriptionForm.BusinessName.focus();
					return false;
				}
				else if(document.SubscriptionForm.FirstName.value=='')
				{
					alert('Please enter your first name.');
					document.SubscriptionForm.FirstName.focus();
					return false;
				}
				else if(document.SubscriptionForm.LastName.value=='')
				{
					alert('Please enter your last name.');
					document.SubscriptionForm.LastName.focus();
					return false;
				}
				else if(document.SubscriptionForm.Title.value=='')
				{
					alert('Please enter your title.');
					document.SubscriptionForm.Title.focus();
					return false;
				}
				else if(document.SubscriptionForm.Address.value=='')
				{
					alert('Please enter your address.');
					document.SubscriptionForm.Address.focus();
					return false;
				}
				else if(document.SubscriptionForm.City.value=='')
				{
					alert('Please enter the city name.');
					document.SubscriptionForm.City.focus();
					return false;
				}
				else if(document.SubscriptionForm.State.value=='')
				{
					alert('Please enter the state name.');
					document.SubscriptionForm.State.focus();
					return false;
				}
				else if(document.SubscriptionForm.Country.value=='')
				{
					alert('Please enter the country name.');
					document.SubscriptionForm.Country.focus();
					return false;
				}
				
				else if(document.SubscriptionForm.Zip.value=='' || isNaN(document.SubscriptionForm.Zip.value))
				{
					alert('Please enter the zip. It should have a numeric value');
					document.SubscriptionForm.Zip.focus();
					return false;
				}
				else if(document.SubscriptionForm.Phone.value=='')
				{
					alert('Please enter your phone number.It should have a numeric value');
					document.SubscriptionForm.Phone.focus();
					return false;
				}
				else if(document.SubscriptionForm.email.value=='')
				{
					alert('Please enter your email address.');
					document.SubscriptionForm.email.focus();
					return false;
				}
				else if(document.SubscriptionForm.repeatEmail.value=='')
				{
					alert('Please confirm your email address.');
					document.SubscriptionForm.repeatEmail.focus();
					return false;
				}
				else if(document.SubscriptionForm.repeatEmail.value!=document.SubscriptionForm.email.value)
				{
					alert('Email mismatch!!! Please confirm your email address.');
					document.SubscriptionForm.repeatEmail.focus();
					return false;
				}
				else
				{
						if(flag2==false)
						{
							alert('Please select any of the payment scheme.');
							return false;
						}
						else if(flag4==true && document.SubscriptionForm.CardNumber.value=='')
						{
							alert('Please enter the CardNumber.');
							document.SubscriptionForm.CardNumber.focus();
							return false;
						}
						else if(flag4==true && document.SubscriptionForm.CardCVV.value=='')
						{
							alert('Please enter Card Identification Number.');
							document.SubscriptionForm.CardCVV.focus();
							return false;
						}
						else if(document.SubscriptionForm.highSchoolName.value=='')
						{
							alert('Please enter the high school name value.');
							document.SubscriptionForm.highSchoolName.focus();
							return false;
						}	
						else if(flagVersion==false)
						{
							alert('Please select the version you would like to receive.');
							return false;
						}	
						else if(flagRegion==false)
						{
							alert('Please select any region.');
							return false;
						}		
						else if(flagBusinessType==false && flagBusinessTypeOther==false)
						{
							alert('Please select any business type.');
							return false;
						}
						else if(flagBusinessTypeOther==true && document.SubscriptionForm.Other.value=='')
						{
							alert('Please enter the detail of the business type.');
							document.SubscriptionForm.Other.focus();
							return false;
						}
						else if(document.SubscriptionForm.jobTitle.value=='')
						{
							alert('Please select a job title.');
							document.SubscriptionForm.jobTitle.focus();
							return false;
						}
						else if(document.SubscriptionForm.jobTitle.value=='Other' && document.SubscriptionForm.jobTitleOther.value=='')
						{
							alert('Please eneter the job title detail.');
							document.SubscriptionForm.jobTitleOther.focus();
							return false;
						}
						else
						{
							return true;
						}
		
				}
		}
		else
		{
				if(document.SubscriptionForm.email.value=='')
				{
					alert('Please enter your email address.');
					document.SubscriptionForm.email.focus();
					return false;
				}
				else if(document.SubscriptionForm.repeatEmail.value=='')
				{
					alert('Please confirm your email address.');
					document.SubscriptionForm.repeatEmail.focus();
					return false;
				}
				else if(document.SubscriptionForm.repeatEmail.value!=document.SubscriptionForm.email.value)
				{
					alert('Email mismatch!!! Please confirm your email address.');
					document.SubscriptionForm.repeatEmail.focus();
					return false;
				}
				else
				{
					return true;
				}
				
		}	
				
	}
	
function showcard(val)
{
	if(val==1)
	{
		document.getElementById('divAuthorizeSeal').style.display='none';
		document.getElementById('carddetails').style.display='none';
	}
	else
	{
		document.getElementById('divAuthorizeSeal').style.display='block';
		document.getElementById('carddetails').style.display='block';
	}
}	
	
function clearField(id)
{
	if(id==1)
	{
		document.getElementById('divmiddleName').style.display="block";
		document.getElementById('divhighSchoolName').style.display="none";
		document.SubscriptionForm.highSchoolName.value='';
		
	}
	else if(id==2)
	{
		document.getElementById('divmiddleName').style.display="none";
		document.getElementById('divhighSchoolName').style.display="block";
		document.SubscriptionForm.middleName.value='';
	}
}

function showMostArticles(type)
{
	$('#divMostArticle').html='Loading...';
	if(type=='rated')
	{
		$('#formMostArticle').ajaxSubmit({target:'#divMostArticle' ,url:'http://www.partsandpeople.com/articles/mostRated'}); 
	}
	else if(type=='emailed')
	{
		$('#formMostArticle').ajaxSubmit({target:'#divMostArticle' ,url:'http://www.partsandpeople.com/articles/mostEmailed'}); 	
	}
	else
	{
		$('#formMostArticle').ajaxSubmit({target:'#divMostArticle' ,url:'http://www.partsandpeople.com/articles/mostRead'}); 	
	}
	return false;  
	
}


function invoice_form_validator(theForm)
{
  var chkVal = theForm.InvoiceNumber.value;
  var prsVal = chkVal;
  if (chkVal== "")
  {
    alert("Please enter a value in the \"InvoiceNumber\" field.");
    theForm.InvoiceNumber.focus();
    return (false);
  }

  var chkVal = theForm.Amount.value;
  var prsVal = chkVal;
  if (chkVal== "" || isNaN(chkVal))
  {
    alert("Please enter proper value in the \"Amount\" field.");
    theForm.Amount.focus();
	theForm.Amount.value='';
    return (false);
  }
 
  var chkVal = theForm.Contact_FirstName.value;
  var prsVal = chkVal;
  if (chkVal == "")
  {
    alert("Please enter a value in the \"FirstName\" field.");
    theForm.Contact_FirstName.focus();
    return (false);
  }

  var chkVal = theForm.Contact_LastName.value;
  var prsVal = chkVal;
  if (chkVal == "")
  {
    alert("Please enter a value in the \"LastName\" field.");
    theForm.Contact_LastName.focus();
    return (false);
  }

  var chkVal = theForm.Contact_Email.value;
  var prsVal = chkVal;
  if (chkVal == "" )
  {
    alert("Please enter a value in the \"Email\" field.");
    theForm.Contact_Email.focus();
    return (false);
  }
  
  var chkVal = theForm.CardNumber.value;
  var prsVal = chkVal;
  if (chkVal == "" )
  {
    alert("Please enter a value in the \"Card Number\" field.");
    theForm.CardNumber.focus();
    return (false);
  }
  var chkVal = theForm.CardCVV.value;
  var prsVal = chkVal;
  if (chkVal == "" )
  {
    alert("Please enter a value in the \"Card Identification Number\" field.");
    theForm.CardCVV.focus();
    return (false);
  }
  var chkVal = theForm.CardAddress.value;
  var prsVal = chkVal;
  if (chkVal == "" )
  {
    alert("Please enter a value in the \"Card Address\" field.");
    theForm.CardAddress.focus();
    return (false);
  }
  var chkVal = theForm.CardCity.value;
  var prsVal = chkVal;
  if (chkVal == "" )
  {
    alert("Please enter a value in the \"Card City\" field.");
    theForm.CardCity.focus();
    return (false);
  }
  var chkVal = theForm.CardState.value;
  var prsVal = chkVal;
  if (chkVal == "" )
  {
    alert("Please enter a value in the \"Card State\" field.");
    theForm.CardState.focus();
    return (false);
  }
  var chkVal = theForm.CardZip.value;
  var prsVal = chkVal;
  if (chkVal == "" || isNaN(chkVal))
  {
    alert("Please enter proper value in the \"Card Zip\" field.");
    theForm.CardZip.focus();
    return (false);
  }
  
  
  return (true);
}

	function makeSearch(type)
	{
		if(document.getElementById('SearchField').value=='')
		{
			alert('Please enter a search string');
		}
		else
		{
			if(type=='pp')
			{
				document.frmSearchPP.submit();
			}
			else
			{
				document.frmSearchPP.action='http://search.yahoo.com/search';
				document.getElementById('SearchField').name='p';
			
			}	document.frmSearchPP.submit();
		}
	}
