﻿var searchListingArr = new Array();
var userListingArr = new Array();

var headerKeywordId = 'hd-search-input';

function BrowserIsIE() {
	var isIE = false;
    if (navigator.appVersion.indexOf("MSIE") != -1) isIE = true;
    return isIE;
}
  function BrowserVersion() {
    var version = 999; // we assume a sane browser
    if (navigator.appVersion.indexOf("MSIE") != -1) {
		// bah, IE again, lets downgrade version number
		version = navigator.appVersion.split("MSIE ")[1];
		version = version.split(";")[0];
		//version = parseFloat(navigator.appVersion.split("MSIE")[1]);
	}
    return version;
  }
  function BrowserMajorVersion() {
    var majversion = 999; // we assume a sane browser
    if (navigator.appVersion.indexOf("MSIE") != -1)
      // bah, IE again, lets downgrade version number
      majversion = parseFloat(navigator.appVersion.split("MSIE")[1]);
    return majversion;
  }
  function BrowserMinorVersion() {
    var minversion = 999; // we assume a sane browser
    if (navigator.appVersion.indexOf("MSIE") != -1)
      // bah, IE again, lets downgrade version number
      minversion = BrowserVersion().split(".")[1];
      //version = parseFloat(navigator.appVersion.split("MSIE")[1]);
    return minversion;
  }
function CHASE_IRIS_BAD_BROWSER() {
	var isBad = false;
	if (BrowserIsIE() && BrowserMajorVersion() == "6" /*&& BrowserMinorVersion == "0.2900"*/) {
		isBad = true;
	}
	return isBad;
}

//alert(BrowserIsIE());
//alert(BrowserVersion());
//alert(BrowserMajorVersion());
//alert(BrowserMinorVersion());
//alert(CHASE_IRIS_BAD_BROWSER());

function gts_toggleDebug () {
	if (document.getElementById('rootDebug').className == 'rootDebug_active') {
		document.getElementById('rootDebug').className				= 'rootDebug_inactive';
		document.getElementById('rootDebug_content').style.display	= 'none';
	} else {
		document.getElementById('rootDebug').className				= 'rootDebug_active';
		document.getElementById('rootDebug_content').style.display	= '';
	}
	document.getElementById(headerKeywordId).focus();
}

//Used as a function that's called after thickbox loads ajax content
// the thickbox code was altered to use this
function gts_thickBoxResponse () {}

function gts_getCookie (name) {
	var dc		= document.cookie;
	var prefix	= name + "=";
	var begin	= dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
	end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}


function gts_submitENEQueryString (pENEQueryString, pAction) {
	gts_loadENEQueryString(pENEQueryString);
	if (pAction != null) document.getElementById('elb_form').action = pAction;
	document.getElementById('elb_form').dataMethod.value = 'string';
	gts_submitENE_asIs();
}
function gts_loadENEQueryString (pENEQueryString) {
	document.getElementById('elb_form').ENEQueryString.value	= pENEQueryString;
}
function gts_submitENE_asIs () {
	document.getElementById('elb_form').submit();
}

var gts_keywordSection_id = 'ctl00_searchBar_labelN';
function gts_submitKeyword () {
	eneN        = document.getElementById(gts_keywordSection_id).value;
	eneKeyword	= document.getElementById(headerKeywordId).value;
	if (eneN == 'undefined') eneN = '0';
	if (eneKeyword == 'undefined') eneKeyword = '';
		if (typeof(document.elb_form.ListingIDs) != 'undefined') document.elb_form.ListingIDs.value = ''; //Clear the filter of ListingID (if there is one)
		gts_submitENEQueryString ('N=' + eneN + '&Ntk=All&Ntt=' + escape(eneKeyword) + '&search=1', 'Search.aspx');
    
}
function checkNoFoundRequired(){
	var username = document.getElementById('usernameInput').value; 
	var email = document.getElementById('emailInput').value; 
	var msg = document.getElementById('messageInput').value; 
	 
	if ( username== "" ){
		alert("Please enter your name");					 
	}else if (email =="" ){
		alert("Please enter your email");					 
	}else if (msg  =="" ){ 
		alert("Please enter your message");			 
	}else{ 	
			document.getElementById('elb_form').username.value = username; 
			document.getElementById('elb_form').email.value = email; 
			document.getElementById('elb_form').message.value = msg; 			
			gts_submitKeyword(); 
	}				 
}
 

