// JavaScript Document

function compare(name, value, days) {
	var popupSize = "700,500"; //Width & Height of Popup
	var tmpl = "compare"; //template name
	
	// DO NOT TOUCH ANYTHING BELOW THIS LINE!!!!!!!!!!!!!!!!!!!
	
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else {
		var expires = "";
	}
  
	document.cookie = name+"="+value+expires+"; path=/";
  
	var ca = document.cookie.split(';');
	var nameEQ = name;
	var props = '';
	for(var i=0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
		var show = c.indexOf('=') + 1;
		var anum=/(^\d+$)|(^\d+\.\d+$)/;
		if (anum.test(c.substring(show, c.length)))props = props + ',' + c.substring(show, c.length);
    }

	var cleanup	= props.substring(1, props.length);
	
	var newURL = window.location.href;
	
	//Remove f_Propertylist from URL
	if (window.location.href.indexOf('&f_PropertyList=') > 0){
	var pList_stripURLAt = window.location.href.indexOf('&f_PropertyList=');			
	var pList_lastPart = window.location.href.substring(pList_stripURLAt);			
	var pList_startLastPart = pList_lastPart.indexOf('=') + pList_stripURLAt + 1;		
	var pList_startURLReplacement = window.location.href.substr(0, pList_stripURLAt);	
	var pList_endURLReplacement = window.location.href.substring(pList_startLastPart);
	newURL = pList_startURLReplacement+pList_endURLReplacement;
	}
	
	//Remove tmpl from URL
	if (newURL.indexOf('&tmpl=') > 0){
	var tmpl_stripURLAt = newURL.indexOf('&tmpl=');			
	var tmpl_lastPart = newURL.substring(tmpl_stripURLAt);			
	var tmpl_startLastPart = tmpl_lastPart.indexOf('=') + tmpl_stripURLAt + 1;	
	var tmpl_startURLReplacement = pList_startURLReplacement.substr(0, tmpl_stripURLAt);	
	var tmpl_endURLReplacement = pList_endURLReplacement.substring(tmpl_startLastPart);	
	newURL = tmpl_startURLReplacement+tmpl_endURLReplacement;
	}
	
	if (days != -1) {
  		CompareBox(newURL+'&tmpl='+tmpl,cleanup);		
	}else if(cleanup.length > 4){
		window.location.href = newURL +'&tmpl='+ tmpl +'&f_PropertyList='+cleanup;
	} else {
		parent.document.location.reload();
	}
}

function CompareBox(linkInfo, props) {	
	linkIs = linkInfo + '&f_PropertyList=' + props;
	var GB_ANIMATION = true;
	GB_show("Compare",linkIs,550,700);
}
