// Fill formList array with selectors for each input field to save cookies to.

var formList = new Array();
formList[0] = "#fnameInput input";
formList[1] = "#lnameInput input";
formList[2] = "#schoolInput input";
formList[3] = "#titleInput input";
formList[4] = "#phoneInput input";
formList[5] = "#emailInput input";
formList[6] = "#interestInput input";
formList[7] = "#helpInput input";


$("document").ready(function(){
	getFormCookie();
	if(location.search.match("success=1")){	
		$("#subContainer, #conForm").css("display","none");
		$("#response").append("<br/><h3>Thank You</h3><p>Your inquiry has been sent successfully.</p>");
	}	
	if(location.search.match("success=0")){	
		$("#response").append("<h3>You're message was not sent. Please fill in all required information.</h3>");
		$("#conForm p label").append("*");
	}	
	$("#subContainer").append("<a href='' id='conClear'>Clear form</a>");
	$("#conClear").click(function(){
		for(var ii=0;ii<formList.length;ii++){
			$(formList[ii])[0].value ="";
		}
		return false;
	 });
});

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function setFormCookie()
{
	var days = 365;
	for(var i=0;i<formList.length;i++){
		setCookie($(formList[i])[0].name,$(formList[i])[0].value,days);
	}
	return true;
}

function getFormCookie()
{
	for(var i=0;i<formList.length;i++){
		$(formList[i])[0].value = getCookie($(formList[i])[0].name);	
	}
}