function gts_submitKeyword_leftCol () {
	eneN		= document.getElementById('lower_search_query').value;
	eneKeyword	= document.getElementById('searchFilters_keyword_leftCol').value;  
	if (eneN == 'undefined') eneN = '0';
	if (eneKeyword == 'undefined') eneKeywork = '';
	gts_submitENEQueryString ('N=' + eneN + '&Ntk=All&Ntt=' + eneKeyword + '&search=1', 'Search.aspx');
}

function gts_isEnter_onKeyword (e, btn) {
    if (gts_isEnter(e)) {
		//gts_submitKeyword();
		gts_setDir(btn);
		return false;
	} else {
		return true;
	}
}

function gts_setDir(btn)
{
    var value="";
    var key = "";
    var modeVal="";
    
    if (btn == "1") 
    {
		var sections = document.getElementById(gts_keywordSection_id);
        value = sections.options[sections.options.selectedIndex].value;
        //alert(value);
        key = document.getElementById(headerKeywordId).value;
//        modeVal = document.getElementById('header_searchBar_matchModeList').value;
    }
    else if (btn == "2")
    {
        value = document.getElementById('labelN2').value;
        key = document.getElementById('search_query').value;
    }
    
    var url = "";
    if (value != 0)
    {
        url = value + "/";
    } 
    if (key != "")
    {
        url = url + escape(key) + "_keyword" ;
    }
//    if (modeVal != "")
//    {
//        url = url + "?MatchMode=" + modeVal;
//    }
    
    if (url != "")
    {
        location.href = document.getElementsByTagName('base')[0].getAttribute('href') + url; // + "_keyword" ; //value + "/" + key +"_keyword";//"Search.aspx?" + url;
   	    //alert(url);	
   	}
   	else if (url == "")
   	{
   	    location.href = document.getElementsByTagName('base')[0].getAttribute('href') + "Search.aspx";
   	}
}

function gts_isEnter_onKeyword_leftCol (e) {
	if (gts_isEnter(e)) {
		gts_submitKeyword_leftCol();
		return false;
	} else {
		return true;
	}
}


function gts_isEnter (e) {
	var keycode;
	
	if (window.event) {
		
		keycode = window.event.keyCode;
	} else if (e) {
		
		keycode = e.which;		
	} else {
		
		return true;
	}
	if (keycode == 13) {
		return true;
	} else {
		return false;
	}
}

function gts_goToPage (pPage, pPerPage, pQueryString, pPageName) {
	gts_submitENEQueryString(pQueryString.replace('OFFSET', (pPage*pPerPage)-pPerPage), pPageName);
}

function gts_pagination_byInput (pInputID, pPageCount, pQueryString, pPerPage) {
	this.inputID		= pInputID;
	this.pageCount		= pPageCount;
	this.ENEQueryString	= pQueryString;
	this.perPage		= pPerPage;
	this.offset			= 0;
	this.target			= 'Search.aspx';
	this.focusedObject	= '';
	
	this.submit		= gts_pagination_submit;
	this.onKeyPress	= gts_pagination_onKeyPress;
}
function gts_pagination_submit () {
	gts_submitENEQueryString(this.ENEQueryString.replace('OFFSET', (document.getElementById(this.inputID).value*this.perPage)-this.perPage), this.target);
}
function gts_pagination_onKeyPress (e) {
	if (gts_isEnter(e)) {
		this.submit();
		return false;
	} else {
		return true;
	}
}



function gts_listingDetails_tabClick (activeID, inactiveID) {
	document.getElementById('listingDetails_listing_tab_'+activeID).blur();
	document.getElementById('listingDetails_listing_tab_'+activeID).className		= 'tabActive';
	document.getElementById('listingDetails_listing_tab_'+inactiveID).className	= 'tabInactive';
	document.getElementById('listingDetails_listing_'+activeID).className			= 'tabContentActive';
	document.getElementById('listingDetails_listing_'+inactiveID).className		= 'tabContentInactive';
}

