var COMPARABLE_COOKIE='comparable';


function GoToDestination( id, dest ){
        var d = new Date();        
        if( document.getElementById ){
                var xform = document.getElementById( "phantomform" );                
                if( xform ){
                        xform.phantom_artdetail.value=id;
                        xform.phantomform_destination.value=dest;
                        xform.phantomform_time.value = d.getTime();                
                }else{
                        var body = document.getElementsByTagName("body").item(0);
                        if( document.getElementById ){
                                var form = "<form  id='phantomform' name='hideform' action='/eradix/shop/'  method='post' >";
                                form += "<input id='phantomform_artdetail' type='hidden' name='artdetail' value='"+id+"' />";
                                form += "<input id='phantomform_destination' type='hidden' name='destination' value='"+dest+"' />";
                                form += "<input id='phantomform_preserve' type='hidden' name='preserve' value='1' />" ;
                                form += "<input id='phantomform_time' type='hidden' name='time' value='"+d.getTime()+"' />";
                                form += "</form>";        
                                body.innerHTML += form;
                        }else{
                                alert( "not supported function " );        
                        }
                        
                }
                
                hideform.submit();
        }else{
                alert( "not supported function " );
        }
}
function read_comparable_cookie(){
        return readCookie( COMPARABLE_COOKIE );        
}
function erase_comparable_cookie(){
        return eraseCookie(COMPARABLE_COOKIE);  
}

function add2Compare( x ){
        //alert( x ) ;
        var txt = readCookie( COMPARABLE_COOKIE );        
        if( txt == null )
                txt ="";   
                
        if( txt.length > 1 &&  txt.indexOf( x )>=0 ){               
                var xreg = eval( '/\#'+x+'/g' ); 
                txt = txt.replace( xreg , " " );
        }else{
                txt+='#'+x;
        }
        eraseCookie(COMPARABLE_COOKIE);  
        createCookie( COMPARABLE_COOKIE, txt  );        
        showCompare();
        
}	
function showCompare(){                
        var xvalue = readCookie( COMPARABLE_COOKIE );
        if( xvalue != null ) {
                if( xvalue.lastIndexOf( '#' )>0 ){			
                        show( 'divxcompare' );
                }else{
                        hide( 'divxcompare' );
                }
        }
        checkComparable(COMPARABLE_COOKIE);
}

function uncheckAll(){
    try{
        var eles = document.getElementsByName( "check_compare" );
        for( var i=0; i<eles.length; i++ ){
                eles[i].checked=false;
        }
    }catch( error ){}
}
function clearAll(){
    uncheckAll();
    erase_comparable_cookie();
}

function checkComparable(x){
        var txt;
        uncheckAll();
        try{
               txt = readCookie( x ).split( '#' );
                for( var i = 0; i<txt.length; i++ ){                
                        try{
                                var id = ("check_"+txt[i]).replace( " ", "" );
                                var ele = document.getElementById( id );
                                if( ele != null )
                                        ele.checked=true;
                        }catch( err ){}
                }
        }catch( error ){}
}
function fillcomparable( x ){
        var ele = document.getElementById( x );
        var xtxt = readCookie( x );
        if( xtxt != null && xtxt){
                var txt = readCookie( x ).split( '#' );
                ele.value = "";
                var found = false;
                for( var i = 0; i<txt.length; i++ ){                
                        if( found ){
                                ele.value += ';'        
                        }else{
                                found = ( txt[i].length>0 );
                        }
                        ele.value += txt[i];
                }        
                return true;
        }
        return false;
}
////
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else 
                var expires = "";        
        var txt = name+"="+value+expires+"; path=/eradix/shop/";
        //alert( "createCookie "+txt );
	document.cookie =txt;
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') 
                        c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) 
                        return c.substring(nameEQ.length,c.length);
	}
	return null;
}


function eraseCookie(name) {
	createCookie(name,"",-1);
}

