function setCookie(cookie_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	//document.cookie=cookie_name+ "=" + escape(value) + ((expiredays==null) ? "" : + ";expires="+exdate.toGMTString();
	document.cookie=cookie_name+ "=" + escape(value);
}

function setTrafficSource() {
	var checkWhetherCookieSet = whetherCookieSet();
	if (checkWhetherCookieSet == 'false') {
		var sourceOfTraffic = "";
		var semSource = getPaidSource();
	 	var seoSource = getSeoSource();
		if (semSource != "") {
			sourceOfTraffic = semSource;
		} else if (seoSource != "") {
			sourceOfTraffic = seoSource;
		} else {
			sourceOfTraffic = "Direct";
		}
		setCookie('trafficSource',sourceOfTraffic,0);
	} else {
	}
}

function whetherCookieSet() {
	var cookieSet = getSourceFromCookie('trafficSource');	
	if(cookieSet != "") {	
		return  'true';
	} else {
		return 'false';
	}
}

function getPaidSource() {
	var paidTrafficSource = "";
	var locationUrl = document.URL;	
        if (locationUrl.indexOf("gclid") > 0) {
                paidTrafficSource = "GGLPPC";
        } else if (locationUrl.indexOf("src=yahooSEM") > 0) {
                paidTrafficSource = "YAHPPC"
        } else if (locationUrl.indexOf("src=msnSEM") > 0) {
                paidTrafficSource = "MSN Adcenter"
	} else {
	}
	return paidTrafficSource;
}