function gts_listingDetails_thumbNailOver (pThumbNum, pFullSrc) {
	if (pFullSrc != '') {
		document.getElementById('large_image1').src = pFullSrc;
		if (pThumbNum != 1) document.getElementById('productDetails_thumb1').className = 'th_image_hover';
		if (pThumbNum != 2 && document.getElementById('productDetails_thumb2') != null) document.getElementById('productDetails_thumb2').className = 'th_image_hover';
		if (pThumbNum != 3 && document.getElementById('productDetails_thumb3') != null) document.getElementById('productDetails_thumb3').className = 'th_image_hover';
		if (pThumbNum != 4 && document.getElementById('productDetails_thumb4') != null) document.getElementById('productDetails_thumb4').className = 'th_image_hover';
		if (pThumbNum == 1) document.getElementById('productDetails_thumb1').className = 'th_image_on';
		if (pThumbNum == 2) document.getElementById('productDetails_thumb2').className = 'th_image_on';
		if (pThumbNum == 3) document.getElementById('productDetails_thumb3').className = 'th_image_on';
		if (pThumbNum == 4) document.getElementById('productDetails_thumb4').className = 'th_image_on';
	}
}
function gts_closeThickbox () {
	TB_remove();
	return true;
}

function gts_emailStore (pStoreName, pStoreEmail) {
	var params	= '';
	var url		= 'Ajax/EmailStore.aspx';
	var state	= '1';
	var height	= '350';
	var theForm	= document.getElementById('emailStore_form');
	var valid	= true;
	if (theForm != null) {
		if (typeof theForm.name != 'undefined' && theForm.name.value.length == 0) valid = false;
		if (typeof theForm.email != 'undefined' && theForm.email.value.length == 0) valid = false;
		if (typeof theForm.message != 'undefined' && theForm.message.value.length == 0) valid = false;
		if (!valid) {
			document.getElementById('errorMessage_p_state1').innerHTML		= 'Please fill out all fields.';
			document.getElementById('errorMessage_p_state1').style.display	= 'block';
			return;
		} else {
			state	= '3';
			height	= '350';
			params	= '&' + Form.serialize(document.getElementById('emailStore_form'));
			$('#TB_window,#TB_overlay,#TB_HideSelect').remove();
		}
	}
	url += '?height=' + height + '&width=410&State=' + state + '&StoreName=' + escape(pStoreName) + '&StoreEmail=' + escape(pStoreEmail) + params;
	TB_show(null, url, false);
}

function gts_viewLargerImage(pNAME, pProductNumber, pPhoto1, pPhoto2, pPhoto3, pPhoto4, pPhoto1_Thumb, pPhoto2_Thumb, pPhoto3_Thumb, pPhoto4_Thumb) {
	var params	= '';
	var url		= 'Ajax/ViewLargerImage.aspx';
	var state	= '1';
	var valid	= true;
	url += '?height=392&width=560&State=' + state + '&Name=' + escape(pNAME) + '&ProductNumber='+ pProductNumber + '&Photo1Full=' + escape(pPhoto1) + '&Photo2Full=' + escape(pPhoto2) + '&Photo3Full=' + escape(pPhoto3) + '&Photo4Full=' + escape(pPhoto4) + '&Photo1Thumb=' + escape(pPhoto1_Thumb) + '&Photo2Thumb=' + escape(pPhoto2_Thumb) + '&Photo3Thumb=' + escape(pPhoto3_Thumb) + '&Photo4Thumb=' + escape(pPhoto4_Thumb) + params;
	TB_show(null, url, false);
}

function gts_tellAFriend (pProductName) {
	var params	= '';
	var url		= 'Ajax/TellAFriend.aspx';
	var state	= '1';
	var height	= '400';
	var theForm	= document.getElementById('tellAFriend_form');
	var valid	= true;
	if (theForm != null) {
		if (typeof theForm.name != 'undefined' && theForm.name.value.length == 0) valid = false;
		if (typeof theForm.email != 'undefined' && theForm.email.value.length == 0) valid = false;
		if (typeof theForm.friendname != 'undefined' && theForm.friendname.value.length == 0) valid = false;
		if (typeof theForm.friendemail != 'undefined' && theForm.friendemail.value.length == 0) valid = false;
		if (typeof theForm.message != 'undefined' && theForm.message.value.length == 0) valid = false;
		if (!valid) {
			document.getElementById('errorMessage_p_state1').innerHTML		= 'Please fill out all fields.';
			document.getElementById('errorMessage_p_state1').style.display	= 'block';
			return;
		} else {
			state	= '3';
			height	= '400';
			params	= '&' + Form.serialize(document.getElementById('tellAFriend_form'));
			$('#TB_window,#TB_overlay,#TB_HideSelect').remove();
		}
	}
	url += '?height=' + height + '&width=410&State=' + state + '&ProductName=' + escape(pProductName) + params+ "&productURL="+escape(window.top.location.href);
	TB_show(null, url, false);
}

