
// JavaScript Document
//var bIsDebugMode = true;
function GetValueFromQuery( sKey ) 
//////////////////////////////////////////////////////////////////////
// vomegah        -              janiking.com - 07/22/2010
//takes in a key as a paramter and returns the value part if found
//////////////////////////////////////////////////////////////////////
{
                sQuery = window.location.search.substring(1);
                sList = sQuery.split("&");
                for (i=0;i<sList.length;i++) 
                {
                                sItem = sList[i].split("=");
                                if (sItem[0] == sKey) {
                                return sItem[1];
                                }
                }
                return "";
}
 
/////////////////////////////////////////////////////////////////////////
//            vomegah - janiking.com - 07/22/2010 - helper cookie functions
//            function names are self explanatory
/////////////////////////////////////////////////////////////////////////
 
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.toUTCString());
}
 
 
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 "";
}
 
//////////////////////////////////////////////////////////////////////////////////////////
//vomegah - janiking.com            -              07/22/2010
//desc: checks for the passing of a vendor referrece tag - if found then sets the cookie
//                            and updates the drop down - this function should be called on the submission pages
//                            tag should be in the format of vendref=name where name is the vendor name or tag
//                            definitions:
//                                            sDropDownListId             -              the drop down list id
//                                            sDisplay                                -              the display part of the drop down
//                                            sVlue                                     -              the value part of the drop down option - returned on submission
//                                            bSetCookie                         -              flag to determine whether to store the vendref cookie or not
//                                                                                                                            should only be set to true on the prmiary landing pages
/////////////////////////////////////////////////////////////////////////////////////////
//'ctl00_ContentPlaceHolder1_FranchiseGetStarted_ddlHowHear', 'Career Builder', 'careerbuilder', true
function CheckForVendorReferral ( sDropDownListId, sDisplay, sValue, bSetCookie ) {
	var sVendor;
	
	try
	{
		var obj;	
		sVendor = GetValueFromQuery("vendref");
		if ( sVendor == "" )
		{
			sVendor = getCookie("vendref");	
		}
		//modifications 10/26/2011
		//set the display and name value pairs
		
		switch ( sVendor )
		{
			case "careerbuilder":
				sDisplay = "CareerBuilder.com";
				sValue = "CareerBuilder.com";
				break;
				
			case "chicagotribune":
				sDisplay = "Chicago Tribune";
				sValue = "Chicago Tribune";
				
				break;	
					
		}
		
		if ( sVendor != "" )
		{
			//new referral - go ahead and set the cookie and flags
			if (bSetCookie)
			{	
				setCookie( "vendref", sVendor);
			}
						
			obj = document.getElementById(sDropDownListId );
			//check 
			if  ( !obj) 
			{
			//alert("Debug");
			obj = document.getElementById("ctl00_ContentPlaceHolder1_FranchiseRequestInfo1_ddlHowHear" );	
			}
			if ( obj)
			{
				obj.options.length = 0;	
				obj.options[0] = new Option( sDisplay, sValue);
			}
		
		}
									
	}
	catch(e)
	{
	    if(typeof(bIsDebugMode) != 'undefined') 
      {
      	alert(e);
      }
	   return false;
	   
   }
									
	

}