function getSeoSource() {
	var seoTrafficSource = "";
	var originalReferrer = document.referrer;

	var knownSourceFound = "false";
	if (originalReferrer.indexOf("google") > 0) {
		seoTrafficSource = "ORGGGL";
		knownSourceFound = "true";
	} else if (originalReferrer.indexOf("search.yahoo") > 0) {
		seoTrafficSource = "ORGYAH";
		knownSourceFound = "true";
	} else if (originalReferrer.indexOf("search.msn") > 0) {
		seoTrafficSource = "ORGOTH-MSN";
		knownSourceFound = "true";
	} else if (originalReferrer.indexOf("search.aol") > 0) {
		seoTrafficSource = "ORGOTH-AOL";
		knownSourceFound = "true";
	} else if (originalReferrer.indexOf("www.ask") > 0) {
		seoTrafficSource = "ORGOTH-ASK";
		knownSourceFound = "true";
	} else if (originalReferrer.indexOf("counton2.com/cbd/news/local/article/new_sc_online_school/23359") > 0) {
		seoTrafficSource = "WCBDNW";
		knownSourceFound = "true";
	} else if (originalReferrer.indexOf("wyff4.com/education/19153384/detail.html") > 0) {
		seoTrafficSource = "WYFFNW";
		knownSourceFound = "true";		
	} else if (originalReferrer.indexOf("carolinalive.com/news/story.aspx?id=284530") > 0) {
		seoTrafficSource = "CHN15N";
		knownSourceFound = "true";
	} else if (originalReferrer.indexOf("prnewswire.com") > 0) {
		seoTrafficSource = "PRNWRI";
		knownSourceFound = "true";
	} else if (originalReferrer.indexOf("edisonlearning.com") > 0) {
		seoTrafficSource = "EDLRNI";
		knownSourceFound = "true";
	} else if (originalReferrer.indexOf("provostecademy.com") > 0) {
		seoTrafficSource = "DIRECT";
		knownSourceFound = "true";
	} else if (originalReferrer.indexOf("improvescschools.com") > 0) {
		seoTrafficSource = "IMPSCH";
		knownSourceFound = "true";	
	} else if (originalReferrer.indexOf("newsblaze.com/story/2009031011230300004.pnw/topstory.html") > 0) {
		seoTrafficSource = "NWSBLZ";
		knownSourceFound = "true";	
	} else if (originalReferrer.indexOf("sccharter.com/schools.asp") > 0) {
		seoTrafficSource = "SCCHRT";
		knownSourceFound = "true";	
	} else if (originalReferrer.indexOf("bestonlinehighschools.com/directory/property/online-high-schools/provost-academy-south-carolina") > 0) {
		seoTrafficSource = "BONHSI";
		knownSourceFound = "true";			
	} else if (originalReferrer.indexOf("onlinehighschool.org/Home.html") > 0) {
		seoTrafficSource = "ONHSOG";
		knownSourceFound = "true";			
	} else if (originalReferrer.indexOf("en.wikipedia.org/wiki/Provost_Academy_South_Carolina") > 0) {
		seoTrafficSource = "WIKIPD";
		knownSourceFound = "true";							
	} else if (originalReferrer.indexOf("scnow.com") > 0) {
		seoTrafficSource = "SCNOW";
		knownSourceFound = "true";							
	} else if (originalReferrer.indexOf("wistv.com") > 0) {
		seoTrafficSource = "WISTV";
		knownSourceFound = "true";							
	} else if (originalReferrer.indexOf("thestate.com") > 0) {
		seoTrafficSource = "THSTAT";
		knownSourceFound = "true";							
	} else if (originalReferrer.indexOf("greenvilleonline.com") > 0) {
		seoTrafficSource = "GRVONL";
		knownSourceFound = "true";							
	} else if (originalReferrer.indexOf("postandcourier.com") > 0) {
		seoTrafficSource = "PSTCUR";
		knownSourceFound = "true";							
	} else if (originalReferrer.indexOf("columbia.craigslist.org") > 0) {
		seoTrafficSource = "CLBCGL";
		knownSourceFound = "true";							
	} else if (originalReferrer.indexOf("southcarolinaradionetwork.com") > 0) {
		seoTrafficSource = "CSRDNW";
		knownSourceFound = "true";							
	} else if (originalReferrer.indexOf("live5news.com") > 0) {
		seoTrafficSource = "LV5NWS";
		knownSourceFound = "true";							
	} else if (originalReferrer.indexOf("twitter.com") > 0) {
		seoTrafficSource = "TWITER";
		knownSourceFound = "true";							
	} else if (originalReferrer.indexOf("linkedin.com") > 0) {
		seoTrafficSource = "LNKDIN";
		knownSourceFound = "true";							
	} else if (document.URL.indexOf("provostacademy.com/upstate") > 0) {
		seoTrafficSource = "DRMAIL";
		knownSourceFound = "true";							
	} else if (document.URL.indexOf("provostacademy.com/midlands") > 0) {
		seoTrafficSource = "DRMAIL";
		knownSourceFound = "true";							
	} else if (document.URL.indexOf("provostacademy.com/lowcountry") > 0) {
		seoTrafficSource = "DRMAIL";
		knownSourceFound = "true";							
	} else {
	}
	
	if ((knownSourceFound != "true") && (originalReferrer != "")) {
		seoTrafficSource = "Other Organic Sources";
	}
	return seoTrafficSource;
}

function getSourceFromCookie(cookie_name) {
	if (document.cookie.length>0) {
		cookie_start=document.cookie.indexOf(cookie_name + "=");
		if (cookie_start!=-1) {
			cookie_start=cookie_start + cookie_name.length+1;
			cookie_end=document.cookie.indexOf(";",cookie_start);
			if (cookie_end==-1) cookie_end=document.cookie.length;
			return unescape(document.cookie.substring(cookie_start,cookie_end));
    		}
	}
	return "";
}

function getTrafficSource() {
	var trafficOrigination = getSourceFromCookie('trafficSource');
	return trafficOrigination;
}

function setTrafficSourceValue() {
	var trafficSourceElement = document.getElementById("TrafficSource");
	trafficSourceElement.value = getTrafficSource();
		//return true;
}

function formSubmit()
{
	setTrafficSourceValue();
	document.enqform.submit()
}

function showrf()
{
//document.getElementById('geturlLead').innerHTML=document.referrer;
alert(document.URL);
alert(document.referrer);
}