function gts_addDeleteMyFavorites (pAction, pListingID, pSiteID, pLoggedIn) {
	if (pLoggedIn) {
		var addToMyFavLink = document.getElementById('addToMyFavorites_a');
		if (typeof addToMyFavLink == 'undefined' || addToMyFavLink == null) addToMyFavLink = document.getElementById('ctl00_MainContent_addToMyFavorites_a');
		if (pAction == '+') {
			addToMyFavLink.href		= addToMyFavLink.href.replace('+', '-');
			addToMyFavLink.innerHTML	= addToMyFavLink.innerHTML.replace('Add to Wishlist', 'Remove');
			document.getElementById('myFavs_li').className			= 'remove_from_my_favorites';
			document.getElementById('myFavs_p').className			= 'remove_from_my_favorites';
		} else if (pAction == '-') {
			addToMyFavLink.href		= addToMyFavLink.href.replace('-', '+');
			addToMyFavLink.innerHTML	= addToMyFavLink.innerHTML.replace('Remove', 'Add to Wishlist');
			document.getElementById('myFavs_li').className			= 'add_to_my_favorites';
			document.getElementById('myFavs_p').className			= 'add_to_my_favorites';
		}
		gts_loadMyFavoritesInfo(pAction, pListingID);
	} else {
		gts_myFavoritesLogin (pSiteID);
	}
}

//pLinkIdPrefixes is optional, and is a comma delimited list. Used if there are multiple links on the same page for the same listing (see styleboards for example)
function gts_addDeleteMyFavorites2 (pAction, pListingID, pSiteID, pLoggedIn, pLinkIdPrefixes){
    if (pLoggedIn=='true')
    {
       gts_addDeleteMyFavorites2_updateLink_getEleValue(pAction,pListingID,pLinkIdPrefixes);
       gts_loadMyFavoritesInfo(pAction, pListingID);
    } 
    else {
      gts_myFavoritesLogin (pSiteID);
    }
}

function gts_addDeleteMyFavorites2_updateLink_getEleValue(pAction,pListingID,pLinkIdPrefixes)
{
    if (typeof(pLinkIdPrefixes) == 'undefined' || pLinkIdPrefixes == '') 
     {
		     gts_addDeleteMyFavorites2_updateLink(pAction, 'record-'+pListingID,pListingID);
	 }
   else 
    {
        prefixArray = pLinkIdPrefixes.split(',');
        for (i=0; i<prefixArray.length; i++) 
        {
	        gts_addDeleteMyFavorites2_updateLink(pAction, prefixArray[i]+'record-'+pListingID,pListingID);
        }
   }
}


function gts_addDeleteMyFavorites2_updateLink(pAction, pName, pListingID) {
	if (document.getElementById(pName) == null) return;
	if (pAction == '+') {	
	    userListingArr.length = userListingArr.length + 1;
        userListingArr[userListingArr.length-1] = pListingID;    
		document.getElementById(pName).innerHTML = "Remove";
		document.getElementById(pName).href = document.getElementById(pName).href.replace('+', '-');
		document.getElementById(pName).className = 'result_wishlist_remove';
	} else if (pAction == '-') {
		gts_removeItems(userListingArr, pListingID);
		document.getElementById(pName).innerHTML = "Add to <i>wishlist</i>";
		document.getElementById(pName).href = document.getElementById(pName).href.replace('-', '+');
		document.getElementById(pName).className = 'result_wishlist';
	}
	else if (pAction == 'login')
    {
     userListingArr.length = userListingArr.length + 1;
     userListingArr[userListingArr.length-1] = pListingID;
     document.getElementById(pName).href = document.getElementById(pName).href.replace('+', '-');
     document.getElementById(pName).innerHTML = 'Remove';
     document.getElementById(pName).className = "result_wishlist_remove";
    }
    else if (pAction == 'logout')
    { document.getElementById(pName).innerHTML = "Add to <i>wishlist</i>";
      document.getElementById(pName).className = "result_wishlist";
    }
}

