﻿//Inventory Link Builder
// Parameters: 
// sQry = string required URL for the homenet.
// IframeLink = IFrame Object that will store the results.
// provider: provider name for the link (if we have different providers we can change the logic of the link creation
function BuildLink(sQry, IframeLink, provider)
	{
	    if(provider.toLowerCase()=="homenet")
	      HomeNetLink(sQry,IframeLink);
	}



function HomeNetLink(sQry, IframeLink){
    var args = new Object();
	var query = location.search.substring(1);
	var pairs = query.split("&");                 // Split at ampersand
	search_array = query.split("&");
	for (var i=0; i < pairs.length; i++)
	{
	    if(i>0)sQry+="&";
		var pos = pairs[i].indexOf('=');          
		if (pos == -1) continue;                  
		var argname = pairs[i].substring(0,pos).toLowerCase();  
		var value = pairs[i].substring(pos+1).toLowerCase();    
		
		if(argname=="param_model")
		   sQry += argname + "="+homeNetExceptions(value)+"%25";
		if(argname=="param_year")
		    sQry += "param_year_begin" + "="+value;
		if(argname == "param_make")
		    sQry += argname + "="+value;
	}
    IframeLink.src = sQry+"&style=narrow&param_new-used=new";
}

//This function is created to handle the exception mapping for the names on each service.
function homeNetExceptions(model){
    switch(model.toLowerCase()){
    case "F-350 Super Duty Chassis Cab".toLowerCase():
            model ="F-350";break;
    case "F-450 Super Duty Chassis Cab".toLowerCase():
    case "F-450 Super Duty".toLowerCase():
            model ="F-450";break;
    case  "Explorer Sport Trac".toLowerCase():
            model ="Explorer";
     case "E-Series Econoline Wagon".toLowerCase():
     case "E-Series Econoline Van".toLowerCase():
            model="Econoline";
        }

return model.toLowerCase();
}
