clevereve = {
	testimoniesTextDiv: 'user_testimonies_text',
	testimoniesTextObj: '',
	testimoniesText2Div: '',
	testimoniesText2Obj: '',
    lastIDUsed: 0,
    lastIDUsed2: 0,
    
    setSortingMethod: function( method, category, page, filter, sort ) {
        var windowLocation, method, category, page, filter, sort;
        
        windowLocation  = '/categories/' + category;
        windowLocation += ( filter != '' ? '/' + filter : '' );
        windowLocation += '.html';
        windowLocation += ( method != '' ? '&sort=' + method : '' );
        
        window.location = windowLocation;
    },
    setSortWatches: function( category, page, filter, sort ) {
    	firstSortMethod = document.getElementById("sort_gmf");
    	secondSortMethod = document.getElementById("sort_bla");    	
		thirdSortMethod = document.getElementById("sort_lstcra");    	
        var windowLocation, method, category, page, filter, sort;
        if( firstSortMethod && secondSortMethod && thirdSortMethod ){        
	        windowLocation  = '/categories/' + category;
	        windowLocation += ( filter != '' ? '/' + filter : '' );
	        windowLocation += '.html';
	        windowLocation += ( firstSortMethod.value != '' && secondSortMethod.value !='' && thirdSortMethod.value !=''? '&sort=' + firstSortMethod.value+'-'+secondSortMethod.value+'-'+thirdSortMethod.value: '' );
	        window.location = windowLocation;
        }
    },
    
    setSortMethod: function( category, page, filter, sort ) {
    	firstSortMethod = document.getElementById("sort_mnp");
    	secondSortMethod = document.getElementById("sort_pyw");    	
        var windowLocation, category, page, filter, sort;
        if( firstSortMethod && secondSortMethod ){
	        windowLocation  = '/categories/' + category;
	        windowLocation += ( filter != '' ? '/' + filter : '' );
	        windowLocation += '.html';
	        windowLocation += ( firstSortMethod.value != '' && secondSortMethod.value !='' ? '&sort=' + firstSortMethod.value+'*'+ secondSortMethod.value : '' );
	        window.location = windowLocation;
		}
    },
    
	initTestimonies: function( testimoniesDiv, isMain ) {
		var isMain, testimoniesDiv, fetchTestimoniesRequest;
        
		updateCounter = 0;
        if ( isMain )
        {
        	clevereve.testimoniesText2Div = testimoniesDiv;
            clevereve.testimoniesText2Obj = document.getElementById( testimoniesDiv );
    		clevereve.testimoniesText2Obj.updateInterval = window.setInterval(
    			function( ) {
    				fetchTestimoniesRequest = utils.createXMLHTTPRequest( );
    				fetchTestimoniesRequest.open( "GET", '/testimonies.php?lastID=' + clevereve.lastIDUsed + '&noCache=' + new Date( ).getTime( ), true );
    				fetchTestimoniesRequest.onreadystatechange = function( ) {
    					if( fetchTestimoniesRequest.readyState == 4 ) {
    						if ( fetchTestimoniesRequest.status == 200 ) {
                				document.getElementById( testimoniesDiv ).style.opacity      = 0;
                				document.getElementById( testimoniesDiv ).style.MozOpacity   = 0;
                				document.getElementById( testimoniesDiv ).style.KhtmlOpacity = 0;
                				document.getElementById( testimoniesDiv ).style.filter       = "alpha(opacity='1')";
                                
    							var fetchTestimoniesResponse       = fetchTestimoniesRequest.responseText;
    							var fetchTestimoniesAuthor         = fetchTestimoniesResponse.match( /\<author\>(.*?)\<\/author\>/ );
    							var fetchTestimoniesAuthorLocation = fetchTestimoniesResponse.match( /\<author_location\>(.*?)\<\/author_location\>/ );
    							var fetchTestimoniesTestimony      = fetchTestimoniesResponse.match( /\<testimony\>(.*?)\<\/testimony\>/ );
    							var fetchTestimoniesID             = fetchTestimoniesResponse.match( /\<rand\>(.*?)\<\/rand\>/ );
    							
                                tmpLink = document.createElement( 'a' );
                                tmpLink.setAttribute( 'href', '/reviews.html' );
                                tmpLink.appendChild( document.createTextNode( 'Read More' ) );
                                
                                clevereve.lastIDUsed2 = fetchTestimoniesID[1];
                                utils.clearNode( clevereve.testimoniesText2Obj );
                                clevereve.testimoniesText2Obj.appendChild( document.createTextNode( fetchTestimoniesTestimony[1] ) );
                                clevereve.testimoniesText2Obj.appendChild( document.createTextNode( '... ' ) );
                                clevereve.testimoniesText2Obj.appendChild( tmpLink );
    							clevereve.testimoniesText2Obj.appendChild( document.createElement( 'br' ) );
    							clevereve.testimoniesText2Obj.appendChild( document.createElement( 'br' ) );
    							clevereve.testimoniesText2Obj.appendChild( document.createTextNode( fetchTestimoniesAuthor[1] ) );
    							clevereve.testimoniesText2Obj.appendChild( document.createElement( 'br' ) );
    							clevereve.testimoniesText2Obj.appendChild( document.createTextNode( fetchTestimoniesAuthorLocation[1] ) );
                                
                                effectsEngine.fade( document.getElementById( testimoniesDiv ), 0, 100, 8, 25, 0.5 );
    						}
    					}
    				};
    				updateCounter++;
    				fetchTestimoniesRequest.send( null );				
    			}, 9000 );
        }
        else
        {
        	clevereve.testimoniesTextDiv = testimoniesDiv;
            clevereve.testimoniesTextObj = document.getElementById( testimoniesDiv );
    		clevereve.testimoniesTextObj.updateInterval = window.setInterval(
    			function( ) {
    				fetchTestimoniesRequest = utils.createXMLHTTPRequest( );
    				fetchTestimoniesRequest.open( "GET", '/testimonies.php?lastID=' + clevereve.lastIDUsed + '&noCache=' + new Date( ).getTime( ), true );
    				fetchTestimoniesRequest.onreadystatechange = function( ) {
    					if( fetchTestimoniesRequest.readyState == 4 ) {
    						if ( fetchTestimoniesRequest.status == 200 ) {
                				document.getElementById( testimoniesDiv ).style.opacity      = 0;
                				document.getElementById( testimoniesDiv ).style.MozOpacity   = 0;
                				document.getElementById( testimoniesDiv ).style.KhtmlOpacity = 0;
                				document.getElementById( testimoniesDiv ).style.filter       = "alpha(opacity='1')";
                                
    							var fetchTestimoniesResponse       = fetchTestimoniesRequest.responseText;
    							var fetchTestimoniesAuthor         = fetchTestimoniesResponse.match( /\<author\>(.*?)\<\/author\>/ );
    							var fetchTestimoniesAuthorLocation = fetchTestimoniesResponse.match( /\<author_location\>(.*?)\<\/author_location\>/ );
    							var fetchTestimoniesTestimony      = fetchTestimoniesResponse.match( /\<testimony\>(.*?)\<\/testimony\>/ );
    							var fetchTestimoniesID             = fetchTestimoniesResponse.match( /\<rand\>(.*?)\<\/rand\>/ );
    							
                                clevereve.lastIDUsed = fetchTestimoniesID[1];
                                utils.clearNode( clevereve.testimoniesTextObj );
                                clevereve.testimoniesTextObj.appendChild( document.createTextNode( fetchTestimoniesTestimony[1] ) );
    							clevereve.testimoniesTextObj.appendChild( document.createElement( 'br' ) );
    							clevereve.testimoniesTextObj.appendChild( document.createElement( 'br' ) );
    							clevereve.testimoniesTextObj.appendChild( document.createTextNode( fetchTestimoniesAuthor[1] ) );
    							clevereve.testimoniesTextObj.appendChild( document.createElement( 'br' ) );
    							clevereve.testimoniesTextObj.appendChild( document.createTextNode( fetchTestimoniesAuthorLocation[1] ) );
                                
                                effectsEngine.fade( document.getElementById( testimoniesDiv ), 0, 100, 8, 25, 0.5 );
    						}
    					}
    				};
    				updateCounter++;
    				fetchTestimoniesRequest.send( null );				
    			}, 9000 );
        }
	},
	
	submitForm: function( value ) {
		
		document.getElementById( 'checkout_action' ).name = value;
		document.forms.checkout_form.submit( );
	},
	
	bookmarkPage: function( pageTitle, pageUrl ) {
		var pageTitle, pageUrl, elem;
		if ( window.sidebar ) {
			window.sidebar.addPanel( pageTitle, pageUrl, "" );
		} else if( window.opera && window.print ) {
			elem = document.createElement( 'a' );
			elem.setAttribute( 'href', pageUrl );
			elem.setAttribute( 'title', pageTitle );
			elem.setAttribute( 'rel', 'sidebar' );
			elem.click( );
		} else if( document.all ) {
			window.external.AddFavorite( pageUrl, pageTitle );
		}                                
	}
};
function changeMainImage(obj){
	var img_obj = document.getElementById("main_image");
	var path = "http://www.clevereveassets.com/uploads/images/";
	if(img_obj && obj){
		img_obj.src = path + obj.options[obj.options.selectedIndex].value;
	}
}

function TrimString(sInString){
	return sInString.replace(/(^\s+)|(\s+$)/g, '');
}

function fieldSearchFor(obj){
	if(obj){
		if(obj.value == "Search for..."){
			obj.value = "";
		}else if(obj.value != "Search for..." && TrimString(obj.value).length === 0){
			obj.value = "Search for...";
		}		
	}
}