function gts_findItem(array, item){
    var i=0;
    var index=0;
    while (i < array.length){
        if (array[i] != item){
            index = i;
            break;
        }
        i++
    }
    return index;
}

function gts_removeItems(array, item){
    var i=0;
    var arr = new Array();
    if (arr.length > 0) arr.length = array.length-1;
    var j = 0;
    while (i < array.length){
        if (array[i] != item){
            arr[j] = array[i];
            j++;
        }
        i++;
    }
    i=0;
    array.length = arr.length;
    while (i < arr.length){
        array[i] = arr[i];
        i++;
    }
}


function gts_findSearchResultsID()
{
    searchListingArr.length = 0;
    var hrefs, i;
    hrefs = document.getElementsByTagName('a');
    for (i in hrefs)
    {
  
        if ((/result_wishlist/.test(hrefs[i].className)) | (/result_wishlist_remove/.test(hrefs[i].className)))
        {
           var id = hrefs[i].id;
           var idArr ="";           
           idArr = id.split('record-');             
           searchListingArr.length = searchListingArr.length + 1;
           searchListingArr[searchListingArr.length-1] = idArr[1];               
            
        }
    }
}

var gts_loadMyFavoritesInfo_DivID = 'myFavorites_ajax';
function gts_loadMyFavoritesInfo (pAction, pListingID) {    
	params = '';
	if (pAction != '' && pListingID != '' && pAction) 
	    params = 'action=' + pAction + '&ListingID=' + pListingID;
	if (!CHASE_IRIS_BAD_BROWSER()) {
		requester = new jAjaxRequest('Ajax/MyFavorites_Info.aspx', {method: 'get', parameters: params, onComplete: gts_loadMyFavoritesInfo_afterLoading});
	}
}

function gts_loadMyFavoritesInfo_afterLoading (textResponse) {
	if ((textResponse.responseText.indexOf('Sign In</a>')> 0 || textResponse.responseText.indexOf('Login</a>') > 0) && (top.document.location.toString().toLowerCase().indexOf('/wishlist.aspx') > 0)) {
	     top.document.location.href = top.document.location.href.toString().toLowerCase().replace('wishlist.aspx', ' ');//'/';
	} else {
		document.getElementById(gts_loadMyFavoritesInfo_DivID).innerHTML = textResponse.responseText;
		if (top.document.location.toString().toLowerCase().indexOf('/product.aspx') > 0 || top.document.location.toString().toLowerCase().indexOf('/view_listing.asp') > 0 ) {
				gts_loadMyFavroitesAddRemoveLink();
		}		
		if(typeof(pageName)!='undefined'){
		    if (pageName.toLowerCase().indexOf('search.aspx') >= 0 || pageName.toLowerCase().indexOf('sbdetail.aspx') >= 0){ 
		        if (textResponse.responseText.indexOf('Login</a>') > 0 || textResponse.responseText.indexOf('Sign In</a>') > 0) { gts_updatePage('logout');}
		        else { 
		 
		            gts_findSearchResultsID(); 
                    document.getElementById('searchResultsList').innerHTML = document.getElementById('searchResultsList').innerHTML.replace(/'x'/g, "'+'");
                    document.getElementById('searchResultsList').innerHTML = document.getElementById('searchResultsList').innerHTML.replace(/'false'/g, "'true'");
                    if(pageName.toLowerCase() == "sbdetail.aspx")
                    {
                    document.getElementById('view').innerHTML = document.getElementById('view').innerHTML.replace(/'x'/g, "'+'");
                    document.getElementById('view').innerHTML = document.getElementById('view').innerHTML.replace(/'false'/g, "'true'");
                    document.getElementById('detail_photo_wrap').innerHTML = document.getElementById('detail_photo_wrap').innerHTML.replace(/'x'/g, "'+'");
                    document.getElementById('detail_photo_wrap').innerHTML = document.getElementById('detail_photo_wrap').innerHTML.replace(/'false'/g, "'true'"); }                
                    
                    if (userListingArr.length<1){
                        gts_updatePage('login');
                    }
		        }
	        }
	    }
    }
}

function gts_loadMyFavroitesAddRemoveLink () {
	if (!CHASE_IRIS_BAD_BROWSER()) {
		requester = new jAjaxRequest('Ajax/Myfavorites_LoggedIn.aspx', {method: 'get', parameters: '', onComplete: gts_loadMyFavroitesAddRemoveLink_afterLoading});
	}
}

function gts_loadMyFavroitesAddRemoveLink_afterLoading (textResponse) {
	respVars	= textResponse.responseText.split('&');
	loggedIn	= '';
	siteID		= '';
	listingIDs	= '';
	for (i=0; i<respVars.length; i++) {
		key		= respVars[i].split('=')[0].replace('\n','');
		value	= respVars[i].split('=')[1].replace('\n','');
		if (key == 'loggedIn') loggedIn = value;
		if (key == 'siteID') siteID = value;
		if (key == 'listingIDs') listingIDs = value;
	}
	var addToMyFavLink = document.getElementById('addToMyFavorites_a');
	if (typeof addToMyFavLink == 'undefined' || addToMyFavLink == null) addToMyFavLink = document.getElementById('ctl00_MainContent_addToMyFavorites_a');
	if(pageName.toLowerCase() == '/sbdetail.aspx')
	{
	    addToMyFavLink ="";
	}
	if (loggedIn == 'true') {
		addToMyFavLink.href		= addToMyFavLink.href.replace('false', 'true');
		if (listingIDs.indexOf('|'+GLOBAL_listingID+'|') >= 0) {
			addToMyFavLink.href	= addToMyFavLink.href.replace(/'+'/g, "'-'");
			addToMyFavLink.href	= addToMyFavLink.href.replace(/'x'/g, "'-'");
			addToMyFavLink.innerHTML	= addToMyFavLink.innerHTML.replace('Add to Wishlist', 'Remove');
			document.getElementById('myFavs_li').className			= 'remove_from_my_favorites';
			document.getElementById('myFavs_p').className				= 'remove_from_my_favorites';
		} else {
			addToMyFavLink.href	= addToMyFavLink.href.replace(/'-'/g, "'+'");
			addToMyFavLink.href	= addToMyFavLink.href.replace(/'x'/g, "'+'");
			addToMyFavLink.innerHTML	= addToMyFavLink.innerHTML.replace('Remove', 'Add to Wishlist');
			document.getElementById('myFavs_li').className			= 'add_to_my_favorites';
			document.getElementById('myFavs_p').className				= 'add_to_my_favorites';
		}
	} else {
	    addToMyFavLink.href		= addToMyFavLink.href.replace('true', 'false');
		addToMyFavLink.innerHTML	= addToMyFavLink.innerHTML.replace('Remove', 'Add to Wishlist');
		document.getElementById('myFavs_li').className			= 'add_to_my_favorites';
		document.getElementById('myFavs_p').className				= 'add_to_my_favorites';
	}
}

function gts_myFavoritesRegister (pSiteID) {
	var params	= '';
	var url		= 'Ajax/MyFavorites.aspx';
	var state	= '5';
	var height	= '350';
	var theForm	= document.getElementById('myFavs_login_form');
	if (theForm != null) {
		valid = true;
		if (theForm.email.value.length < 6) valid = false;
		if (typeof theForm.firstname != 'undefined' && theForm.firstname.value.length == 0) valid = false;
		if (typeof theForm.lastname != 'undefined' && theForm.lastname.value.length == 0) valid = false;
		if (!valid) {
			if (theForm.email.value.length < 6) {
				document.getElementById('errorMessage_p_state1').innerHTML		= 'Please enter a valid e-mail address.';
			} else {
				document.getElementById('errorMessage_p_state1').innerHTML		= 'Please fill out all fields.';
			}
			document.getElementById('errorMessage_p_state1').style.display	= 'block';
			return;
		} else {
			state	= '6';
			height	= '350';
			params	= '&' + Form.serialize(document.getElementById('myFavs_login_form'));
			$('#TB_window,#TB_overlay,#TB_HideSelect').remove();
		}
	}
	url += '?height=' + height + '&width=410&State=' + state + "&SiteID=" + pSiteID + params;
	gts_thickBoxResponse = gts_loadMyFavoritesInfo;
	TB_show(null, url, false);
}

function gts_myFavoritesLogin (pSiteID) {
	var params	= '';
	var url		= 'Ajax/MyFavorites.aspx';
	var state	= '1';
	var height	= '350';
	var theForm	= document.getElementById('myFavs_login_form');
	if (theForm != null) {
		valid = true;
		if (theForm.email.value.length < 6) {
			valid = false;
			if (theForm.email.value.length == 5 && theForm.email.value.substr(1,1) == '-' && theForm.email.value.substr(3,1) == '-') valid = true;
		}
		if (!valid) {
			document.getElementById('errorMessage_p_state1').innerHTML		= 'Please enter a valid e-mail address.';
			document.getElementById('errorMessage_p_state1').style.display	= 'block';
			return;
		} else {
			state	= '3';
			height	= '350';
			params	= '&' + Form.serialize(document.getElementById('myFavs_login_form'));
		}
		$('#TB_window,#TB_overlay,#TB_HideSelect').remove();
	}
	url += '?height=' + height + '&width=410&State=' + state + "&SiteID=" + pSiteID + params;
	gts_thickBoxResponse = gts_loadMyFavoritesInfo;
	TB_show(null, url, false);
}

function gts_myFavoriteFinish(){
    if(window.top.location.href.toUpperCase().indexOf("WISHLIST.ASPX") > -1 ) {		 
		window.top.location.href = window.top.location.href.toString().toLowerCase().replace('wishlist.aspx', ' '); //window.top.location.href; 
	}
	TB_remove();
}

function gts_myFavoritesLogout () {
   
    if (window.top.location.href.toUpperCase().indexOf("WISHLIST.ASPX") > -1){
        gts_thickBoxResponse = gts_loadMyFavoritesInfo;
        TB_show(null, 'Ajax/MyFavorites.aspx?state=7', false);
        window.top.location.href = window.top.location.href.toString().toLowerCase().replace('wishlist.aspx', ' ');
    } else {
        //alert(pageName.toLowerCase().indexOf('search.aspx'));
        if (typeof(pageName)!='undefined'){
            if (pageName.toLowerCase().indexOf('search.aspx') >= 0 || pageName.toLowerCase().indexOf('sbdetail.aspx') >= 0) {                
                //window.top.location.href.toUpperCase().indexOf("SEARCH.ASPX") > -1){
                document.getElementById('searchResultsList').innerHTML = document.getElementById('searchResultsList').innerHTML.replace(/'+'/g, "'x'");
                document.getElementById('searchResultsList').innerHTML = document.getElementById('searchResultsList').innerHTML.replace(/'-'/g, "'x'");
                document.getElementById('searchResultsList').innerHTML = document.getElementById('searchResultsList').innerHTML.replace(/'true'/g, "'false'");
                if(pageName.toLowerCase() == "sbdetail.aspx")
                {
                    document.getElementById('view').innerHTML = document.getElementById('view').innerHTML.replace(/'+'/g, "'x'");
                    document.getElementById('view').innerHTML = document.getElementById('view').innerHTML.replace(/'-'/g, "'x'");
                    document.getElementById('view').innerHTML = document.getElementById('view').innerHTML.replace(/'true'/g, "'false'");
                    document.getElementById('detail_photo_wrap').innerHTML = document.getElementById('detail_photo_wrap').innerHTML.replace(/'+'/g, "'x'");
                    document.getElementById('detail_photo_wrap').innerHTML = document.getElementById('detail_photo_wrap').innerHTML.replace(/'-'/g, "'x'");
                    document.getElementById('detail_photo_wrap').innerHTML = document.getElementById('detail_photo_wrap').innerHTML.replace(/'true'/g, "'false'");
                    
                
                }
                for (i=0; i<userListingArr.length; i++)
                {
                   
                    //var value = 'record-' + userListingArr[i];   
                      if(pageName.toLowerCase() == "sbdetail.aspx")  
                      {
                        gts_addDeleteMyFavorites2_updateLink_getEleValue('logout',userListingArr[i],'tab1-,tab2-,tab3-');	
                      }   
                       else
                      {
                        gts_addDeleteMyFavorites2_updateLink_getEleValue('logout',userListingArr[i]);	
                      }                  
//                    if (document.getElementById(value))
//                    {
//                        document.getElementById(value).innerHTML = "Add to <i>wishlist</i>";
//                        document.getElementById(value).className = "result_wishlist";
//                    }                                  
                   
                    
                }
                userListingArr = new Array();
            }
        }
        gts_thickBoxResponse = gts_loadMyFavoritesInfo;
	    TB_show(null, 'Ajax/MyFavorites.aspx?height=150&width=410&state=4', false);
	}
}

function gts_updatePage(sender){

    params = 'sender='+sender;   
	if (!CHASE_IRIS_BAD_BROWSER()) {
	    requester = new jAjaxRequest('Ajax/updatePage.aspx', {method: 'get', parameters: params, onComplete: gts_updatePage_afterLoading});
	}
}

function gts_updatePage_afterLoading (textResponse)
{  
    var responseArr = textResponse.responseText.split('+');
     
    if (responseArr.length>0 && responseArr[0]!='test')
    {
        var favs_Array = responseArr[0].split('|');
       if (searchListingArr.length>0)
        {
            for (favs_Array_i=0; favs_Array_i<favs_Array.length; favs_Array_i++)
            {   
              if(pageName.toLowerCase() == "sbdetail.aspx")  
              {
                gts_addDeleteMyFavorites2_updateLink_getEleValue(responseArr[1],favs_Array[favs_Array_i],'tab1-,tab2-,tab3-');	
              }   
              else
              {
                gts_addDeleteMyFavorites2_updateLink_getEleValue(responseArr[1],favs_Array[favs_Array_i]);	
              }
            }
        }
    }
}

function gts_noResultsForm_submit () {
	var params	= '';
	var state	= '1';
	if (document.getElementById('noResults_form') != null) {
		state	= '3';
		params	= '&' + Form.serialize(document.getElementById('noResults_form'));
	}
	params	= 'State=' + state + params;
	updater	= new jAjaxUpdater('ajaxErrorForm', 'Ajax/NoResultsForm.aspx', {method: 'get', parameters: params});
}

function gts_showAsSeenOnContent(pContentDivID) {
	var li_1 = '';
	var li_2 = '';
	if (pContentDivID == 'dreamHome_contentDiv') {
		document.getElementById('iWantThat_contentDiv').style.display = 'none';
		document.getElementById('dreamHome_contentDiv').style.display = 'block';
		li_1 = '<li><a href="javascript:gts_showAsSeenOnContent(\'iWantThat_contentDiv\');">I Want That! Products</a></li>';
		li_2 = '<li class="on">Dream Home Products</li>';
	} else {
		document.getElementById('dreamHome_contentDiv').style.display = 'none';
		document.getElementById('iWantThat_contentDiv').style.display = 'block';
		li_1 = '<li class="on">I Want That! Products</li>';
		li_2 = '<li><a href="javascript:gts_showAsSeenOnContent(\'dreamHome_contentDiv\');">Dream Home Products</a></li>';
	}
	document.getElementById('featuredBox_ulSpan').innerHTML =	'<ul class="ontv_nav">\n' + li_1 + '\n' + li_2 + '\n</ul>';
}

function submitForm(e, myfunc ){
	if(e.keyCode==13){
		myfunc();
	}
}

function gts_printBuyingGuide (pWhichGuide) {
	window.open('/BuyingGuides/Print.aspx?bg='+pWhichGuide, 'printBuyGuide', 'width=650,height=500,scrollbars=1');
}

function gts_resizeImage(img, maxW, maxH) {
	var thisW		= img.width;
	var thisH		= img.height;
	var thisRatio	= thisH/thisW;
	
	if (thisW>maxW) {
		thisW = maxW;
		thisH = parseInt(thisW*thisRatio);
	}
	if (thisH>maxH) {
		thisH = maxH;
		thisW = parseInt(thisH/thisRatio);
	}
	document.getElementById(img.name).src = img.src;
	document.getElementById(img.name).width = thisW;
	document.getElementById(img.name).height = thisH;
	document.getElementById(img.name).style.width = thisW + 'px';
	document.getElementById(img.name).style.height = thisH + 'px';
	
	var horzPadding = '0';
	var vertPadding = '0';
	if (thisW<maxW) var horzPadding = parseInt((maxW-thisW)/2);
	if (thisH<maxH) var vertPadding = parseInt((maxH-thisH)/2);
	document.getElementById(img.name).style.padding = vertPadding + 'px ' + horzPadding + 'px ' + vertPadding + 'px ' + horzPadding + 'px';
}

function gts_getQSValue(key) {
	var qsString	= window.location.search.substring(1);
	var qsArray		= qsString.split("&");
	for (i=0; i<qsArray.length; i++) {
		var keyValPair = qsArray[i].split("=");
		if (keyValPair[0].toLowerCase() == key.toLowerCase()) {
			return keyValPair[1];
		}
	}
}
